Skip to content

Commit

Permalink
AQL: More pseudo keywords (PrismJS#2055)
Browse files Browse the repository at this point in the history
This adds `COUNT`, `CURRENT`, `KEEP`, and `PRUNE` to the list of keywords such that false positives are (mostly) avoided.
  • Loading branch information
Simran-B authored and RunDevelopment committed Sep 16, 2019
1 parent 32a4c42 commit 899574e
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 15 deletions.
11 changes: 9 additions & 2 deletions components/prism-aql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
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.

28 changes: 24 additions & 4 deletions tests/languages/aql/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
WITH COUNT INTO
COUNT

AGGREGATE
ALL
AND
Expand Down Expand Up @@ -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"],
Expand Down Expand Up @@ -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"
]

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

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

Expand Down Expand Up @@ -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", "]"]
]

Expand Down

0 comments on commit 899574e

Please sign in to comment.