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

Added support for WarpScript #2307

Merged
merged 2 commits into from Apr 27, 2020
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.

4 changes: 4 additions & 0 deletions components.json
Expand Up @@ -1105,6 +1105,10 @@
"alias": "vb",
"owner": "Golmote"
},
"warpscript": {
"title": "WarpScript",
"owner": "RunDevelopment"
},
"wasm": {
"title": "WebAssembly",
"owner": "Golmote"
Expand Down
21 changes: 21 additions & 0 deletions components/prism-warpscript.js
@@ -0,0 +1,21 @@
Prism.languages.warpscript = {
'comment': /#.*|\/\/.*|\/\*[\s\S]*?\*\//,
'string': {
pattern: /"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'|<'(?:[^\\']|'(?!>)|\\.)*'>/,
greedy: true
},
'variable': /\$\S+/,
'macro': {
pattern: /@\S+/,
alias: 'property'
},
// WarpScript doesn't have any keywords, these are all functions under the control category
// https://www.warp10.io/tags/control
'keyword': /\b(?:BREAK|CHECKMACRO|CONTINUE|CUDF|DEFINED|DEFINEDMACRO|EVAL|FAIL|FOR|FOREACH|FORSTEP|IFT|IFTE|MSGFAIL|NRETURN|RETHROW|RETURN|SWITCH|TRY|UDF|UNTIL|WHILE)\b/,
'number': /[+-]?\b(?:NaN|Infinity|\d+(?:\.\d*)?(?:[Ee][+-]?\d+)?|0x[\da-fA-F]+|0b[01]+)\b/,
'boolean': /\b(?:false|true|F|T)\b/,
'punctuation': /<%|%>|[{}[\]()]/,
// Some operators from the "operators" category
// https://www.warp10.io/tags/operators
'operator': /==|&&?|\|\|?|\*\*?|>>>?|<<|==|[<>!~]=?|[-/%^]|\+!?|\b(?:AND|NOT|OR)\b/
};
1 change: 1 addition & 0 deletions components/prism-warpscript.min.js

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

22 changes: 22 additions & 0 deletions examples/prism-warpscript.html
@@ -0,0 +1,22 @@
<h2>Full example</h2>
<pre><code>// Source: https://www.warp10.io/content/04_Tutorials/01_WarpScript/05_Best_Practices

//factorial macro. take a number on the stack, push its factorial
&lt;%
'input' STORE
1
1 $input &lt;% * %> FOR
%> 'factorial' STORE

//build a map with key from 1 to 10 and value = key!
{} 'result' STORE

1 10
&lt;%
'key' STORE
$result $key @factorial $key PUT
DROP //remove the map let by PUT
%> FOR

//push the result on the stack
$result</code></pre>
17 changes: 17 additions & 0 deletions tests/languages/warpscript/boolean_feature.test
@@ -0,0 +1,17 @@
false
true
F
T

----------------------------------------------------

[
["boolean", "false"],
["boolean", "true"],
["boolean", "F"],
["boolean", "T"]
]

----------------------------------------------------

Checks for booleans.
19 changes: 19 additions & 0 deletions tests/languages/warpscript/comment_feature.test
@@ -0,0 +1,19 @@
# Python style comments, starting with a '#' and extending to the end of the line

// Java style comments, extending to the end of the line after the '//'

/*
C style block comments, possibly spanning multiple lines
*/

----------------------------------------------------

[
["comment", "# Python style comments, starting with a '#' and extending to the end of the line"],
["comment", "// Java style comments, extending to the end of the line after the '//'"],
["comment", "/*\r\n C style block comments, possibly spanning multiple lines\r\n*/"]
]

----------------------------------------------------

Checks for comments.
35 changes: 35 additions & 0 deletions tests/languages/warpscript/number_feature.test
@@ -0,0 +1,35 @@
123
-123
5e4
5e-4
123.546
123.546E-5

0xFFF
0b10101

NaN
Infinity
-Infinity

----------------------------------------------------

[
["number", "123"],
["number", "-123"],
["number", "5e4"],
["number", "5e-4"],
["number", "123.546"],
["number", "123.546E-5"],

["number", "0xFFF"],
["number", "0b10101"],

["number", "NaN"],
["number", "Infinity"],
["number", "-Infinity"]
]

----------------------------------------------------

Checks for numbers.
45 changes: 45 additions & 0 deletions tests/languages/warpscript/operator_feature.test
@@ -0,0 +1,45 @@
!= < > ~= <= == >=
% * + - / **
! && AND OR NOT ||
& ^ | >>> ~ << >>
+!

----------------------------------------------------

[
["operator", "!="],
["operator", "<"],
["operator", ">"],
["operator", "~="],
["operator", "<="],
["operator", "=="],
["operator", ">="],

["operator", "%"],
["operator", "*"],
["operator", "+"],
["operator", "-"],
["operator", "/"],
["operator", "**"],

["operator", "!"],
["operator", "&&"],
["operator", "AND"],
["operator", "OR"],
["operator", "NOT"],
["operator", "||"],

["operator", "&"],
["operator", "^"],
["operator", "|"],
["operator", ">>>"],
["operator", "~"],
["operator", "<<"],
["operator", ">>"],

["operator", "+!"]
]

----------------------------------------------------

Checks for operators.
19 changes: 19 additions & 0 deletions tests/languages/warpscript/punctuation_feature.test
@@ -0,0 +1,19 @@
<% %>
( ) [ ] { }

----------------------------------------------------

[
["punctuation", "<%"],
["punctuation", "%>"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", "{"],
["punctuation", "}"]
]

----------------------------------------------------

Checks for punctuation.
19 changes: 19 additions & 0 deletions tests/languages/warpscript/string_feature.test
@@ -0,0 +1,19 @@
'Caf%C3%A9'

"foo"

<'
foo
'>

----------------------------------------------------

[
["string", "'Caf%C3%A9'"],
["string", "\"foo\""],
["string", "<'\r\n foo\r\n'>"]
]

----------------------------------------------------

Checks for strings.