Skip to content

Commit ec25ba6

Browse files
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",

0 commit comments

Comments
 (0)