Skip to content

Commit 234b6d8

Browse files
authored
Merge pull request #776 from Altinity/issue-746
Adjust syntax highlighting regexps
2 parents 650500f + bb6a17e commit 234b6d8

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

src/views/QueryEditor/components/QueryTextEditor/editor/initiateEditor.ts

+8-7
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,15 @@ export const initiateEditor = (
9292
const constantsImported = constants;
9393
const macrosImported = macros;
9494

95+
const sortedFunctions = [...functionsImported].sort((a, b) => b.length - a.length);
96+
const allKeywords = [...keywordsImported, ...dynamicKeyword, ...dynamicSystemDatabases];
97+
const sortedKeywords = [...allKeywords].sort((a, b) => b.length - a.length);
98+
9599
monacoInstance.languages.setMonarchTokensProvider(LANGUAGE_ID, {
96100
tokenizer: {
97101
root: [
98-
[
99-
new RegExp(`\\b(${[...keywordsImported, ...dynamicKeyword, ...dynamicSystemDatabases].join('|')})\\b`),
100-
TokenType.KEYWORDS,
101-
],
102-
[new RegExp(`\\s(${functionsImported.join('|')})`), TokenType.FUNCTIONS],
102+
[new RegExp(`\\b(${sortedFunctions.join('|')})(?=\\()`), TokenType.FUNCTIONS],
103+
[new RegExp(`\\b(${sortedKeywords.join('|')})(?=\\W|$)`), TokenType.KEYWORDS],
103104
[new RegExp(`[()]`), TokenType.PARENTHESIS],
104105
[new RegExp(`--.*$`), TokenType.COMMENT],
105106
[new RegExp(`\`\`\`.*\`\`\``), TokenType.COMMENT_BLOCK],
@@ -108,7 +109,7 @@ export const initiateEditor = (
108109
[new RegExp(`'.*?'`), TokenType.STRING],
109110
[new RegExp(`\\b(${dataTypesImported.join('|')})\\b`), TokenType.DATATYPES],
110111
[new RegExp(`\\b(${constantsImported.join('|')})\\b`), TokenType.CONSTANTS],
111-
[new RegExp(`(${macrosImported.map((macros) => macros.replace('$', '\\$')).join('|')})`), TokenType.MACROS],
112+
[new RegExp(`\\b(${macrosImported.map((macros) => macros.replace('$', '\\$')).join('|')})\\b`), TokenType.MACROS],
112113
],
113114
},
114115
});
@@ -119,7 +120,6 @@ export const initiateEditor = (
119120
base: 'vs-dark',
120121
inherit: false,
121122
rules: [
122-
{ token: TokenType.FUNCTIONS, foreground: Colors.FUNCTIONS },
123123
{ token: TokenType.PARENTHESIS, foreground: Colors.PARENTHESIS },
124124
{ token: TokenType.KEYWORDS, foreground: Colors.KEYWORDS },
125125
{ token: TokenType.CONSTANTS, foreground: Colors.CONSTANTS },
@@ -129,6 +129,7 @@ export const initiateEditor = (
129129
{ token: TokenType.COMMENT_BLOCK, foreground: Colors.COMMENT_BLOCK },
130130
{ token: TokenType.VARIABLE, foreground: Colors.MACROS },
131131
{ token: TokenType.STRING, foreground: Colors.STRING },
132+
{ token: TokenType.FUNCTIONS, foreground: Colors.FUNCTIONS },
132133
],
133134
colors: {
134135
'editor.foreground': '#e0e0e0',

0 commit comments

Comments
 (0)