Skip to content

Commit

Permalink
AQL: Added missing keyword + minor improvements (#2047)
Browse files Browse the repository at this point in the history
This adds 5 missing keywords, fixes the operator pattern to support the array concatenation operator properly, and makes the number pattern stricter.
  • Loading branch information
Simran-B authored and RunDevelopment committed Sep 12, 2019
1 parent 1af89e0 commit 32a4c42
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 12 deletions.
17 changes: 14 additions & 3 deletions components/prism-aql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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': /::|[?.:,;()[\]{}]/
};
2 changes: 1 addition & 1 deletion components/prism-aql.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

87 changes: 87 additions & 0 deletions tests/languages/aql/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -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.
8 changes: 7 additions & 1 deletion tests/languages/aql/operator_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

! && ||

[**]
[**] [***] [****]

..
1..100
Expand Down Expand Up @@ -36,6 +36,12 @@
["punctuation", "["],
["operator", "**"],
["punctuation", "]"],
["punctuation", "["],
["operator", "***"],
["punctuation", "]"],
["punctuation", "["],
["operator", "****"],
["punctuation", "]"],

["range", ".."],

Expand Down
45 changes: 38 additions & 7 deletions tests/languages/aql/property_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

----------------------------------------------------

[
Expand All @@ -15,44 +18,72 @@ 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", ":"],
" … ",
["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", "]"]
]

----------------------------------------------------
Expand Down

0 comments on commit 32a4c42

Please sign in to comment.