Skip to content

Commit

Permalink
Added Tremor project DSL language definition (#3087)
Browse files Browse the repository at this point in the history
* Add tremor project DSL langauge definitions

Signed-off-by: Darach Ennis <darach@gmail.com>

* Update components/prism-tremor.js

Apply fix worst-case time complexity per @RunDevelopment's insight

Co-authored-by: Michael Schmidt <msrd0000@gmail.com>

* Update components/prism-tremor.js

Terser formulation of pattern

Co-authored-by: Michael Schmidt <msrd0000@gmail.com>

* Update components/prism-tremor.js

Terser formulation of pattern

Co-authored-by: Michael Schmidt <msrd0000@gmail.com>

* Update components/prism-tremor.js

Terser formulation of pattern

Co-authored-by: Michael Schmidt <msrd0000@gmail.com>

* Add partial interpolation, expand tests, attend to lints

Signed-off-by: Darach Ennis <darach@gmail.com>

* Improved Tremor tokenization

Signed-off-by: Michael Schmidt <mitchi5000.ms@googlemail.com>

Co-authored-by: Michael Schmidt <msrd0000@gmail.com>
Co-authored-by: Michael Schmidt <mitchi5000.ms@googlemail.com>
  • Loading branch information
3 people authored Sep 21, 2021
1 parent 99d94fa commit ec25ba6
Show file tree
Hide file tree
Showing 20 changed files with 689 additions and 3 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,18 @@
"title": "TOML",
"owner": "RunDevelopment"
},
"tremor": {
"title": "Tremor",
"alias": [
"trickle",
"troy"
],
"owner": "darach",
"aliasTitles": {
"trickle": "trickle",
"troy": "troy"
}
},
"turtle": {
"title": "Turtle",
"alias": "trig",
Expand Down
68 changes: 68 additions & 0 deletions components/prism-tremor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
(function (Prism) {

Prism.languages.tremor = {
'comment': {
pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
lookbehind: true
},
'interpolated-string': null, // see below
'extractor': {
pattern: /\b[a-z_]\w*\|(?:[^\r\n\\|]|\\(?:\r\n|[\s\S]))*\|/i,
greedy: true,
inside: {
'function': /^\w+/,
'regex': /\|[\s\S]+/,
}
},
'identifier': {
pattern: /`[^`]*`/,
greedy: true
},

'function': /\b[a-z_]\w*(?=\s*(?:::\s*<|\())\b/,

'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/,
'boolean': /\b(?:true|false|null)\b/i,

'number': /\b(?:0b[0-1_]*|0x[0-9a-fA-F_]*|\d[0-9_]*(?:\.\d[0-9_]*)?(?:[Ee][+-]?[0-9_]+)?)\b/,

'pattern-punctuation': {
pattern: /%(?=[({[])/,
alias: 'punctuation'
},
'operator': /[-+*\/%~!^]=?|=[=>]?|&[&=]?|\|[|=]?|<<?=?|>>?>?=?|(?:not|and|or|xor|present|absent)\b/,
'punctuation': /::|[;\[\]()\{\},.:]/,
};

var interpolationPattern = /#\{(?:[^"{}]|\{[^{}]*\}|"(?:[^"\\\r\n]|\\(?:\r\n|[\s\S]))*")*\}/.source;

Prism.languages.tremor['interpolated-string'] = {
pattern: RegExp(
/(^|[^\\])/.source +
'(?:' +
'"""(?:' + /[^"\\#]|\\[\s\S]|"(?!"")|#(?!\{)/.source + '|' + interpolationPattern + ')*"""' +
'|' +
'"(?:' + /[^"\\\r\n#]|\\(?:\r\n|[\s\S])|#(?!\{)/.source + '|' + interpolationPattern + ')*"' +
')'
),
lookbehind: true,
greedy: true,
inside: {
'interpolation': {
pattern: RegExp(interpolationPattern),
inside: {
'punctuation': /^#\{|\}$/,
'expression': {
pattern: /[\s\S]+/,
inside: Prism.languages.tremor
}
}
},
'string': /[\s\S]+/
}
};

Prism.languages.troy = Prism.languages['tremor'];
Prism.languages.trickle = Prism.languages['tremor'];

}(Prism));
1 change: 1 addition & 0 deletions components/prism-tremor.min.js

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

82 changes: 82 additions & 0 deletions examples/prism-tremor.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<h2>Comments</h2>
<pre><code># Single line comment
### Module level documentation comment
## Statement level documentation comment
# Regular code comment
</code></pre>

<h2>Strings</h2>
<pre><code>
# double quote single line strings
"foo \"bar\" baz"

# heredocs or multiline strings
"""
{ "snot": "badger" }
"""
</code></pre>

<h2>Variables</h2>
<pre><code>
# Immutable constants
const snot = "fleek";

# Mutable variables
let badger = "flook";
</code></pre>

<h2>Operators</h2>
<pre><code>
merge {} of
{ "snot": "badger" }
end;

patch {} of
insert snot = "badger"
end;
</code></pre>

<h2>Functions and keywords</h2>
<pre><code>
fn fib_(a, b, n) of
case (a, b, n) when n > 0 => recur(b, a + b, n - 1)
default => a
end;

fn fib(n) with
fib_(0, 1, n)
end;

fib(event)
</code></pre>

<h2>Queries</h2>
<pre><code>
define script fib
script
fn fib_(a, b, n) of
case (a, b, n) when n > 0 => recur(b, a + b, n - 1)
default => a
end;

fn fib(n) with
fib_(0, 1, n)
end;

{ "fib": fib(event.n) }
end;

create script fib;
select event.n from in into fib;
select event from fib into out;
</code></pre>

<h2>Deployments</h2>
<pre><code>
define pipeline passthrough
pipeline
select event from in into out;
end;

deploy pipeline passthrough;
</code></pre>
2 changes: 2 additions & 0 deletions plugins/autoloader/prism-autoloader.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@
"sln": "solution-file",
"rq": "sparql",
"t4": "t4-cs",
"trickle": "tremor",
"troy": "tremor",
"trig": "turtle",
"ts": "typescript",
"tsconfig": "typoscript",
Expand Down
2 changes: 1 addition & 1 deletion plugins/autoloader/prism-autoloader.min.js

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

2 changes: 2 additions & 0 deletions plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,8 @@
"tap": "TAP",
"tt2": "Template Toolkit 2",
"toml": "TOML",
"trickle": "trickle",
"troy": "troy",
"trig": "TriG",
"ts": "TypeScript",
"tsconfig": "TSConfig",
Expand Down
Loading

0 comments on commit ec25ba6

Please sign in to comment.