Skip to content

Commit 7e51b99

Browse files
authored
Added support for Jexl (#2764)
1 parent 9633564 commit 7e51b99

12 files changed

+298
-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
@@ -605,6 +605,10 @@
605605
"title": "Java stack trace",
606606
"owner": "RunDevelopment"
607607
},
608+
"jexl": {
609+
"title": "Jexl",
610+
"owner": "czosel"
611+
},
608612
"jolie": {
609613
"title": "Jolie",
610614
"require": "clike",

components/prism-jexl.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Prism.languages.jexl = {
2+
'string': /(["'])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
3+
'transform': {
4+
pattern: /(\|\s*)[a-zA-Zа-яА-Я_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$][a-zA-Zа-яА-Я0-9_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$]*/,
5+
alias: "function",
6+
lookbehind: true
7+
},
8+
'function': /[a-zA-Zа-яА-Я_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$][a-zA-Zа-яА-Я0-9_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$]*\s*(?=\()/,
9+
'number': /\b\d+(?:\.\d+)?\b|\B\.\d+\b/,
10+
'operator': /[<>!]=?|-|\+|&&|==|\|\|?|\/\/?|[?:*^%]/,
11+
'boolean': /\b(?:true|false)\b/,
12+
'keyword': /\bin\b/,
13+
'punctuation': /[{}[\](),.]/,
14+
};

components/prism-jexl.min.js

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

examples/prism-jexl.html

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h2>Full example</h2>
2+
<pre><code>
3+
[
4+
fun(1,2),
5+
{ obj: "1" }.obj,
6+
ctx|transform
7+
]|join(", ")
8+
</code></pre>
+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
true
2+
false
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "true"],
8+
["boolean", "false"]
9+
]
10+
11+
----------------------------------------------------
12+
13+
Checks for booleans.
+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
foo()
2+
foo ()
3+
foo
4+
()
5+
foo . bar ()
6+
foo_bar()
7+
foo_bar ( )
8+
f42()
9+
_()
10+
$()
11+
ä()
12+
Ý()
13+
foo({ x: 1 })
14+
foo({ y: fun() })
15+
foo(bar())
16+
17+
----------------------------------------------------
18+
19+
[
20+
["function", "foo"],
21+
["punctuation", "("],
22+
["punctuation", ")"],
23+
24+
["function", "foo "],
25+
["punctuation", "("],
26+
["punctuation", ")"],
27+
28+
["function", "foo\r\n"],
29+
["punctuation", "("],
30+
["punctuation", ")"],
31+
32+
"\r\nfoo ",
33+
["punctuation", "."],
34+
["function", "bar "],
35+
["punctuation", "("],
36+
["punctuation", ")"],
37+
38+
["function", "foo_bar"],
39+
["punctuation", "("],
40+
["punctuation", ")"],
41+
42+
["function", "foo_bar "],
43+
["punctuation", "("],
44+
["punctuation", ")"],
45+
46+
["function", "f42"],
47+
["punctuation", "("],
48+
["punctuation", ")"],
49+
50+
["function", "_"],
51+
["punctuation", "("],
52+
["punctuation", ")"],
53+
54+
["function", "$"],
55+
["punctuation", "("],
56+
["punctuation", ")"],
57+
58+
["function", "ä"],
59+
["punctuation", "("],
60+
["punctuation", ")"],
61+
62+
["function", "Ý"],
63+
["punctuation", "("],
64+
["punctuation", ")"],
65+
66+
["function", "foo"],
67+
["punctuation", "("],
68+
["punctuation", "{"],
69+
" x",
70+
["operator", ":"],
71+
["number", "1"],
72+
["punctuation", "}"],
73+
["punctuation", ")"],
74+
75+
["function", "foo"],
76+
["punctuation", "("],
77+
["punctuation", "{"],
78+
" y",
79+
["operator", ":"],
80+
["function", "fun"],
81+
["punctuation", "("],
82+
["punctuation", ")"],
83+
["punctuation", "}"],
84+
["punctuation", ")"],
85+
86+
["function", "foo"],
87+
["punctuation", "("],
88+
["function", "bar"],
89+
["punctuation", "("],
90+
["punctuation", ")"],
91+
["punctuation", ")"]
92+
]
93+
94+
----------------------------------------------------
95+
96+
Checks for functions. Also checks for unicode characters in identifiers.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
in
2+
"foo" in ["foo"]
3+
"f" in "foo"
4+
5+
----------------------------------------------------
6+
7+
[
8+
["keyword", "in"],
9+
10+
["string", "\"foo\""],
11+
["keyword", "in"],
12+
["punctuation", "["],
13+
["string", "\"foo\""],
14+
["punctuation", "]"],
15+
16+
["string", "\"f\""],
17+
["keyword", "in"],
18+
["string", "\"foo\""]
19+
]
20+
21+
----------------------------------------------------
22+
23+
Checks for all keywords.
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
42
2+
3.14159
3+
-5.7
4+
5+
----------------------------------------------------
6+
7+
[
8+
["number", "42"],
9+
["number", "3.14159"],
10+
["operator", "-"], ["number", "5.7"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for integers and floats. Negative numbers are handled differently than in Jexl for simplicity: In Jexl, the minus sign in "-1" is parsed as an operator in "1-1" and as part of the number literal in ("-1").
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
-
2+
+
3+
< <=
4+
> >=
5+
==
6+
! !=
7+
&& ||
8+
*
9+
/ //
10+
^
11+
? :
12+
%
13+
14+
----------------------------------------------------
15+
16+
[
17+
["operator", "-"],
18+
["operator", "+"],
19+
["operator", "<"], ["operator", "<="],
20+
["operator", ">"], ["operator", ">="],
21+
["operator", "=="],
22+
["operator", "!"], ["operator", "!="],
23+
["operator", "&&"], ["operator", "||"],
24+
["operator", "*"],
25+
["operator", "/"], ["operator", "//"],
26+
["operator", "^"],
27+
["operator", "?"], ["operator", ":"],
28+
["operator", "%"]
29+
]
30+
31+
----------------------------------------------------
32+
33+
Checks for all operators.
+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'a'
2+
'ä'
3+
'本'
4+
'À'
5+
'\''
6+
'""'
7+
'Hello,
8+
world!'
9+
10+
"\n"
11+
"\""
12+
"Hello,
13+
world!"
14+
"日本語"
15+
16+
----------------------------------------------------
17+
18+
[
19+
["string", "'a'"],
20+
["string", "'ä'"],
21+
["string", "'本'"],
22+
["string", "'À'"],
23+
["string", "'\\''"],
24+
["string", "'\"\"'"],
25+
["string", "'Hello,\r\nworld!'"],
26+
27+
["string", "\"\\n\""],
28+
["string", "\"\\\"\""],
29+
["string", "\"Hello,\r\nworld!\""],
30+
["string", "\"日本語\""]
31+
]
32+
33+
----------------------------------------------------
34+
35+
Jexl strings can contain special characters, and even linebreaks.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
"foo"|bar
2+
"foo"| bar
3+
"foo"
4+
|
5+
bar
6+
7+
foo|Ý
8+
9+
foo|bar()
10+
foo|bar(1,2)
11+
foo|bar(
12+
1,2
13+
)
14+
15+
----------------------------------------------------
16+
17+
[
18+
["string", "\"foo\""], ["operator", "|"], ["transform", "bar"],
19+
["string", "\"foo\""], ["operator", "|"], ["transform", "bar"],
20+
["string", "\"foo\""],
21+
["operator", "|"],
22+
["transform", "bar"],
23+
24+
"\r\n\r\nfoo", ["operator", "|"], ["transform", "Ý"],
25+
26+
"\r\n\r\nfoo",
27+
["operator", "|"],
28+
["transform", "bar"],
29+
["punctuation", "("],
30+
["punctuation", ")"],
31+
32+
"\r\nfoo",
33+
["operator", "|"],
34+
["transform", "bar"],
35+
["punctuation", "("],
36+
["number", "1"],
37+
["punctuation", ","],
38+
["number", "2"],
39+
["punctuation", ")"],
40+
41+
"\r\nfoo",
42+
["operator", "|"],
43+
["transform", "bar"],
44+
["punctuation", "("],
45+
46+
["number", "1"],
47+
["punctuation", ","],
48+
["number", "2"],
49+
50+
["punctuation", ")"]
51+
]
52+
53+
----------------------------------------------------
54+
55+
Checks for transforms. Transforms follow the same naming rules as functions.

0 commit comments

Comments
 (0)