Skip to content

Commit

Permalink
closes #101, editted toml regex to not use lookbehind
Browse files Browse the repository at this point in the history
  • Loading branch information
Ynng committed Jan 19, 2023
1 parent 3e47de8 commit c6a8da7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/components/FileViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ export default function FileViewer() {
monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true);
monaco.languages.register({ id: 'toml' });
monaco.languages.setLanguageConfiguration('toml', toml.conf);
monaco.languages.setMonarchTokensProvider('toml', toml.language);
if(toml.language)
monaco.languages.setMonarchTokensProvider('toml', toml.language);
// monaco.languages.typescript.typescriptDefaults.setDiagnosticsOptions({
// noSemanticValidation: true,
// noSyntaxValidation: true,
Expand Down
13 changes: 9 additions & 4 deletions src/utils/monaco-languages/toml.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import monaco from 'monaco-editor';
import { negativeLookbehindSupported } from 'utils/util';

type IRichLanguageConfiguration = monaco.languages.LanguageConfiguration;
type ILanguage = monaco.languages.IMonarchLanguage;
Expand Down Expand Up @@ -68,7 +69,8 @@ export const language = <ILanguage>{

// array: [{ include: '@comments' }, { include: '@dataTypes' }],

boolean: [[/(?<!\w)(true|false)(?!\w)/, 'constant.other.boolean.toml']],
// boolean: [[/(?<!\w)(true|false)(?!\w)/, 'constant.other.boolean.toml']],
boolean: [[/(true|false)(?!\w)/, 'constant.other.boolean.toml']],

comments: [
[
Expand Down Expand Up @@ -96,7 +98,8 @@ export const language = <ILanguage>{

dateTimeWithTz: [
[
/(?<!\w)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2}))(?!\w)/,
// /(?<!\w)(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2}))(?!\w)/,
/(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2}))/,
'constant.other.datetime-with-timezone.toml',
],
],
Expand All @@ -112,14 +115,16 @@ export const language = <ILanguage>{

float: [
[
/(?<!\w)([+-]?(0|([1-9](([0-9]|_[0-9])+)?))(?:(?:\.(0|([1-9](([0-9]|_[0-9])+)?)))?[eE][+-]?[1-9]_?[0-9]*|(?:\.[0-9_]*)))(?!\w)/,
// /(?<!\w)([+-]?(0|([1-9](([0-9]|_[0-9])+)?))(?:(?:\.(0|([1-9](([0-9]|_[0-9])+)?)))?[eE][+-]?[1-9]_?[0-9]*|(?:\.[0-9_]*)))(?!\w)/,
/([+-]?(0|([1-9](([0-9]|_[0-9])+)?))(?:(?:\.(0|([1-9](([0-9]|_[0-9])+)?)))?[eE][+-]?[1-9]_?[0-9]*|(?:\.[0-9_]*)))/,
'constant.numeric.float.toml',
],
],

integer: [
[
/(?<!\w)((?:[+-]?(0|([1-9](([0-9]|_[0-9])+)?))))(?!\w)/,
// /(?<!\w)((?:[+-]?(0|([1-9](([0-9]|_[0-9])+)?))))(?!\w)/,
/((?:[+-]?(0|([1-9](([0-9]|_[0-9])+)?))))/,
'constant.numeric.integer.toml',
],
],
Expand Down
10 changes: 10 additions & 0 deletions src/utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -777,3 +777,13 @@ export const openPort = async (port: number) => {
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(...inputs));
}

// detect if we are in a browser that supports negative lookbehind
export const negativeLookbehindSupported = (() => {
try {
new RegExp('(?<!\\w)foo');
return true;
} catch (e) {
return false;
}
})();

0 comments on commit c6a8da7

Please sign in to comment.