Skip to content

Commit ec25ba6

Browse files
darachRunDevelopment
andauthoredSep 21, 2021
Added Tremor project DSL language definition (#3087)
* Add tremor project DSL langauge definitions Signed-off-by: Darach Ennis <[email protected]> * Update components/prism-tremor.js Apply fix worst-case time complexity per @RunDevelopment's insight Co-authored-by: Michael Schmidt <[email protected]> * Update components/prism-tremor.js Terser formulation of pattern Co-authored-by: Michael Schmidt <[email protected]> * Update components/prism-tremor.js Terser formulation of pattern Co-authored-by: Michael Schmidt <[email protected]> * Update components/prism-tremor.js Terser formulation of pattern Co-authored-by: Michael Schmidt <[email protected]> * Add partial interpolation, expand tests, attend to lints Signed-off-by: Darach Ennis <[email protected]> * Improved Tremor tokenization Signed-off-by: Michael Schmidt <[email protected]> Co-authored-by: Michael Schmidt <[email protected]> Co-authored-by: Michael Schmidt <[email protected]>
1 parent 99d94fa commit ec25ba6

20 files changed

+689
-3
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

+12
Original file line numberDiff line numberDiff line change
@@ -1313,6 +1313,18 @@
13131313
"title": "TOML",
13141314
"owner": "RunDevelopment"
13151315
},
1316+
"tremor": {
1317+
"title": "Tremor",
1318+
"alias": [
1319+
"trickle",
1320+
"troy"
1321+
],
1322+
"owner": "darach",
1323+
"aliasTitles": {
1324+
"trickle": "trickle",
1325+
"troy": "troy"
1326+
}
1327+
},
13161328
"turtle": {
13171329
"title": "Turtle",
13181330
"alias": "trig",

‎components/prism-tremor.js

+68
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
(function (Prism) {
2+
3+
Prism.languages.tremor = {
4+
'comment': {
5+
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
6+
lookbehind: true
7+
},
8+
'interpolated-string': null, // see below
9+
'extractor': {
10+
pattern: /\b[a-z_]\w*\|(?:[^\r\n\\|]|\\(?:\r\n|[\s\S]))*\|/i,
11+
greedy: true,
12+
inside: {
13+
'function': /^\w+/,
14+
'regex': /\|[\s\S]+/,
15+
}
16+
},
17+
'identifier': {
18+
pattern: /`[^`]*`/,
19+
greedy: true
20+
},
21+
22+
'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())\b/,
23+
24+
'keyword': /\b(?:event|state|select|create|define|deploy|operator|script|connector|pipeline|flow|config|links|connect|to|from|into|with|group|by|args|window|stream|tumbling|sliding|where|having|set|each|emit|drop|const|let|for|match|of|case|when|default|end|patch|insert|update|erase|move|copy|merge|fn|intrinsic|recur|use|as|mod)\b/,
25+
'boolean': /\b(?:true|false|null)\b/i,
26+
27+
'number': /\b(?:0b[0-1_]*|0x[0-9a-fA-F_]*|\d[0-9_]*(?:\.\d[0-9_]*)?(?:[Ee][+-]?[0-9_]+)?)\b/,
28+
29+
'pattern-punctuation': {
30+
pattern: /%(?=[({[])/,
31+
alias: 'punctuation'
32+
},
33+
'operator': /[-+*\/%~!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?>?=?|(?:not|and|or|xor|present|absent)\b/,
34+
'punctuation': /::|[;\[\]()\{\},.:]/,
35+
};
36+
37+
var interpolationPattern = /#\{(?:[^"{}]|\{[^{}]*\}|"(?:[^"\\\r\n]|\\(?:\r\n|[\s\S]))*")*\}/.source;
38+
39+
Prism.languages.tremor['interpolated-string'] = {
40+
pattern: RegExp(
41+
/(^|[^\\])/.source +
42+
'(?:' +
43+
'"""(?:' + /[^"\\#]|\\[\s\S]|"(?!"")|#(?!\{)/.source + '|' + interpolationPattern + ')*"""' +
44+
'|' +
45+
'"(?:' + /[^"\\\r\n#]|\\(?:\r\n|[\s\S])|#(?!\{)/.source + '|' + interpolationPattern + ')*"' +
46+
')'
47+
),
48+
lookbehind: true,
49+
greedy: true,
50+
inside: {
51+
'interpolation': {
52+
pattern: RegExp(interpolationPattern),
53+
inside: {
54+
'punctuation': /^#\{|\}$/,
55+
'expression': {
56+
pattern: /[\s\S]+/,
57+
inside: Prism.languages.tremor
58+
}
59+
}
60+
},
61+
'string': /[\s\S]+/
62+
}
63+
};
64+
65+
Prism.languages.troy = Prism.languages['tremor'];
66+
Prism.languages.trickle = Prism.languages['tremor'];
67+
68+
}(Prism));

‎components/prism-tremor.min.js

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

‎examples/prism-tremor.html

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<h2>Comments</h2>
2+
<pre><code># Single line comment
3+
### Module level documentation comment
4+
## Statement level documentation comment
5+
# Regular code comment
6+
</code></pre>
7+
8+
<h2>Strings</h2>
9+
<pre><code>
10+
# double quote single line strings
11+
"foo \"bar\" baz"
12+
13+
# heredocs or multiline strings
14+
"""
15+
{ "snot": "badger" }
16+
"""
17+
</code></pre>
18+
19+
<h2>Variables</h2>
20+
<pre><code>
21+
# Immutable constants
22+
const snot = "fleek";
23+
24+
# Mutable variables
25+
let badger = "flook";
26+
</code></pre>
27+
28+
<h2>Operators</h2>
29+
<pre><code>
30+
merge {} of
31+
{ "snot": "badger" }
32+
end;
33+
34+
patch {} of
35+
insert snot = "badger"
36+
end;
37+
</code></pre>
38+
39+
<h2>Functions and keywords</h2>
40+
<pre><code>
41+
fn fib_(a, b, n) of
42+
case (a, b, n) when n > 0 => recur(b, a + b, n - 1)
43+
default => a
44+
end;
45+
46+
fn fib(n) with
47+
fib_(0, 1, n)
48+
end;
49+
50+
fib(event)
51+
</code></pre>
52+
53+
<h2>Queries</h2>
54+
<pre><code>
55+
define script fib
56+
script
57+
fn fib_(a, b, n) of
58+
case (a, b, n) when n > 0 => recur(b, a + b, n - 1)
59+
default => a
60+
end;
61+
62+
fn fib(n) with
63+
fib_(0, 1, n)
64+
end;
65+
66+
{ "fib": fib(event.n) }
67+
end;
68+
69+
create script fib;
70+
select event.n from in into fib;
71+
select event from fib into out;
72+
</code></pre>
73+
74+
<h2>Deployments</h2>
75+
<pre><code>
76+
define pipeline passthrough
77+
pipeline
78+
select event from in into out;
79+
end;
80+
81+
deploy pipeline passthrough;
82+
</code></pre>

‎plugins/autoloader/prism-autoloader.js

+2
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@
239239
"sln": "solution-file",
240240
"rq": "sparql",
241241
"t4": "t4-cs",
242+
"trickle": "tremor",
243+
"troy": "tremor",
242244
"trig": "turtle",
243245
"ts": "typescript",
244246
"tsconfig": "typoscript",

‎plugins/autoloader/prism-autoloader.min.js

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

‎plugins/show-language/prism-show-language.js

+2
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@
227227
"tap": "TAP",
228228
"tt2": "Template Toolkit 2",
229229
"toml": "TOML",
230+
"trickle": "trickle",
231+
"troy": "troy",
230232
"trig": "TriG",
231233
"ts": "TypeScript",
232234
"tsconfig": "TSConfig",

‎plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
true
2+
false
3+
null
4+
5+
----------------------------------------------------
6+
7+
[
8+
["boolean", "true"],
9+
["boolean", "false"],
10+
["boolean", "null"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for booleans.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#
2+
## foobar
3+
### snot badger
4+
5+
----------------------------------------------------
6+
7+
[
8+
["comment", "#"],
9+
["comment", "## foobar"],
10+
["comment", "### snot badger"]
11+
]
12+
13+
----------------------------------------------------
14+
15+
Checks for comments.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
re|^(?P<kind>bat.*)$|
2+
datetime|%Y-%m-%d %H:%M|
3+
4+
----------------------------------------------------
5+
6+
[
7+
["extractor", [
8+
["function", "re"],
9+
["regex", "|^(?P<kind>bat.*)$|"]
10+
]],
11+
["extractor", [
12+
["function", "datetime"],
13+
["regex", "|%Y-%m-%d %H:%M|"]
14+
]]
15+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
foo
2+
foo_bar_42
3+
`foo`
4+
`bar`
5+
6+
----------------------------------------------------
7+
8+
[
9+
"foo\r\nfoo_bar_42\r\n",
10+
["identifier", "`foo`"],
11+
["identifier", "`bar`"]
12+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
`args`
2+
`as`
3+
`by`
4+
`case`
5+
`config`
6+
`connect`
7+
`connector`
8+
`const`
9+
`copy`
10+
`create`
11+
`default`
12+
`define`
13+
`deploy`
14+
`drop`
15+
`each`
16+
`emit`
17+
`end`
18+
`erase`
19+
`event`
20+
`flow`
21+
`fn`
22+
`for`
23+
`from`
24+
`group`
25+
`having`
26+
`insert`
27+
`into`
28+
`intrinsic`
29+
`let`
30+
`links`
31+
`match`
32+
`merge`
33+
`mod`
34+
`move`
35+
`of`
36+
`operator`
37+
`patch`
38+
`pipeline`
39+
`recur`
40+
`script`
41+
`select`
42+
`set`
43+
`sliding`
44+
`state`
45+
`stream`
46+
`to`
47+
`tumbling`
48+
`update`
49+
`use`
50+
`when`
51+
`where`
52+
`window`
53+
`with`
54+
55+
----------------------------------------------------
56+
57+
[
58+
["identifier", "`args`"],
59+
["identifier", "`as`"],
60+
["identifier", "`by`"],
61+
["identifier", "`case`"],
62+
["identifier", "`config`"],
63+
["identifier", "`connect`"],
64+
["identifier", "`connector`"],
65+
["identifier", "`const`"],
66+
["identifier", "`copy`"],
67+
["identifier", "`create`"],
68+
["identifier", "`default`"],
69+
["identifier", "`define`"],
70+
["identifier", "`deploy`"],
71+
["identifier", "`drop`"],
72+
["identifier", "`each`"],
73+
["identifier", "`emit`"],
74+
["identifier", "`end`"],
75+
["identifier", "`erase`"],
76+
["identifier", "`event`"],
77+
["identifier", "`flow`"],
78+
["identifier", "`fn`"],
79+
["identifier", "`for`"],
80+
["identifier", "`from`"],
81+
["identifier", "`group`"],
82+
["identifier", "`having`"],
83+
["identifier", "`insert`"],
84+
["identifier", "`into`"],
85+
["identifier", "`intrinsic`"],
86+
["identifier", "`let`"],
87+
["identifier", "`links`"],
88+
["identifier", "`match`"],
89+
["identifier", "`merge`"],
90+
["identifier", "`mod`"],
91+
["identifier", "`move`"],
92+
["identifier", "`of`"],
93+
["identifier", "`operator`"],
94+
["identifier", "`patch`"],
95+
["identifier", "`pipeline`"],
96+
["identifier", "`recur`"],
97+
["identifier", "`script`"],
98+
["identifier", "`select`"],
99+
["identifier", "`set`"],
100+
["identifier", "`sliding`"],
101+
["identifier", "`state`"],
102+
["identifier", "`stream`"],
103+
["identifier", "`to`"],
104+
["identifier", "`tumbling`"],
105+
["identifier", "`update`"],
106+
["identifier", "`use`"],
107+
["identifier", "`when`"],
108+
["identifier", "`where`"],
109+
["identifier", "`window`"],
110+
["identifier", "`with`"]
111+
]
112+
113+
----------------------------------------------------
114+
115+
Checks for variables.
+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
args
2+
as
3+
by
4+
case
5+
config
6+
connect
7+
connector
8+
const
9+
copy
10+
create
11+
default
12+
define
13+
deploy
14+
drop
15+
each
16+
emit
17+
end
18+
erase
19+
event
20+
flow
21+
fn
22+
for
23+
from
24+
group
25+
having
26+
insert
27+
into
28+
intrinsic
29+
let
30+
links
31+
match
32+
merge
33+
mod
34+
move
35+
of
36+
operator
37+
patch
38+
pipeline
39+
recur
40+
script
41+
select
42+
set
43+
sliding
44+
state
45+
stream
46+
to
47+
tumbling
48+
update
49+
use
50+
when
51+
where
52+
window
53+
with
54+
55+
----------------------------------------------------
56+
57+
[
58+
["keyword", "args"],
59+
["keyword", "as"],
60+
["keyword", "by"],
61+
["keyword", "case"],
62+
["keyword", "config"],
63+
["keyword", "connect"],
64+
["keyword", "connector"],
65+
["keyword", "const"],
66+
["keyword", "copy"],
67+
["keyword", "create"],
68+
["keyword", "default"],
69+
["keyword", "define"],
70+
["keyword", "deploy"],
71+
["keyword", "drop"],
72+
["keyword", "each"],
73+
["keyword", "emit"],
74+
["keyword", "end"],
75+
["keyword", "erase"],
76+
["keyword", "event"],
77+
["keyword", "flow"],
78+
["keyword", "fn"],
79+
["keyword", "for"],
80+
["keyword", "from"],
81+
["keyword", "group"],
82+
["keyword", "having"],
83+
["keyword", "insert"],
84+
["keyword", "into"],
85+
["keyword", "intrinsic"],
86+
["keyword", "let"],
87+
["keyword", "links"],
88+
["keyword", "match"],
89+
["keyword", "merge"],
90+
["keyword", "mod"],
91+
["keyword", "move"],
92+
["keyword", "of"],
93+
["keyword", "operator"],
94+
["keyword", "patch"],
95+
["keyword", "pipeline"],
96+
["keyword", "recur"],
97+
["keyword", "script"],
98+
["keyword", "select"],
99+
["keyword", "set"],
100+
["keyword", "sliding"],
101+
["keyword", "state"],
102+
["keyword", "stream"],
103+
["keyword", "to"],
104+
["keyword", "tumbling"],
105+
["keyword", "update"],
106+
["keyword", "use"],
107+
["keyword", "when"],
108+
["keyword", "where"],
109+
["keyword", "window"],
110+
["keyword", "with"]
111+
]
112+
113+
----------------------------------------------------
114+
115+
Checks for keywords.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
foo
2+
foo::bar
3+
foo::bar::baz
4+
`foo`::bar::`baz`
5+
`foo`
6+
`foo`::`bar`::`baz`
7+
8+
----------------------------------------------------
9+
10+
[
11+
"foo\r\nfoo",
12+
["punctuation", "::"],
13+
"bar\r\nfoo",
14+
["punctuation", "::"],
15+
"bar",
16+
["punctuation", "::"],
17+
"baz\r\n",
18+
19+
["identifier", "`foo`"],
20+
["punctuation", "::"],
21+
"bar",
22+
["punctuation", "::"],
23+
["identifier", "`baz`"],
24+
25+
["identifier", "`foo`"],
26+
27+
["identifier", "`foo`"],
28+
["punctuation", "::"],
29+
["identifier", "`bar`"],
30+
["punctuation", "::"],
31+
["identifier", "`baz`"]
32+
]
33+
34+
----------------------------------------------------
35+
36+
Checks modularity and references for bare/namespaced variables
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
42
2+
0.154
3+
0xBadFace
4+
0b10101010
5+
1_000_000_000
6+
7+
----------------------------------------------------
8+
9+
[
10+
["number", "42"],
11+
["number", "0.154"],
12+
["number", "0xBadFace"],
13+
["number", "0b10101010"],
14+
["number", "1_000_000_000"]
15+
]
16+
17+
----------------------------------------------------
18+
19+
Checks for decimal and hexadecimal numbers.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
+ - / * % ~ ^ & |
2+
+= -= /= *= %= ~= ^= &= |=
3+
== != < > <= >=
4+
= =>
5+
6+
! && ||
7+
8+
<< >> >>>
9+
<<= >>= >>>=
10+
11+
not and or xor present absent
12+
13+
----------------------------------------------------
14+
15+
[
16+
["operator", "+"],
17+
["operator", "-"],
18+
["operator", "/"],
19+
["operator", "*"],
20+
["operator", "%"],
21+
["operator", "~"],
22+
["operator", "^"],
23+
["operator", "&"],
24+
["operator", "|"],
25+
26+
["operator", "+="],
27+
["operator", "-="],
28+
["operator", "/="],
29+
["operator", "*="],
30+
["operator", "%="],
31+
["operator", "~="],
32+
["operator", "^="],
33+
["operator", "&="],
34+
["operator", "|="],
35+
36+
["operator", "=="],
37+
["operator", "!="],
38+
["operator", "<"],
39+
["operator", ">"],
40+
["operator", "<="],
41+
["operator", ">="],
42+
43+
["operator", "="],
44+
["operator", "=>"],
45+
46+
["operator", "!"], ["operator", "&&"], ["operator", "||"],
47+
48+
["operator", "<<"], ["operator", ">>"], ["operator", ">>>"],
49+
["operator", "<<="], ["operator", ">>="], ["operator", ">>>="],
50+
51+
["operator", "not"],
52+
["operator", "and"],
53+
["operator", "or"],
54+
["operator", "xor"],
55+
["operator", "present"],
56+
["operator", "absent"]
57+
]
58+
59+
----------------------------------------------------
60+
61+
Checks for operators
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
( ) [ ] { }
2+
, ; . :
3+
%( ) %[ ] %{ }
4+
5+
----------------------------------------------------
6+
7+
[
8+
["punctuation", "("],
9+
["punctuation", ")"],
10+
["punctuation", "["],
11+
["punctuation", "]"],
12+
["punctuation", "{"],
13+
["punctuation", "}"],
14+
15+
["punctuation", ","],
16+
["punctuation", ";"],
17+
["punctuation", "."],
18+
["punctuation", ":"],
19+
20+
["pattern-punctuation", "%"],
21+
["punctuation", "("],
22+
["punctuation", ")"],
23+
["pattern-punctuation", "%"],
24+
["punctuation", "["],
25+
["punctuation", "]"],
26+
["pattern-punctuation", "%"],
27+
["punctuation", "{"],
28+
["punctuation", "}"]
29+
]
+87
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
""
2+
"" ""
3+
"""
4+
"""
5+
"fo\"obar"
6+
"foo\
7+
bar"
8+
"""
9+
multiline
10+
"""
11+
"snot#{badger}badger"
12+
"""
13+
I am
14+
a
15+
long
16+
multi-line
17+
string with #{ "#{a+1} interpolation" }
18+
"""
19+
20+
----------------------------------------------------
21+
22+
[
23+
["interpolated-string", [
24+
["string", "\"\""]
25+
]],
26+
27+
["interpolated-string", [
28+
["string", "\"\""]
29+
]],
30+
["interpolated-string", [
31+
["string", "\"\""]
32+
]],
33+
34+
["interpolated-string", [
35+
["string", "\"\"\"\r\n\"\"\""]
36+
]],
37+
38+
["interpolated-string", [
39+
["string", "\"fo\\\"obar\""]
40+
]],
41+
42+
["interpolated-string", [
43+
["string", "\"foo\\\r\nbar\""]
44+
]],
45+
46+
["interpolated-string", [
47+
["string", "\"\"\"\r\nmultiline\r\n\"\"\""]
48+
]],
49+
50+
["interpolated-string", [
51+
["string", "\"snot"],
52+
["interpolation", [
53+
["punctuation", "#{"],
54+
["expression", ["badger"]],
55+
["punctuation", "}"]
56+
]],
57+
["string", "badger\""]
58+
]],
59+
60+
["interpolated-string", [
61+
["string", "\"\"\"\r\n I am\r\n a\r\n long\r\n multi-line\r\n string with "],
62+
["interpolation", [
63+
["punctuation", "#{"],
64+
["expression", [
65+
["interpolated-string", [
66+
["string", "\""],
67+
["interpolation", [
68+
["punctuation", "#{"],
69+
["expression", [
70+
"a",
71+
["operator", "+"],
72+
["number", "1"]
73+
]],
74+
["punctuation", "}"]
75+
]],
76+
["string", " interpolation\""]
77+
]]
78+
]],
79+
["punctuation", "}"]
80+
]],
81+
["string", "\r\n\"\"\""]
82+
]]
83+
]
84+
85+
----------------------------------------------------
86+
87+
Checks for strings.

0 commit comments

Comments
 (0)
Please sign in to comment.