Commit 899574eb25b9f23843e85f6d421ce529a2adf894

Simran 2019-09-16T18:12:48

AQL: More pseudo keywords (#2055) This adds `COUNT`, `CURRENT`, `KEEP`, and `PRUNE` to the list of keywords such that false positives are (mostly) avoided.

diff --git a/components/prism-aql.js b/components/prism-aql.js
index 2947e73..2de1522 100644
--- a/components/prism-aql.js
+++ b/components/prism-aql.js
@@ -11,16 +11,23 @@ Prism.languages.aql = {
 	},
 	'variable': /@@?\w+/,
 	'keyword': [
+		{
+			pattern: /(\bWITH\s+)COUNT(?=\s+INTO\b)/i,
+			lookbehind: true
+		},
 		/\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,
 		// pseudo keywords get a lookbehind to avoid false positives
 		{
-			pattern: /(^|[^\w.[])(?:OPTIONS|SEARCH|TO)\b/i,
+			pattern: /(^|[^\w.[])(?:KEEP|PRUNE|SEARCH|TO)\b/i,
 			lookbehind: true
 		},
 		{
-			pattern: /(^|[^\w.[])(?:NEW|OLD)\b/,
+			pattern: /(^|[^\w.[])(?:CURRENT|NEW|OLD)\b/,
 			lookbehind: true
 		},
+		{
+			pattern: /\bOPTIONS(?=\s*{)/i
+		}
 	],
 	'function': /(?!\d)\w+(?=\s*\()/,
 	'boolean': /(?:true|false)/i,
diff --git a/components/prism-aql.min.js b/components/prism-aql.min.js
index 4994fd7..5fa9a63 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:[/\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.[])(?:OPTIONS|SEARCH|TO)\b/i,lookbehind:!0},{pattern:/(^|[^\w.[])(?:NEW|OLD)\b/,lookbehind:!0}],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/keyword_feature.test b/tests/languages/aql/keyword_feature.test
index 99645e0..204d457 100644
--- a/tests/languages/aql/keyword_feature.test
+++ b/tests/languages/aql/keyword_feature.test
@@ -1,3 +1,6 @@
+WITH COUNT INTO
+COUNT
+
 AGGREGATE
 ALL
 AND
@@ -31,16 +34,26 @@ UPDATE
 UPSERT
 WITH
 
-OPTIONS
+KEEP
+PRUNE
 SEARCH
 TO
 
-OLD
+CURRENT
 NEW
+OLD
+
+OPTIONS {}
+OPTIONS
 
 ----------------------------------------------------
 
 [
+	["keyword", "WITH"],
+	["keyword", "COUNT"],
+	["keyword", "INTO"],
+	"\r\nCOUNT\r\n\r\n",
+
 	["keyword", "AGGREGATE"],
 	["keyword", "ALL"],
 	["keyword", "AND"],
@@ -74,12 +87,19 @@ NEW
 	["keyword", "UPSERT"],
 	["keyword", "WITH"],
 
-	["keyword", "OPTIONS"],
+	["keyword", "KEEP"],
+	["keyword", "PRUNE"],
 	["keyword", "SEARCH"],
 	["keyword", "TO"],
 
+	["keyword", "CURRENT"],
+	["keyword", "NEW"],
 	["keyword", "OLD"],
-	["keyword", "NEW"]
+
+	["keyword", "OPTIONS"],
+	["punctuation", "{"],
+	["punctuation", "}"],
+	"\r\nOPTIONS"
 ]
 
 ----------------------------------------------------
diff --git a/tests/languages/aql/property_feature.test b/tests/languages/aql/property_feature.test
index 6c9c468..9783aa3 100644
--- a/tests/languages/aql/property_feature.test
+++ b/tests/languages/aql/property_feature.test
@@ -7,8 +7,8 @@
 // not a property
 LET opType = IS_NULL(OLD) ? "insert" : "update"
 
-LET foo = { to: 5, search: 6, options: 7 }
-LET bar = foo.search + foo[options] + foo["to"]
+LET foo = { CURRENT: 1, keep: 2, NEW: 3, OLD: 4, options: 5, prune: 6, search: 7, to: 8 }
+LET bar = foo[CURRENT] + foo.NEW + foo["OLD"] + foo[keep] + foo.options + foo["prune"] + foo.search + foo[to]
 
 ----------------------------------------------------
 
@@ -56,33 +56,76 @@ LET bar = foo.search + foo[options] + foo["to"]
 	" foo ",
 	["operator", "="],
 	["punctuation", "{"],
-	["property", "to"],
+	["property", "CURRENT"],
+	["punctuation", ":"],
+	["number", "1"],
+	["punctuation", ","],
+	["property", "keep"],
+	["punctuation", ":"],
+	["number", "2"],
+	["punctuation", ","],
+	["property", "NEW"],
+	["punctuation", ":"],
+	["number", "3"],
+	["punctuation", ","],
+	["property", "OLD"],
+	["punctuation", ":"],
+	["number", "4"],
+	["punctuation", ","],
+	["property", "options"],
 	["punctuation", ":"],
 	["number", "5"],
 	["punctuation", ","],
-	["property", "search"],
+	["property", "prune"],
 	["punctuation", ":"],
 	["number", "6"],
 	["punctuation", ","],
-	["property", "options"],
+	["property", "search"],
 	["punctuation", ":"],
 	["number", "7"],
+	["punctuation", ","],
+	["property", "to"],
+	["punctuation", ":"],
+	["number", "8"],
 	["punctuation", "}"],
 	["keyword", "LET"],
 	" bar ",
 	["operator", "="],
 	" foo",
+	["punctuation", "["],
+	"CURRENT",
+	["punctuation", "]"],
+	["operator", "+"],
+	" foo",
 	["punctuation", "."],
-	"search ",
+	"NEW ",
+	["operator", "+"],
+	" foo",
+	["punctuation", "["],
+	["string", "\"OLD\""],
+	["punctuation", "]"],
+	["operator", "+"],
+	" foo",
+	["punctuation", "["],
+	"keep",
+	["punctuation", "]"],
+	["operator", "+"],
+	" foo",
+	["punctuation", "."],
+	"options ",
 	["operator", "+"],
 	" foo",
 	["punctuation", "["],
-	"options",
+	["string", "\"prune\""],
 	["punctuation", "]"],
 	["operator", "+"],
 	" foo",
+	["punctuation", "."],
+	"search ",
+	["operator", "+"],
+	" foo",
 	["punctuation", "["],
-	["string", "\"to\""],
+	"to",
 	["punctuation", "]"]
 ]