From fa540ab72c5c8b33605a102b26e9110b0406e2b7 Mon Sep 17 00:00:00 2001 From: Michael Schmidt Date: Mon, 22 Nov 2021 13:00:47 +0100 Subject: [PATCH] AQL: Differenciate between strings and identifiers (#3183) --- components/prism-aql.js | 6 +++++- components/prism-aql.min.js | 2 +- tests/languages/aql/identifier_feature.test | 9 +++++++++ tests/languages/aql/string_feature.test | 8 ++------ 4 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 tests/languages/aql/identifier_feature.test diff --git a/components/prism-aql.js b/components/prism-aql.js index 19592992db..42868dd6cc 100644 --- a/components/prism-aql.js +++ b/components/prism-aql.js @@ -6,7 +6,11 @@ Prism.languages.aql = { greedy: true }, 'string': { - pattern: /(["'´`])(?:(?!\1)[^\\\r\n]|\\.)*\1/, + pattern: /(["'])(?:(?!\1)[^\\\r\n]|\\.)*\1/, + greedy: true + }, + 'identifier': { + pattern: /([´`])(?:(?!\1)[^\\\r\n]|\\.)*\1/, greedy: true }, 'variable': /@@?\w+/, diff --git a/components/prism-aql.min.js b/components/prism-aql.min.js index 612b347516..9ed85972d2 100644 --- a/components/prism-aql.min.js +++ b/components/prism-aql.min.js @@ -1 +1 @@ -Prism.languages.aql={comment:/\/\/.*|\/\*[\s\S]*?\*\//,property:{pattern:/([{,]\s*)(?:(?!\d)\w+|(["'´`])(?:(?!\2)[^\\\r\n]|\\.)*\2)(?=\s*:)/,lookbehind:!0,greedy:!0},string:{pattern:/(["'´`])(?:(?!\1)[^\\\r\n]|\\.)*\1/,greedy:!0},variable:/@@?\w+/,keyword:[{pattern:/(\bWITH\s+)COUNT(?=\s+INTO\b)/i,lookbehind:!0},/\b(?:AGGREGATE|ALL|AND|ANY|ASC|COLLECT|DESC|DISTINCT|FILTER|FOR|GRAPH|IN|INBOUND|INSERT|INTO|K_PATHS|K_SHORTEST_PATHS|LET|LIKE|LIMIT|NONE|NOT|NULL|OR|OUTBOUND|REMOVE|REPLACE|RETURN|SHORTEST_PATH|SORT|UPDATE|UPSERT|WINDOW|WITH)\b/i,{pattern:/(^|[^\w.[])(?:KEEP|PRUNE|SEARCH|TO)\b/i,lookbehind:!0},{pattern:/(^|[^\w.[])(?:CURRENT|NEW|OLD)\b/,lookbehind:!0},{pattern:/\bOPTIONS(?=\s*\{)/i}],function:/\b(?!\d)\w+(?=\s*\()/,boolean:/\b(?:false|true)\b/i,range:{pattern:/\.\./,alias:"operator"},number:[/\b0b[01]+/i,/\b0x[0-9a-f]+/i,/(?:\B\.\d+|\b(?:0|[1-9]\d*)(?:\.\d+)?)(?:e[+-]?\d+)?/i],operator:/\*{2,}|[=!]~|[!=<>]=?|&&|\|\||[-+*/%]/,punctuation:/::|[?.:,;()[\]{}]/}; \ No newline at end of file +Prism.languages.aql={comment:/\/\/.*|\/\*[\s\S]*?\*\//,property:{pattern:/([{,]\s*)(?:(?!\d)\w+|(["'´`])(?:(?!\2)[^\\\r\n]|\\.)*\2)(?=\s*:)/,lookbehind:!0,greedy:!0},string:{pattern:/(["'])(?:(?!\1)[^\\\r\n]|\\.)*\1/,greedy:!0},identifier:{pattern:/([´`])(?:(?!\1)[^\\\r\n]|\\.)*\1/,greedy:!0},variable:/@@?\w+/,keyword:[{pattern:/(\bWITH\s+)COUNT(?=\s+INTO\b)/i,lookbehind:!0},/\b(?:AGGREGATE|ALL|AND|ANY|ASC|COLLECT|DESC|DISTINCT|FILTER|FOR|GRAPH|IN|INBOUND|INSERT|INTO|K_PATHS|K_SHORTEST_PATHS|LET|LIKE|LIMIT|NONE|NOT|NULL|OR|OUTBOUND|REMOVE|REPLACE|RETURN|SHORTEST_PATH|SORT|UPDATE|UPSERT|WINDOW|WITH)\b/i,{pattern:/(^|[^\w.[])(?:KEEP|PRUNE|SEARCH|TO)\b/i,lookbehind:!0},{pattern:/(^|[^\w.[])(?:CURRENT|NEW|OLD)\b/,lookbehind:!0},{pattern:/\bOPTIONS(?=\s*\{)/i}],function:/\b(?!\d)\w+(?=\s*\()/,boolean:/\b(?:false|true)\b/i,range:{pattern:/\.\./,alias:"operator"},number:[/\b0b[01]+/i,/\b0x[0-9a-f]+/i,/(?:\B\.\d+|\b(?:0|[1-9]\d*)(?:\.\d+)?)(?:e[+-]?\d+)?/i],operator:/\*{2,}|[=!]~|[!=<>]=?|&&|\|\||[-+*/%]/,punctuation:/::|[?.:,;()[\]{}]/}; \ No newline at end of file diff --git a/tests/languages/aql/identifier_feature.test b/tests/languages/aql/identifier_feature.test new file mode 100644 index 0000000000..664358bbef --- /dev/null +++ b/tests/languages/aql/identifier_feature.test @@ -0,0 +1,9 @@ +´filter´ +`sort` + +---------------------------------------------------- + +[ + ["identifier", "´filter´"], + ["identifier", "`sort`"] +] diff --git a/tests/languages/aql/string_feature.test b/tests/languages/aql/string_feature.test index 064c0f0e72..21db276995 100644 --- a/tests/languages/aql/string_feature.test +++ b/tests/languages/aql/string_feature.test @@ -10,9 +10,6 @@ 'this is a longer string.' 'the path separator on Windows is \\' -´filter´ -`sort` - ---------------------------------------------------- [ @@ -21,13 +18,12 @@ ["string", "\"this is a \\\"quoted\\\" word\""], ["string", "\"this is a longer string.\""], ["string", "\"the path separator on Windows is \\\\\""], + ["string", "'yikes!'"], ["string", "'don\\'t know'"], ["string", "'this is a \"quoted\" word'"], ["string", "'this is a longer string.'"], - ["string", "'the path separator on Windows is \\\\'"], - ["string", "´filter´"], - ["string", "`sort`"] + ["string", "'the path separator on Windows is \\\\'"] ] ----------------------------------------------------