Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tremor project DSL langauge definitions #3087

Merged
merged 8 commits into from Sep 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions components.json
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
@@ -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
@@ -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
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
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