Skip to content

Commit

Permalink
Add support for Jexl
Browse files Browse the repository at this point in the history
Jexl is the [Javascript Expression
Language](https://github.com/TomFrost/Jexl).
  • Loading branch information
czosel committed Feb 14, 2021
1 parent 3419fb7 commit 7860844
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 1 deletion.
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 @@ -577,6 +577,10 @@
"title": "Java stack trace",
"owner": "RunDevelopment"
},
"jexl": {
"title": "Jexl",
"owner": "czosel"
},
"jolie": {
"title": "Jolie",
"require": "clike",
Expand Down
13 changes: 13 additions & 0 deletions components/prism-jexl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Prism.languages.jexl = {
string: /(["'])(?:\\(?:[\s\S])|(?!\1)[^\\])*\1/,
transform: {
pattern: /\|\s*[a-zA-Zа-яА-Я_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$][a-zA-Zа-яА-Я0-9_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$]*/,
alias: "function",
},
function: /[a-zA-Zа-яА-Я_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$][a-zA-Zа-яА-Я0-9_\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u00FF$]*\s*(?=\()/,
number: /-?(?:(?:[0-9]*\.[0-9]+)|[0-9]+)/,
boolean: /\b(?:true|false)\b/,
operator: /[<>]=?|[!=]=?|-|\+|&&|\|\||\/\/?|[?:*^%]/,
keyword: /\bin\b/,
punctuation: /[{}[\](),.]/,
};
1 change: 1 addition & 0 deletions components/prism-jexl.min.js

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

13 changes: 13 additions & 0 deletions tests/languages/jexl/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
true
false

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

[
["boolean", "true"],
["boolean", "false"]
]

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

Checks for booleans.
96 changes: 96 additions & 0 deletions tests/languages/jexl/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
foo()
foo ()
foo
()
foo . bar ()
foo_bar()
foo_bar ( )
f42()
_()
$()
ä()
Ý()
foo({ x: 1 })
foo({ y: fun() })
foo(bar())

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

[
["function", "foo"],
["punctuation", "("],
["punctuation", ")"],

["function", "foo "],
["punctuation", "("],
["punctuation", ")"],

["function", "foo\r\n"],
["punctuation", "("],
["punctuation", ")"],

"\r\nfoo ",
["punctuation", "."],
["function", "bar "],
["punctuation", "("],
["punctuation", ")"],

["function", "foo_bar"],
["punctuation", "("],
["punctuation", ")"],

["function", "foo_bar "],
["punctuation", "("],
["punctuation", ")"],

["function", "f42"],
["punctuation", "("],
["punctuation", ")"],

["function", "_"],
["punctuation", "("],
["punctuation", ")"],

["function", "$"],
["punctuation", "("],
["punctuation", ")"],

["function", "ä"],
["punctuation", "("],
["punctuation", ")"],

["function", "Ý"],
["punctuation", "("],
["punctuation", ")"],

["function", "foo"],
["punctuation", "("],
["punctuation", "{"],
" x",
["operator", ":"],
["number", "1"],
["punctuation", "}"],
["punctuation", ")"],

["function", "foo"],
["punctuation", "("],
["punctuation", "{"],
" y",
["operator", ":"],
["function", "fun"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "}"],
["punctuation", ")"],

["function", "foo"],
["punctuation", "("],
["function", "bar"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", ")"]
]

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

Checks for functions. Also checks for unicode characters in identifiers.
23 changes: 23 additions & 0 deletions tests/languages/jexl/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
in
"foo" in ["foo"]
"f" in "foo"

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

[
["keyword", "in"],

["string", "\"foo\""],
["keyword", "in"],
["punctuation", "["],
["string", "\"foo\""],
["punctuation", "]"],

["string", "\"f\""],
["keyword", "in"],
["string", "\"foo\""]
]

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

Checks for all keywords.
15 changes: 15 additions & 0 deletions tests/languages/jexl/number_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
42
3.14159
-5.7

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

[
["number", "42"],
["number", "3.14159"],
["number", "-5.7"]
]

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

Checks for integers, floats, negative numbers.
33 changes: 33 additions & 0 deletions tests/languages/jexl/operator_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
-
+
< <=
> >=
= ==
! !=
&& ||
*
/ //
^
? :
%

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

[
["operator", "-"],
["operator", "+"],
["operator", "<"], ["operator", "<="],
["operator", ">"], ["operator", ">="],
["operator", "="], ["operator", "=="],
["operator", "!"], ["operator", "!="],
["operator", "&&"], ["operator", "||"],
["operator", "*"],
["operator", "/"], ["operator", "//"],
["operator", "^"],
["operator", "?"], ["operator", ":"],
["operator", "%"]
]

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

Checks for all operators.
35 changes: 35 additions & 0 deletions tests/languages/jexl/string_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
'a'
'ä'
'本'
'À'
'\''
'""'
'Hello,
world!'

"\n"
"\""
"Hello,
world!"
"日本語"

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

[
["string", "'a'"],
["string", "'ä'"],
["string", "'本'"],
["string", "'À'"],
["string", "'\\''"],
["string", "'\"\"'"],
["string", "'Hello,\r\nworld!'"],

["string", "\"\\n\""],
["string", "\"\\\"\""],
["string", "\"Hello,\r\nworld!\""],
["string", "\"日本語\""]
]

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

Jexl strings can contain special characters, and even linebreaks.
51 changes: 51 additions & 0 deletions tests/languages/jexl/transform_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"foo"|bar
"foo"| bar
"foo"
|
bar

foo|Ý

foo|bar()
foo|bar(1,2)
foo|bar(
1,2
)

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

[
["string", "\"foo\""], ["transform", "|bar"],
["string", "\"foo\""], ["transform", "| bar"],
["string", "\"foo\""],
["transform", "| \r\nbar"],

"\r\n\r\nfoo", ["transform", "|Ý"],

"\r\n\r\nfoo",
["transform", "|bar"],
["punctuation", "("],
["punctuation", ")"],

"\r\nfoo",
["transform", "|bar"],
["punctuation", "("],
["number", "1"],
["punctuation", ","],
["number", "2"],
["punctuation", ")"],

"\r\nfoo",
["transform", "|bar"],
["punctuation", "("],

["number", "1"],
["punctuation", ","],
["number", "2"],

["punctuation", ")"]
]

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

Checks for transforms. Transforms follow the same naming rules as functions.

0 comments on commit 7860844

Please sign in to comment.