Added Tremor project DSL language definition (#3087)

* 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>
This commit is contained in:
Darach Ennis 2021-09-21 21:19:47 +02:00 committed by GitHub
parent 99d94fa7c3
commit ec25ba6527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 689 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -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",

View File

@ -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
components/prism-tremor.min.js vendored Normal file
View File

@ -0,0 +1 @@
!function(e){e.languages.tremor={comment:{pattern:/(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,lookbehind:!0},"interpolated-string":null,extractor:{pattern:/\b[a-z_]\w*\|(?:[^\r\n\\|]|\\(?:\r\n|[\s\S]))*\|/i,greedy:!0,inside:{function:/^\w+/,regex:/\|[\s\S]+/}},identifier:{pattern:/`[^`]*`/,greedy:!0},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 n='#\\{(?:[^"{}]|\\{[^{}]*\\}|"(?:[^"\\\\\r\n]|\\\\(?:\r\n|[^]))*")*\\}';e.languages.tremor["interpolated-string"]={pattern:RegExp('(^|[^\\\\])(?:"""(?:[^"\\\\#]|\\\\[^]|"(?!"")|#(?!\\{)|'+n+')*"""|"(?:[^"\\\\\r\n#]|\\\\(?:\r\n|[^])|#(?!\\{)|'+n+')*")'),lookbehind:!0,greedy:!0,inside:{interpolation:{pattern:RegExp(n),inside:{punctuation:/^#\{|\}$/,expression:{pattern:/[\s\S]+/,inside:e.languages.tremor}}},string:/[\s\S]+/}},e.languages.troy=e.languages.tremor,e.languages.trickle=e.languages.tremor}(Prism);

View File

@ -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>

View File

@ -239,6 +239,8 @@
"sln": "solution-file",
"rq": "sparql",
"t4": "t4-cs",
"trickle": "tremor",
"troy": "tremor",
"trig": "turtle",
"ts": "typescript",
"tsconfig": "typoscript",

File diff suppressed because one or more lines are too long

View File

@ -227,6 +227,8 @@
"tap": "TAP",
"tt2": "Template Toolkit 2",
"toml": "TOML",
"trickle": "trickle",
"troy": "troy",
"trig": "TriG",
"ts": "TypeScript",
"tsconfig": "TSConfig",

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,15 @@
true
false
null
----------------------------------------------------
[
["boolean", "true"],
["boolean", "false"],
["boolean", "null"]
]
----------------------------------------------------
Checks for booleans.

View File

@ -0,0 +1,15 @@
#
## foobar
### snot badger
----------------------------------------------------
[
["comment", "#"],
["comment", "## foobar"],
["comment", "### snot badger"]
]
----------------------------------------------------
Checks for comments.

View File

@ -0,0 +1,15 @@
re|^(?P<kind>bat.*)$|
datetime|%Y-%m-%d %H:%M|
----------------------------------------------------
[
["extractor", [
["function", "re"],
["regex", "|^(?P<kind>bat.*)$|"]
]],
["extractor", [
["function", "datetime"],
["regex", "|%Y-%m-%d %H:%M|"]
]]
]

View File

@ -0,0 +1,12 @@
foo
foo_bar_42
`foo`
`bar`
----------------------------------------------------
[
"foo\r\nfoo_bar_42\r\n",
["identifier", "`foo`"],
["identifier", "`bar`"]
]

View File

@ -0,0 +1,115 @@
`args`
`as`
`by`
`case`
`config`
`connect`
`connector`
`const`
`copy`
`create`
`default`
`define`
`deploy`
`drop`
`each`
`emit`
`end`
`erase`
`event`
`flow`
`fn`
`for`
`from`
`group`
`having`
`insert`
`into`
`intrinsic`
`let`
`links`
`match`
`merge`
`mod`
`move`
`of`
`operator`
`patch`
`pipeline`
`recur`
`script`
`select`
`set`
`sliding`
`state`
`stream`
`to`
`tumbling`
`update`
`use`
`when`
`where`
`window`
`with`
----------------------------------------------------
[
["identifier", "`args`"],
["identifier", "`as`"],
["identifier", "`by`"],
["identifier", "`case`"],
["identifier", "`config`"],
["identifier", "`connect`"],
["identifier", "`connector`"],
["identifier", "`const`"],
["identifier", "`copy`"],
["identifier", "`create`"],
["identifier", "`default`"],
["identifier", "`define`"],
["identifier", "`deploy`"],
["identifier", "`drop`"],
["identifier", "`each`"],
["identifier", "`emit`"],
["identifier", "`end`"],
["identifier", "`erase`"],
["identifier", "`event`"],
["identifier", "`flow`"],
["identifier", "`fn`"],
["identifier", "`for`"],
["identifier", "`from`"],
["identifier", "`group`"],
["identifier", "`having`"],
["identifier", "`insert`"],
["identifier", "`into`"],
["identifier", "`intrinsic`"],
["identifier", "`let`"],
["identifier", "`links`"],
["identifier", "`match`"],
["identifier", "`merge`"],
["identifier", "`mod`"],
["identifier", "`move`"],
["identifier", "`of`"],
["identifier", "`operator`"],
["identifier", "`patch`"],
["identifier", "`pipeline`"],
["identifier", "`recur`"],
["identifier", "`script`"],
["identifier", "`select`"],
["identifier", "`set`"],
["identifier", "`sliding`"],
["identifier", "`state`"],
["identifier", "`stream`"],
["identifier", "`to`"],
["identifier", "`tumbling`"],
["identifier", "`update`"],
["identifier", "`use`"],
["identifier", "`when`"],
["identifier", "`where`"],
["identifier", "`window`"],
["identifier", "`with`"]
]
----------------------------------------------------
Checks for variables.

View File

@ -0,0 +1,115 @@
args
as
by
case
config
connect
connector
const
copy
create
default
define
deploy
drop
each
emit
end
erase
event
flow
fn
for
from
group
having
insert
into
intrinsic
let
links
match
merge
mod
move
of
operator
patch
pipeline
recur
script
select
set
sliding
state
stream
to
tumbling
update
use
when
where
window
with
----------------------------------------------------
[
["keyword", "args"],
["keyword", "as"],
["keyword", "by"],
["keyword", "case"],
["keyword", "config"],
["keyword", "connect"],
["keyword", "connector"],
["keyword", "const"],
["keyword", "copy"],
["keyword", "create"],
["keyword", "default"],
["keyword", "define"],
["keyword", "deploy"],
["keyword", "drop"],
["keyword", "each"],
["keyword", "emit"],
["keyword", "end"],
["keyword", "erase"],
["keyword", "event"],
["keyword", "flow"],
["keyword", "fn"],
["keyword", "for"],
["keyword", "from"],
["keyword", "group"],
["keyword", "having"],
["keyword", "insert"],
["keyword", "into"],
["keyword", "intrinsic"],
["keyword", "let"],
["keyword", "links"],
["keyword", "match"],
["keyword", "merge"],
["keyword", "mod"],
["keyword", "move"],
["keyword", "of"],
["keyword", "operator"],
["keyword", "patch"],
["keyword", "pipeline"],
["keyword", "recur"],
["keyword", "script"],
["keyword", "select"],
["keyword", "set"],
["keyword", "sliding"],
["keyword", "state"],
["keyword", "stream"],
["keyword", "to"],
["keyword", "tumbling"],
["keyword", "update"],
["keyword", "use"],
["keyword", "when"],
["keyword", "where"],
["keyword", "window"],
["keyword", "with"]
]
----------------------------------------------------
Checks for keywords.

View File

@ -0,0 +1,36 @@
foo
foo::bar
foo::bar::baz
`foo`::bar::`baz`
`foo`
`foo`::`bar`::`baz`
----------------------------------------------------
[
"foo\r\nfoo",
["punctuation", "::"],
"bar\r\nfoo",
["punctuation", "::"],
"bar",
["punctuation", "::"],
"baz\r\n",
["identifier", "`foo`"],
["punctuation", "::"],
"bar",
["punctuation", "::"],
["identifier", "`baz`"],
["identifier", "`foo`"],
["identifier", "`foo`"],
["punctuation", "::"],
["identifier", "`bar`"],
["punctuation", "::"],
["identifier", "`baz`"]
]
----------------------------------------------------
Checks modularity and references for bare/namespaced variables

View File

@ -0,0 +1,19 @@
42
0.154
0xBadFace
0b10101010
1_000_000_000
----------------------------------------------------
[
["number", "42"],
["number", "0.154"],
["number", "0xBadFace"],
["number", "0b10101010"],
["number", "1_000_000_000"]
]
----------------------------------------------------
Checks for decimal and hexadecimal numbers.

View File

@ -0,0 +1,61 @@
+ - / * % ~ ^ & |
+= -= /= *= %= ~= ^= &= |=
== != < > <= >=
= =>
! && ||
<< >> >>>
<<= >>= >>>=
not and or xor present absent
----------------------------------------------------
[
["operator", "+"],
["operator", "-"],
["operator", "/"],
["operator", "*"],
["operator", "%"],
["operator", "~"],
["operator", "^"],
["operator", "&"],
["operator", "|"],
["operator", "+="],
["operator", "-="],
["operator", "/="],
["operator", "*="],
["operator", "%="],
["operator", "~="],
["operator", "^="],
["operator", "&="],
["operator", "|="],
["operator", "=="],
["operator", "!="],
["operator", "<"],
["operator", ">"],
["operator", "<="],
["operator", ">="],
["operator", "="],
["operator", "=>"],
["operator", "!"], ["operator", "&&"], ["operator", "||"],
["operator", "<<"], ["operator", ">>"], ["operator", ">>>"],
["operator", "<<="], ["operator", ">>="], ["operator", ">>>="],
["operator", "not"],
["operator", "and"],
["operator", "or"],
["operator", "xor"],
["operator", "present"],
["operator", "absent"]
]
----------------------------------------------------
Checks for operators

View File

@ -0,0 +1,29 @@
( ) [ ] { }
, ; . :
%( ) %[ ] %{ }
----------------------------------------------------
[
["punctuation", "("],
["punctuation", ")"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", "{"],
["punctuation", "}"],
["punctuation", ","],
["punctuation", ";"],
["punctuation", "."],
["punctuation", ":"],
["pattern-punctuation", "%"],
["punctuation", "("],
["punctuation", ")"],
["pattern-punctuation", "%"],
["punctuation", "["],
["punctuation", "]"],
["pattern-punctuation", "%"],
["punctuation", "{"],
["punctuation", "}"]
]

View File

@ -0,0 +1,87 @@
""
"" ""
"""
"""
"fo\"obar"
"foo\
bar"
"""
multiline
"""
"snot#{badger}badger"
"""
I am
a
long
multi-line
string with #{ "#{a+1} interpolation" }
"""
----------------------------------------------------
[
["interpolated-string", [
["string", "\"\""]
]],
["interpolated-string", [
["string", "\"\""]
]],
["interpolated-string", [
["string", "\"\""]
]],
["interpolated-string", [
["string", "\"\"\"\r\n\"\"\""]
]],
["interpolated-string", [
["string", "\"fo\\\"obar\""]
]],
["interpolated-string", [
["string", "\"foo\\\r\nbar\""]
]],
["interpolated-string", [
["string", "\"\"\"\r\nmultiline\r\n\"\"\""]
]],
["interpolated-string", [
["string", "\"snot"],
["interpolation", [
["punctuation", "#{"],
["expression", ["badger"]],
["punctuation", "}"]
]],
["string", "badger\""]
]],
["interpolated-string", [
["string", "\"\"\"\r\n I am\r\n a\r\n long\r\n multi-line\r\n string with "],
["interpolation", [
["punctuation", "#{"],
["expression", [
["interpolated-string", [
["string", "\""],
["interpolation", [
["punctuation", "#{"],
["expression", [
"a",
["operator", "+"],
["number", "1"]
]],
["punctuation", "}"]
]],
["string", " interpolation\""]
]]
]],
["punctuation", "}"]
]],
["string", "\r\n\"\"\""]
]]
]
----------------------------------------------------
Checks for strings.