Added support for Warpscript (#2307)

This commit is contained in:
Michael Schmidt 2020-04-27 22:39:29 +02:00 committed by GitHub
parent 1093ceb31d
commit cde5b0fab7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 203 additions and 1 deletions

File diff suppressed because one or more lines are too long

View File

@ -1105,6 +1105,10 @@
"alias": "vb",
"owner": "Golmote"
},
"warpscript": {
"title": "WarpScript",
"owner": "RunDevelopment"
},
"wasm": {
"title": "WebAssembly",
"owner": "Golmote"

View File

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

@ -0,0 +1 @@
Prism.languages.warpscript={comment:/#.*|\/\/.*|\/\*[\s\S]*?\*\//,string:{pattern:/"(?:[^"\\\r\n]|\\.)*"|'(?:[^'\\\r\n]|\\.)*'|<'(?:[^\\']|'(?!>)|\\.)*'>/,greedy:!0},variable:/\$\S+/,macro:{pattern:/@\S+/,alias:"property"},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:/<%|%>|[{}[\]()]/,operator:/==|&&?|\|\|?|\*\*?|>>>?|<<|==|[<>!~]=?|[-/%^]|\+!?|\b(?:AND|NOT|OR)\b/};

View File

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

View File

@ -0,0 +1,17 @@
false
true
F
T
----------------------------------------------------
[
["boolean", "false"],
["boolean", "true"],
["boolean", "F"],
["boolean", "T"]
]
----------------------------------------------------
Checks for booleans.

View File

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

View File

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

View File

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

View File

@ -0,0 +1,19 @@
<% %>
( ) [ ] { }
----------------------------------------------------
[
["punctuation", "<%"],
["punctuation", "%>"],
["punctuation", "("],
["punctuation", ")"],
["punctuation", "["],
["punctuation", "]"],
["punctuation", "{"],
["punctuation", "}"]
]
----------------------------------------------------
Checks for punctuation.

View File

@ -0,0 +1,19 @@
'Caf%C3%A9'
"foo"
<'
foo
'>
----------------------------------------------------
[
["string", "'Caf%C3%A9'"],
["string", "\"foo\""],
["string", "<'\r\n foo\r\n'>"]
]
----------------------------------------------------
Checks for strings.