Skip to content

Commit

Permalink
Added support for AQL (#2025)
Browse files Browse the repository at this point in the history
This adds support for the AQL language.

https://www.arangodb.com/docs/stable/aql/
  • Loading branch information
RunDevelopment authored Sep 2, 2019
1 parent 8ccd258 commit 3fdb7d5
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 2 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@
"title": "AppleScript",
"owner": "Golmote"
},
"aql": {
"title": "AQL",
"owner": "RunDevelopment"
},
"arduino": {
"title": "Arduino",
"require": "cpp",
Expand Down
23 changes: 23 additions & 0 deletions components/prism-aql.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Prism.languages.aql = {
'comment': /\/\/.*|\/\*[\s\S]*?\*\//,
'property': {
pattern: /([{,]\s*)(?:(?!\d)\w+|(["'´`])(?:(?!\2)[^\\\r\n]|\\.)*\2)(?=\s*:)/,
lookbehind: true,
greedy: true
},
'string': {
pattern: /(["'´`])(?:(?!\1)[^\\\r\n]|\\.)*\1/,
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,
'function': /(?!\d)\w+(?=\s*\()/,
'boolean': /(?:true|false)/i,
'range': {
pattern: /\.\./,
alias: 'operator'
},
'number': /(?:\B\.\d+|\b\d+(?:\.\d+)?)(?:e[+-]?\d+)?/i,
'operator': /\*\*|[=!]~|[!=<>]=?|&&|\|\||[-+*/%]/,
'punctuation': /::|[?.:,;()[\]{}]/
};
1 change: 1 addition & 0 deletions components/prism-aql.min.js

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

17 changes: 17 additions & 0 deletions examples/prism-aql.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<h2>Full example</h2>
<pre><code>FOR u IN users
FOR f IN friends
FILTER u.active == @active && f.active == true && u.id == f.userId
RETURN { "name" : u.name, "friends" : friends }

LET name = "Peter"
LET age = 42
RETURN { name, age }

FOR u IN users
FILTER u.status == "not active"
UPDATE u WITH { status: "inactive" } IN users

FOR i IN 1..100
INSERT { value: i } IN test
RETURN NEW</code></pre>
1 change: 1 addition & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"abnf": "Augmented Backus–Naur form",
"apacheconf": "Apache Configuration",
"apl": "APL",
"aql": "AQL",
"arff": "ARFF",
"asciidoc": "AsciiDoc",
"adoc": "AsciiDoc",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

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

16 changes: 16 additions & 0 deletions tests/languages/aql/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// single line
/*
multi
line
*/

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

[
["comment", "// single line"],
["comment", "/*\r\n multi\r\n line\r\n */"]
]

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

Checks for comments.
25 changes: 25 additions & 0 deletions tests/languages/aql/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
1
42
1.23
99.99
0.5
.5
4.87e103
4.87E103

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

[
["number", "1"],
["number", "42"],
["number", "1.23"],
["number", "99.99"],
["number", "0.5"],
["number", ".5"],
["number", "4.87e103"],
["number", "4.87E103"]
]

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

Checks for numbers.
49 changes: 49 additions & 0 deletions tests/languages/aql/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
+ - * / %
> >= <= < == != =
!~ =~

! && ||

[**]

..
1..100

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

[
["operator", "+"],
["operator", "-"],
["operator", "*"],
["operator", "/"],
["operator", "%"],

["operator", ">"],
["operator", ">="],
["operator", "<="],
["operator", "<"],
["operator", "=="],
["operator", "!="],
["operator", "="],

["operator", "!~"],
["operator", "=~"],

["operator", "!"],
["operator", "&&"],
["operator", "||"],

["punctuation", "["],
["operator", "**"],
["punctuation", "]"],

["range", ".."],

["number", "1"],
["range", ".."],
["number", "100"]
]

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

Checks for operators.
60 changes: 60 additions & 0 deletions tests/languages/aql/property_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{ foo: … }
{ 'foo': … }
{ "foo": … }
{ `foo`: … }
{ ´foo´: … }

// not a property
LET opType = IS_NULL(OLD) ? "insert" : "update"

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

[
["punctuation", "{"],
["property", "foo"],
["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",
["punctuation", ")"],
["punctuation", "?"],
["string", "\"insert\""],
["punctuation", ":"],
["string", "\"update\""]
]

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

Checks for properties. (beware of ternary operators)
35 changes: 35 additions & 0 deletions tests/languages/aql/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"yikes!"
"don't know"
"this is a \"quoted\" word"
"this is a longer string."
"the path separator on Windows is \\"

'yikes!'
'don\'t know'
'this is a "quoted" word'
'this is a longer string.'
'the path separator on Windows is \\'

´filter´
`sort`

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

[
["string", "\"yikes!\""],
["string", "\"don't know\""],
["string", "\"this is a \\\"quoted\\\" word\""],
["string", "\"this is a longer string.\""],
["string", "\"the path separator on Windows is \\\\\""],
["string", "'yikes!'"],
["string", "'don\\'t know'"],
["string", "'this is a \"quoted\" word'"],
["string", "'this is a longer string.'"],
["string", "'the path separator on Windows is \\\\'"],
["string", "´filter´"],
["string", "`sort`"]
]

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

Checks for strings.
28 changes: 28 additions & 0 deletions tests/languages/aql/variable_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FILTER u.id == @id && u.name == @name
FOR u IN @@collection

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

[
["keyword", "FILTER"],
" u",
["punctuation", "."],
"id ",
["operator", "=="],
["variable", "@id"],
["operator", "&&"],
" u",
["punctuation", "."],
"name ",
["operator", "=="],
["variable", "@name"],

["keyword", "FOR"],
" u ",
["keyword", "IN"],
["variable", "@@collection"]
]

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

Checks for variable binds.

0 comments on commit 3fdb7d5

Please sign in to comment.