Commit f3c6ba590345b140a2306903a5396e28187466eb

Simran 2019-09-18T14:57:34

AQL: Allow unclosed multi-line comments (#2058) AQL does not require multi-line comments to be closed. ArangoDB simply treats everything until the end of the query string as a comment in that case. This PR adjusts Prism to highlight such comments correctly.

diff --git a/components/prism-aql.js b/components/prism-aql.js
index 2de1522..3ee8a02 100644
--- a/components/prism-aql.js
+++ b/components/prism-aql.js
@@ -1,5 +1,5 @@
 Prism.languages.aql = {
-	'comment': /\/\/.*|\/\*[\s\S]*?\*\//,
+	'comment': /\/\/.*|\/\*[\s\S]*?(?:\*\/|$)/,
 	'property': {
 		pattern: /([{,]\s*)(?:(?!\d)\w+|(["'´`])(?:(?!\2)[^\\\r\n]|\\.)*\2)(?=\s*:)/,
 		lookbehind: true,
diff --git a/components/prism-aql.min.js b/components/prism-aql.min.js
index 5fa9a63..c7bd248 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_SHORTEST_PATHS|LET|LIKE|LIMIT|NONE|NOT|NULL|OR|OUTBOUND|REMOVE|REPLACE|RETURN|SHORTEST_PATH|SORT|UPDATE|UPSERT|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:/(?!\d)\w+(?=\s*\()/,boolean:/(?:true|false)/i,range:{pattern:/\.\./,alias:"operator"},number:/(?:\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},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_SHORTEST_PATHS|LET|LIKE|LIMIT|NONE|NOT|NULL|OR|OUTBOUND|REMOVE|REPLACE|RETURN|SHORTEST_PATH|SORT|UPDATE|UPSERT|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:/(?!\d)\w+(?=\s*\()/,boolean:/(?:true|false)/i,range:{pattern:/\.\./,alias:"operator"},number:/(?:\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/comment_feature.test b/tests/languages/aql/comment_feature.test
index ea3f62a..3de3149 100644
--- a/tests/languages/aql/comment_feature.test
+++ b/tests/languages/aql/comment_feature.test
@@ -3,12 +3,15 @@
  multi
  line
  */
+/* unclosed multi-line comments are allowed
+RETURN 1
 
 ----------------------------------------------------
 
 [
 	["comment", "// single line"],
-	["comment", "/*\r\n multi\r\n line\r\n */"]
+	["comment", "/*\r\n multi\r\n line\r\n */"],
+	["comment", "/* unclosed multi-line comments are allowed\r\nRETURN 1"]
 ]
 
 ----------------------------------------------------