Skip to content

Commit 398e294

Browse files
authoredJul 18, 2020
Added support for Cypher (#2459)
1 parent 4f55052 commit 398e294

16 files changed

+560
-1
lines changed
 

‎components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components.json

+4
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,10 @@
257257
"modify": "css",
258258
"owner": "milesj"
259259
},
260+
"cypher": {
261+
"title": "Cypher",
262+
"owner": "RunDevelopment"
263+
},
260264
"d": {
261265
"title": "D",
262266
"require": "clike",

‎components/prism-cypher.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Prism.languages.cypher = {
2+
// https://neo4j.com/docs/cypher-manual/current/syntax/comments/
3+
'comment': /\/\/.*/,
4+
'string': {
5+
pattern: /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'/,
6+
greedy: true
7+
},
8+
'class-name': {
9+
pattern: /(:\s*)(?:\w+|`(?:[^`\\\r\n])*`)(?=\s*[{):])/,
10+
lookbehind: true,
11+
greedy: true
12+
},
13+
'relationship': {
14+
pattern: /(-\[\s*(?:\w+\s*|`(?:[^`\\\r\n])*`\s*)?:\s*|\|\s*:\s*)(?:\w+|`(?:[^`\\\r\n])*`)/,
15+
lookbehind: true,
16+
greedy: true,
17+
alias: 'property'
18+
},
19+
'identifier': {
20+
pattern: /`(?:[^`\\\r\n])*`/,
21+
greedy: true,
22+
alias: 'symbol'
23+
},
24+
25+
'variable': /\$\w+/,
26+
27+
// https://neo4j.com/docs/cypher-manual/current/syntax/reserved/
28+
'keyword': /\b(?:ADD|ALL|AND|AS|ASC|ASCENDING|ASSERT|BY|CALL|CASE|COMMIT|CONSTRAINT|CONTAINS|CREATE|CSV|DELETE|DESC|DESCENDING|DETACH|DISTINCT|DO|DROP|ELSE|END|ENDS|EXISTS|FOR|FOREACH|IN|INDEX|IS|JOIN|KEY|LIMIT|LOAD|MANDATORY|MATCH|MERGE|NODE|NOT|OF|ON|OPTIONAL|OR|ORDER(?=\s+BY)|PERIODIC|REMOVE|REQUIRE|RETURN|SCALAR|SCAN|SET|SKIP|START|STARTS|THEN|UNION|UNIQUE|UNWIND|USING|WHEN|WHERE|WITH|XOR|YIELD)\b/i,
29+
30+
'function': /\b\w+\b(?=\s*\()/,
31+
32+
'boolean': /\b(?:true|false|null)\b/i,
33+
'number': /\b(?:0x[\da-fA-F]+|\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\b/,
34+
// https://neo4j.com/docs/cypher-manual/current/syntax/operators/
35+
'operator': /:|<--?|--?>?|<>|=~?|[<>]=?|[+*/%^|]|\.\.\.?/,
36+
'punctuation': /[()[\]{},;.]/
37+
};

‎components/prism-cypher.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/prism-cypher.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h2>Full example</h2>
2+
<pre><code>MATCH (person:Person)-[:WORKS_FOR]->(company)
3+
WHERE company.name STARTS WITH "Company"
4+
AND EXISTS {
5+
MATCH (person)-[:LIKES]->(t:Technology)
6+
WHERE size((t)&lt;-[:LIKES]-()) >= 3
7+
}
8+
RETURN person.name as person, company.name AS company;</code></pre>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
true TRUE
2+
false FALSE
3+
null
4+
5+
----------------------------------------------------
6+
7+
[
8+
["boolean", "true"],
9+
["boolean", "TRUE"],
10+
["boolean", "false"],
11+
["boolean", "FALSE"],
12+
["boolean", "null"]
13+
]
14+
15+
----------------------------------------------------
16+
17+
Checks for booleans and null.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
(p:Student)
2+
(p:Student { name: "John" })
3+
(:`Student`)
4+
(:`Student` { name: "John"})
5+
6+
(p:Student:Teacher)
7+
(p:Student { name: "John" }:Teacher)
8+
(:`Student`:`Teacher`)
9+
(:`Student` { name: "John"}:`Teacher` { classes: "..." })
10+
11+
// no class names but still interesting cases
12+
13+
(p { name: "John" })
14+
({ name: "John" })
15+
()
16+
17+
----------------------------------------------------
18+
19+
[
20+
["punctuation", "("],
21+
"p",
22+
["operator", ":"],
23+
["class-name", "Student"],
24+
["punctuation", ")"],
25+
["punctuation", "("],
26+
"p",
27+
["operator", ":"],
28+
["class-name", "Student"],
29+
["punctuation", "{"],
30+
" name",
31+
["operator", ":"],
32+
["string", "\"John\""],
33+
["punctuation", "}"],
34+
["punctuation", ")"],
35+
["punctuation", "("],
36+
["operator", ":"],
37+
["class-name", "`Student`"],
38+
["punctuation", ")"],
39+
["punctuation", "("],
40+
["operator", ":"],
41+
["class-name", "`Student`"],
42+
["punctuation", "{"],
43+
" name",
44+
["operator", ":"],
45+
["string", "\"John\""],
46+
["punctuation", "}"],
47+
["punctuation", ")"],
48+
49+
["punctuation", "("],
50+
"p",
51+
["operator", ":"],
52+
["class-name", "Student"],
53+
["operator", ":"],
54+
["class-name", "Teacher"],
55+
["punctuation", ")"],
56+
["punctuation", "("],
57+
"p",
58+
["operator", ":"],
59+
["class-name", "Student"],
60+
["punctuation", "{"],
61+
" name",
62+
["operator", ":"],
63+
["string", "\"John\""],
64+
["punctuation", "}"],
65+
["operator", ":"],
66+
["class-name", "Teacher"],
67+
["punctuation", ")"],
68+
["punctuation", "("],
69+
["operator", ":"],
70+
["class-name", "`Student`"],
71+
["operator", ":"],
72+
["class-name", "`Teacher`"],
73+
["punctuation", ")"],
74+
["punctuation", "("],
75+
["operator", ":"],
76+
["class-name", "`Student`"],
77+
["punctuation", "{"],
78+
" name",
79+
["operator", ":"],
80+
["string", "\"John\""],
81+
["punctuation", "}"],
82+
["operator", ":"],
83+
["class-name", "`Teacher`"],
84+
["punctuation", "{"],
85+
" classes",
86+
["operator", ":"],
87+
["string", "\"...\""],
88+
["punctuation", "}"],
89+
["punctuation", ")"],
90+
91+
["comment", "// no class names but still interesting cases"],
92+
93+
["punctuation", "("],
94+
"p ",
95+
["punctuation", "{"],
96+
" name",
97+
["operator", ":"],
98+
["string", "\"John\""],
99+
["punctuation", "}"],
100+
["punctuation", ")"],
101+
["punctuation", "("],
102+
["punctuation", "{"],
103+
" name",
104+
["operator", ":"],
105+
["string", "\"John\""],
106+
["punctuation", "}"],
107+
["punctuation", ")"],
108+
["punctuation", "("],
109+
["punctuation", ")"]
110+
]
111+
112+
----------------------------------------------------
113+
114+
Checks for class names.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//comment
2+
3+
----------------------------------------------------
4+
5+
[
6+
["comment", "//comment"]
7+
]
8+
9+
----------------------------------------------------
10+
11+
Checks for comments.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
foo()
2+
3+
----------------------------------------------------
4+
5+
[
6+
["function", "foo"],
7+
["punctuation", "("],
8+
["punctuation", ")"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for function names.
+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
ADD
2+
ALL
3+
AND
4+
AS
5+
ASC
6+
ASCENDING
7+
ASSERT
8+
CALL
9+
CASE
10+
COMMIT
11+
CONSTRAINT
12+
CONTAINS
13+
CREATE
14+
CSV
15+
DELETE
16+
DESC
17+
DESCENDING
18+
DETACH
19+
DISTINCT
20+
DO
21+
DROP
22+
ELSE
23+
END
24+
ENDS
25+
EXISTS
26+
FOR
27+
FOREACH
28+
IN
29+
INDEX
30+
IS
31+
JOIN
32+
KEY
33+
LIMIT
34+
LOAD
35+
MANDATORY
36+
MATCH
37+
MERGE
38+
NODE
39+
NOT
40+
OF
41+
ON
42+
OPTIONAL
43+
OR
44+
ORDER BY
45+
PERIODIC
46+
REMOVE
47+
REQUIRE
48+
RETURN
49+
SCALAR
50+
SCAN
51+
SET
52+
SKIP
53+
START
54+
STARTS
55+
THEN
56+
UNION
57+
UNIQUE
58+
UNWIND
59+
USING
60+
WHEN
61+
WHERE
62+
WITH
63+
XOR
64+
YIELD
65+
66+
----------------------------------------------------
67+
68+
[
69+
["keyword", "ADD"],
70+
["keyword", "ALL"],
71+
["keyword", "AND"],
72+
["keyword", "AS"],
73+
["keyword", "ASC"],
74+
["keyword", "ASCENDING"],
75+
["keyword", "ASSERT"],
76+
["keyword", "CALL"],
77+
["keyword", "CASE"],
78+
["keyword", "COMMIT"],
79+
["keyword", "CONSTRAINT"],
80+
["keyword", "CONTAINS"],
81+
["keyword", "CREATE"],
82+
["keyword", "CSV"],
83+
["keyword", "DELETE"],
84+
["keyword", "DESC"],
85+
["keyword", "DESCENDING"],
86+
["keyword", "DETACH"],
87+
["keyword", "DISTINCT"],
88+
["keyword", "DO"],
89+
["keyword", "DROP"],
90+
["keyword", "ELSE"],
91+
["keyword", "END"],
92+
["keyword", "ENDS"],
93+
["keyword", "EXISTS"],
94+
["keyword", "FOR"],
95+
["keyword", "FOREACH"],
96+
["keyword", "IN"],
97+
["keyword", "INDEX"],
98+
["keyword", "IS"],
99+
["keyword", "JOIN"],
100+
["keyword", "KEY"],
101+
["keyword", "LIMIT"],
102+
["keyword", "LOAD"],
103+
["keyword", "MANDATORY"],
104+
["keyword", "MATCH"],
105+
["keyword", "MERGE"],
106+
["keyword", "NODE"],
107+
["keyword", "NOT"],
108+
["keyword", "OF"],
109+
["keyword", "ON"],
110+
["keyword", "OPTIONAL"],
111+
["keyword", "OR"],
112+
["keyword", "ORDER"],
113+
["keyword", "BY"],
114+
["keyword", "PERIODIC"],
115+
["keyword", "REMOVE"],
116+
["keyword", "REQUIRE"],
117+
["keyword", "RETURN"],
118+
["keyword", "SCALAR"],
119+
["keyword", "SCAN"],
120+
["keyword", "SET"],
121+
["keyword", "SKIP"],
122+
["keyword", "START"],
123+
["keyword", "STARTS"],
124+
["keyword", "THEN"],
125+
["keyword", "UNION"],
126+
["keyword", "UNIQUE"],
127+
["keyword", "UNWIND"],
128+
["keyword", "USING"],
129+
["keyword", "WHEN"],
130+
["keyword", "WHERE"],
131+
["keyword", "WITH"],
132+
["keyword", "XOR"],
133+
["keyword", "YIELD"]
134+
]
135+
136+
----------------------------------------------------
137+
138+
Checks for keywords.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
123
2+
123E45
3+
4+
3.14
5+
6.022E23
6+
7+
0x13af
8+
0xFC3A9
9+
0x66eff
10+
11+
01372
12+
02127
13+
05671
14+
15+
----------------------------------------------------
16+
17+
[
18+
["number", "123"],
19+
["number", "123E45"],
20+
21+
["number", "3.14"],
22+
["number", "6.022E23"],
23+
24+
["number", "0x13af"],
25+
["number", "0xFC3A9"],
26+
["number", "0x66eff"],
27+
28+
["number", "01372"],
29+
["number", "02127"],
30+
["number", "05671"]
31+
]
32+
33+
----------------------------------------------------
34+
35+
Checks for numbers.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
+ - * / % ^
2+
3+
= <> > >= < <=
4+
5+
=~ | : ..
6+
7+
- ->
8+
<- -
9+
- -
10+
--
11+
<--
12+
-->
13+
14+
----------------------------------------------------
15+
16+
[
17+
["operator", "+"],
18+
["operator", "-"],
19+
["operator", "*"],
20+
["operator", "/"],
21+
["operator", "%"],
22+
["operator", "^"],
23+
24+
["operator", "="],
25+
["operator", "<>"],
26+
["operator", ">"],
27+
["operator", ">="],
28+
["operator", "<"],
29+
["operator", "<="],
30+
31+
["operator", "=~"],
32+
["operator", "|"],
33+
["operator", ":"],
34+
["operator", ".."],
35+
36+
["operator", "-"],
37+
["operator", "->"],
38+
["operator", "<-"],
39+
["operator", "-"],
40+
["operator", "-"],
41+
["operator", "-"],
42+
["operator", "--"],
43+
["operator", "<--"],
44+
["operator", "-->"]
45+
]
46+
47+
----------------------------------------------------
48+
49+
Checks for operators.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
( ) [ ] { } ; , .
2+
3+
----------------------------------------------------
4+
5+
[
6+
["punctuation", "("],
7+
["punctuation", ")"],
8+
["punctuation", "["],
9+
["punctuation", "]"],
10+
["punctuation", "{"],
11+
["punctuation", "}"],
12+
["punctuation", ";"],
13+
["punctuation", ","],
14+
["punctuation", "."]
15+
]
16+
17+
----------------------------------------------------
18+
19+
Checks for punctuation.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
-[r:REL_TYPE]->
2+
3+
-[:REL_TYPE]->
4+
5+
<-[:LIKES]-
6+
7+
-[{blocked: false}]->
8+
9+
-[:KNOWS*1..2]-
10+
11+
-[*]->
12+
13+
-[*3..5]->
14+
15+
----------------------------------------------------
16+
17+
[
18+
["operator", "-"],
19+
["punctuation", "["],
20+
"r",
21+
["operator", ":"],
22+
["relationship", "REL_TYPE"],
23+
["punctuation", "]"],
24+
["operator", "->"],
25+
26+
["operator", "-"],
27+
["punctuation", "["],
28+
["operator", ":"],
29+
["relationship", "REL_TYPE"],
30+
["punctuation", "]"],
31+
["operator", "->"],
32+
33+
["operator", "<-"],
34+
["punctuation", "["],
35+
["operator", ":"],
36+
["relationship", "LIKES"],
37+
["punctuation", "]"],
38+
["operator", "-"],
39+
40+
["operator", "-"],
41+
["punctuation", "["],
42+
["punctuation", "{"],
43+
"blocked",
44+
["operator", ":"],
45+
["boolean", "false"],
46+
["punctuation", "}"],
47+
["punctuation", "]"],
48+
["operator", "->"],
49+
50+
["operator", "-"],
51+
["punctuation", "["],
52+
["operator", ":"],
53+
["relationship", "KNOWS"],
54+
["operator", "*"],
55+
["number", "1"],
56+
["operator", ".."],
57+
["number", "2"],
58+
["punctuation", "]"],
59+
["operator", "-"],
60+
61+
["operator", "-"],
62+
["punctuation", "["],
63+
["operator", "*"],
64+
["punctuation", "]"],
65+
["operator", "->"],
66+
67+
["operator", "-"],
68+
["punctuation", "["],
69+
["operator", "*"],
70+
["number", "3"],
71+
["operator", ".."],
72+
["number", "5"],
73+
["punctuation", "]"],
74+
["operator", "->"]
75+
]
76+
77+
----------------------------------------------------
78+
79+
Checks for relationships.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
""
2+
"foo"
3+
''
4+
'foo'
5+
"\foo//'\bar"
6+
7+
----------------------------------------------------
8+
9+
[
10+
["string", "\"\""],
11+
["string", "\"foo\""],
12+
["string", "''"],
13+
["string", "'foo'"],
14+
["string", "\"\\foo//'\\bar\""]
15+
]
16+
17+
----------------------------------------------------
18+
19+
Checks for strings.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
$name
2+
a.$name
3+
4+
----------------------------------------------------
5+
6+
[
7+
["variable", "$name"],
8+
"\na",
9+
["punctuation", "."],
10+
["variable", "$name"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for variables.

0 commit comments

Comments
 (0)
Please sign in to comment.