Commit 32a4c422a15895be034b9533d9d4e0e98c4bc122

Simran 2019-09-12T21:40:54

AQL: Added missing keyword + minor improvements (#2047) This adds 5 missing keywords, fixes the operator pattern to support the array concatenation operator properly, and makes the number pattern stricter.

diff --git a/components/prism-aql.js b/components/prism-aql.js
index d301928..2947e73 100644
--- a/components/prism-aql.js
+++ b/components/prism-aql.js
@@ -10,14 +10,25 @@ Prism.languages.aql = {
 		greedy: true
 	},
 	'variable': /@@?\w+/,
-	'keyword': /\b(?:AGGREGATE|ALL|AND|ANY|ASC|COLLECT|DESC|DISTINCT|FILTER|FOR|GRAPH|IN|INBOUND|INSERT|INTO|LET|LIKE|LIMIT|NONE|NOT|NULL|OR|OUTBOUND|REMOVE|REPLACE|RETURN|SHORTEST_PATH|SORT|UPDATE|UPSERT|WITH)\b/i,
+	'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,
+		// pseudo keywords get a lookbehind to avoid false positives
+		{
+			pattern: /(^|[^\w.[])(?:OPTIONS|SEARCH|TO)\b/i,
+			lookbehind: true
+		},
+		{
+			pattern: /(^|[^\w.[])(?:NEW|OLD)\b/,
+			lookbehind: true
+		},
+	],
 	'function': /(?!\d)\w+(?=\s*\()/,
 	'boolean': /(?:true|false)/i,
 	'range': {
 		pattern: /\.\./,
 		alias: 'operator'
 	},
-	'number': /(?:\B\.\d+|\b\d+(?:\.\d+)?)(?:e[+-]?\d+)?/i,
-	'operator': /\*\*|[=!]~|[!=<>]=?|&&|\|\||[-+*/%]/,
+	'number': /(?:\B\.\d+|\b(?:0|[1-9]\d*)(?:\.\d+)?)(?:e[+-]?\d+)?/i,
+	'operator': /\*{2,}|[=!]~|[!=<>]=?|&&|\|\||[-+*/%]/,
 	'punctuation': /::|[?.:,;()[\]{}]/
 };
diff --git a/components/prism-aql.min.js b/components/prism-aql.min.js
index 038b1d7..4994fd7 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|LET|LIKE|LIMIT|NONE|NOT|NULL|OR|OUTBOUND|REMOVE|REPLACE|RETURN|SHORTEST_PATH|SORT|UPDATE|UPSERT|WITH)\b/i,function:/(?!\d)\w+(?=\s*\()/,boolean:/(?:true|false)/i,range:{pattern:/\.\./,alias:"operator"},number:/(?:\B\.\d+|\b\d+(?:\.\d+)?)(?:e[+-]?\d+)?/i,operator:/\*\*|[=!]~|[!=<>]=?|&&|\|\||[-+*/%]/,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:[/\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
diff --git a/tests/languages/aql/keyword_feature.test b/tests/languages/aql/keyword_feature.test
new file mode 100644
index 0000000..99645e0
--- /dev/null
+++ b/tests/languages/aql/keyword_feature.test
@@ -0,0 +1,87 @@
+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
+
+OPTIONS
+SEARCH
+TO
+
+OLD
+NEW
+
+----------------------------------------------------
+
+[
+	["keyword", "AGGREGATE"],
+	["keyword", "ALL"],
+	["keyword", "AND"],
+	["keyword", "ANY"],
+	["keyword", "ASC"],
+	["keyword", "COLLECT"],
+	["keyword", "DESC"],
+	["keyword", "DISTINCT"],
+	["keyword", "FILTER"],
+	["keyword", "FOR"],
+	["keyword", "GRAPH"],
+	["keyword", "IN"],
+	["keyword", "INBOUND"],
+	["keyword", "INSERT"],
+	["keyword", "INTO"],
+	["keyword", "K_SHORTEST_PATHS"],
+	["keyword", "LET"],
+	["keyword", "LIKE"],
+	["keyword", "LIMIT"],
+	["keyword", "NONE"],
+	["keyword", "NOT"],
+	["keyword", "NULL"],
+	["keyword", "OR"],
+	["keyword", "OUTBOUND"],
+	["keyword", "REMOVE"],
+	["keyword", "REPLACE"],
+	["keyword", "RETURN"],
+	["keyword", "SHORTEST_PATH"],
+	["keyword", "SORT"],
+	["keyword", "UPDATE"],
+	["keyword", "UPSERT"],
+	["keyword", "WITH"],
+
+	["keyword", "OPTIONS"],
+	["keyword", "SEARCH"],
+	["keyword", "TO"],
+
+	["keyword", "OLD"],
+	["keyword", "NEW"]
+]
+
+----------------------------------------------------
+
+Checks for keywords.
diff --git a/tests/languages/aql/operator_feature.test b/tests/languages/aql/operator_feature.test
index 21872c3..9b0d131 100644
--- a/tests/languages/aql/operator_feature.test
+++ b/tests/languages/aql/operator_feature.test
@@ -4,7 +4,7 @@
 
 ! && ||
 
-[**]
+[**] [***] [****]
 
 ..
 1..100
@@ -36,6 +36,12 @@
 	["punctuation", "["],
 	["operator", "**"],
 	["punctuation", "]"],
+	["punctuation", "["],
+	["operator", "***"],
+	["punctuation", "]"],
+	["punctuation", "["],
+	["operator", "****"],
+	["punctuation", "]"],
 
 	["range", ".."],
 
diff --git a/tests/languages/aql/property_feature.test b/tests/languages/aql/property_feature.test
index ed06c7c..6c9c468 100644
--- a/tests/languages/aql/property_feature.test
+++ b/tests/languages/aql/property_feature.test
@@ -7,6 +7,9 @@
 // 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"]
+
 ----------------------------------------------------
 
 [
@@ -15,25 +18,21 @@ LET opType = IS_NULL(OLD) ? "insert" : "update"
 	["punctuation", ":"],
 	" … ",
 	["punctuation", "}"],
-
 	["punctuation", "{"],
 	["property", "'foo'"],
 	["punctuation", ":"],
 	" … ",
 	["punctuation", "}"],
-
 	["punctuation", "{"],
 	["property", "\"foo\""],
 	["punctuation", ":"],
 	" … ",
 	["punctuation", "}"],
-
 	["punctuation", "{"],
 	["property", "`foo`"],
 	["punctuation", ":"],
 	" … ",
 	["punctuation", "}"],
-
 	["punctuation", "{"],
 	["property", "´foo´"],
 	["punctuation", ":"],
@@ -41,18 +40,50 @@ LET opType = IS_NULL(OLD) ? "insert" : "update"
 	["punctuation", "}"],
 
 	["comment", "// not a property"],
-
 	["keyword", "LET"],
 	" opType ",
 	["operator", "="],
 	["function", "IS_NULL"],
 	["punctuation", "("],
-	"OLD",
+	["keyword", "OLD"],
 	["punctuation", ")"],
 	["punctuation", "?"],
 	["string", "\"insert\""],
 	["punctuation", ":"],
-	["string", "\"update\""]
+	["string", "\"update\""],
+
+	["keyword", "LET"],
+	" foo ",
+	["operator", "="],
+	["punctuation", "{"],
+	["property", "to"],
+	["punctuation", ":"],
+	["number", "5"],
+	["punctuation", ","],
+	["property", "search"],
+	["punctuation", ":"],
+	["number", "6"],
+	["punctuation", ","],
+	["property", "options"],
+	["punctuation", ":"],
+	["number", "7"],
+	["punctuation", "}"],
+	["keyword", "LET"],
+	" bar ",
+	["operator", "="],
+	" foo",
+	["punctuation", "."],
+	"search ",
+	["operator", "+"],
+	" foo",
+	["punctuation", "["],
+	"options",
+	["punctuation", "]"],
+	["operator", "+"],
+	" foo",
+	["punctuation", "["],
+	["string", "\"to\""],
+	["punctuation", "]"]
 ]
 
 ----------------------------------------------------