Added support for Wren (#3063)
This commit is contained in:
parent
4fbdd2f8f8
commit
6a356d253a
File diff suppressed because one or more lines are too long
|
@ -1401,6 +1401,10 @@
|
|||
},
|
||||
"owner": "msollami"
|
||||
},
|
||||
"wren": {
|
||||
"title": "Wren",
|
||||
"owner": "clsource"
|
||||
},
|
||||
"xeora": {
|
||||
"title": "Xeora",
|
||||
"require": "markup",
|
||||
|
|
|
@ -0,0 +1,100 @@
|
|||
// https://wren.io/
|
||||
|
||||
Prism.languages.wren = {
|
||||
// Multiline comments in Wren can have nested multiline comments
|
||||
// Comments: // and /* */
|
||||
'comment': [
|
||||
{
|
||||
// support 3 levels of nesting
|
||||
// regex: \/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\/
|
||||
pattern: /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*))*\*\/)*\*\/)*\*\//,
|
||||
greedy: true
|
||||
},
|
||||
{
|
||||
pattern: /(^|[^\\:])\/\/.*/,
|
||||
lookbehind: true,
|
||||
greedy: true
|
||||
}
|
||||
],
|
||||
|
||||
// Triple quoted strings are multiline but cannot have interpolation (raw strings)
|
||||
// Based on prism-python.js
|
||||
'triple-quoted-string': {
|
||||
pattern: /"""[\s\S]*?"""/,
|
||||
greedy: true,
|
||||
alias: 'string'
|
||||
},
|
||||
|
||||
// see below
|
||||
'string-literal': null,
|
||||
|
||||
// #!/usr/bin/env wren on the first line
|
||||
'hashbang': {
|
||||
pattern: /^#!\/.+/,
|
||||
greedy: true,
|
||||
alias: 'comment'
|
||||
},
|
||||
|
||||
// Attributes are special keywords to add meta data to classes
|
||||
'attribute': {
|
||||
// #! attributes are stored in class properties
|
||||
// #!myvar = true
|
||||
// #attributes are not stored and dismissed at compilation
|
||||
pattern: /#!?[ \t\u3000]*\w+/,
|
||||
alias: 'keyword'
|
||||
},
|
||||
'class-name': [
|
||||
{
|
||||
// class definition
|
||||
// class Meta {}
|
||||
pattern: /(\bclass\s+)\w+/,
|
||||
lookbehind: true
|
||||
},
|
||||
// A class must always start with an uppercase.
|
||||
// File.read
|
||||
/\b[A-Z][a-z\d_]*\b/,
|
||||
],
|
||||
|
||||
// A constant can be a variable, class, property or method. Just named in all uppercase letters
|
||||
'constant': /\b[A-Z][A-Z\d_]*\b/,
|
||||
|
||||
'null': {
|
||||
pattern: /\bnull\b/,
|
||||
alias: 'keyword'
|
||||
},
|
||||
'keyword': /\b(?:as|break|class|construct|continue|else|for|foreign|if|import|in|is|return|static|super|this|var|while)\b/,
|
||||
'boolean': /\b(?:true|false)\b/,
|
||||
'number': /\b(?:0x[\da-f]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/i,
|
||||
|
||||
// Functions can be Class.method()
|
||||
'function': /\b[a-z_]\w*(?=\s*[({])/i,
|
||||
|
||||
'operator': /<<|>>|[=!<>]=?|&&|\|\||[-+*/%~^&|?:]|\.{2,3}/,
|
||||
'punctuation': /[\[\](){}.,;]/,
|
||||
};
|
||||
|
||||
Prism.languages.wren['string-literal'] = {
|
||||
// A single quote string is multiline and can have interpolation (similar to JS backticks ``)
|
||||
pattern: /(^|[^\\"])"(?:[^\\"%]|\\[\s\S]|%(?!\()|%\((?:[^()]|\((?:[^()]|\([^)]*\))*\))*\))*"/,
|
||||
lookbehind: true,
|
||||
greedy: true,
|
||||
inside: {
|
||||
'interpolation': {
|
||||
// "%(interpolation)"
|
||||
pattern: /((?:^|[^\\])(?:\\{2})*)%\((?:[^()]|\((?:[^()]|\([^)]*\))*\))*\)/,
|
||||
lookbehind: true,
|
||||
inside: {
|
||||
'expression': {
|
||||
pattern: /^(%\()[\s\S]+(?=\)$)/,
|
||||
lookbehind: true,
|
||||
inside: Prism.languages.wren
|
||||
},
|
||||
'interpolation-punctuation': {
|
||||
pattern: /^%\(|\)$/,
|
||||
alias: 'punctuation'
|
||||
},
|
||||
}
|
||||
},
|
||||
'string': /[\s\S]+/
|
||||
}
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
Prism.languages.wren={comment:[{pattern:/\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*))*\*\/)*\*\/)*\*\//,greedy:!0},{pattern:/(^|[^\\:])\/\/.*/,lookbehind:!0,greedy:!0}],"triple-quoted-string":{pattern:/"""[\s\S]*?"""/,greedy:!0,alias:"string"},"string-literal":null,hashbang:{pattern:/^#!\/.+/,greedy:!0,alias:"comment"},attribute:{pattern:/#!?[ \t\u3000]*\w+/,alias:"keyword"},"class-name":[{pattern:/(\bclass\s+)\w+/,lookbehind:!0},/\b[A-Z][a-z\d_]*\b/],constant:/\b[A-Z][A-Z\d_]*\b/,null:{pattern:/\bnull\b/,alias:"keyword"},keyword:/\b(?:as|break|class|construct|continue|else|for|foreign|if|import|in|is|return|static|super|this|var|while)\b/,boolean:/\b(?:true|false)\b/,number:/\b(?:0x[\da-f]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/i,function:/\b[a-z_]\w*(?=\s*[({])/i,operator:/<<|>>|[=!<>]=?|&&|\|\||[-+*/%~^&|?:]|\.{2,3}/,punctuation:/[\[\](){}.,;]/},Prism.languages.wren["string-literal"]={pattern:/(^|[^\\"])"(?:[^\\"%]|\\[\s\S]|%(?!\()|%\((?:[^()]|\((?:[^()]|\([^)]*\))*\))*\))*"/,lookbehind:!0,greedy:!0,inside:{interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)%\((?:[^()]|\((?:[^()]|\([^)]*\))*\))*\)/,lookbehind:!0,inside:{expression:{pattern:/^(%\()[\s\S]+(?=\)$)/,lookbehind:!0,inside:Prism.languages.wren},"interpolation-punctuation":{pattern:/^%\(|\)$/,alias:"punctuation"}}},string:/[\s\S]+/}};
|
|
@ -0,0 +1,17 @@
|
|||
<h2>Full example</h2>
|
||||
<pre><code>// Source: https://wren.io/
|
||||
|
||||
System.print("Hello, world!")
|
||||
|
||||
class Wren {
|
||||
flyTo(city) {
|
||||
System.print("Flying to %(city)")
|
||||
}
|
||||
}
|
||||
|
||||
var adjectives = Fiber.new {
|
||||
["small", "clean", "fast"].each {|word| Fiber.yield(word) }
|
||||
}
|
||||
|
||||
while (!adjectives.isDone) System.print(adjectives.call())
|
||||
</code></pre>
|
|
@ -0,0 +1,91 @@
|
|||
#hidden = true
|
||||
class Example {}
|
||||
|
||||
#key
|
||||
#key = value
|
||||
#group(
|
||||
multiple,
|
||||
lines = true,
|
||||
lines = 0
|
||||
)
|
||||
class Example {
|
||||
#test(skip = true, iterations = 32)
|
||||
doStuff() {}
|
||||
}
|
||||
|
||||
#doc = "not runtime data"
|
||||
#!runtimeAccess = true
|
||||
#!maxIterations = 16
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["attribute", "#hidden"],
|
||||
["operator", "="],
|
||||
["boolean", "true"],
|
||||
|
||||
["keyword", "class"],
|
||||
["class-name", "Example"],
|
||||
["punctuation", "{"],
|
||||
["punctuation", "}"],
|
||||
|
||||
["attribute", "#key"],
|
||||
|
||||
["attribute", "#key"],
|
||||
["operator", "="],
|
||||
" value\r\n",
|
||||
|
||||
["attribute", "#group"],
|
||||
["punctuation", "("],
|
||||
|
||||
"\r\n multiple",
|
||||
["punctuation", ","],
|
||||
|
||||
"\r\n lines ",
|
||||
["operator", "="],
|
||||
["boolean", "true"],
|
||||
["punctuation", ","],
|
||||
|
||||
"\r\n lines ",
|
||||
["operator", "="],
|
||||
["number", "0"],
|
||||
|
||||
["punctuation", ")"],
|
||||
|
||||
["keyword", "class"],
|
||||
["class-name", "Example"],
|
||||
["punctuation", "{"],
|
||||
|
||||
["attribute", "#test"],
|
||||
["punctuation", "("],
|
||||
"skip ",
|
||||
["operator", "="],
|
||||
["boolean", "true"],
|
||||
["punctuation", ","],
|
||||
" iterations ",
|
||||
["operator", "="],
|
||||
["number", "32"],
|
||||
["punctuation", ")"],
|
||||
|
||||
["function", "doStuff"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["punctuation", "{"],
|
||||
["punctuation", "}"],
|
||||
|
||||
["punctuation", "}"],
|
||||
|
||||
["attribute", "#doc"],
|
||||
["operator", "="],
|
||||
["string-literal", [
|
||||
["string", "\"not runtime data\""]
|
||||
]],
|
||||
|
||||
["attribute", "#!runtimeAccess"],
|
||||
["operator", "="],
|
||||
["boolean", "true"],
|
||||
|
||||
["attribute", "#!maxIterations"],
|
||||
["operator", "="],
|
||||
["number", "16"]
|
||||
]
|
|
@ -0,0 +1,9 @@
|
|||
true
|
||||
false
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["boolean", "true"],
|
||||
["boolean", "false"]
|
||||
]
|
|
@ -0,0 +1,35 @@
|
|||
Foo.bar()
|
||||
|
||||
import "beverages" for Coffee, Tea
|
||||
|
||||
class Foo {}
|
||||
class foo {}
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["class-name", "Foo"],
|
||||
["punctuation", "."],
|
||||
["function", "bar"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
|
||||
["keyword", "import"],
|
||||
["string-literal", [
|
||||
["string", "\"beverages\""]
|
||||
]],
|
||||
["keyword", "for"],
|
||||
["class-name", "Coffee"],
|
||||
["punctuation", ","],
|
||||
["class-name", "Tea"],
|
||||
|
||||
["keyword", "class"],
|
||||
["class-name", "Foo"],
|
||||
["punctuation", "{"],
|
||||
["punctuation", "}"],
|
||||
|
||||
["keyword", "class"],
|
||||
["class-name", "foo"],
|
||||
["punctuation", "{"],
|
||||
["punctuation", "}"]
|
||||
]
|
|
@ -0,0 +1,21 @@
|
|||
// comment
|
||||
|
||||
/**/
|
||||
/* comment */
|
||||
|
||||
/*
|
||||
/*
|
||||
nested comment
|
||||
*/
|
||||
*/
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["comment", "// comment"],
|
||||
|
||||
["comment", "/**/"],
|
||||
["comment", "/* comment */"],
|
||||
|
||||
["comment", "/*\r\n/*\r\nnested comment\r\n*/\r\n*/"]
|
||||
]
|
|
@ -0,0 +1,19 @@
|
|||
foo()
|
||||
|
||||
foo {|x| x * 2}
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["function", "foo"], ["punctuation", "("], ["punctuation", ")"],
|
||||
|
||||
["function", "foo"],
|
||||
["punctuation", "{"],
|
||||
["operator", "|"],
|
||||
"x",
|
||||
["operator", "|"],
|
||||
" x ",
|
||||
["operator", "*"],
|
||||
["number", "2"],
|
||||
["punctuation", "}"]
|
||||
]
|
|
@ -0,0 +1,7 @@
|
|||
#!/usr/bin/env wren
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["hashbang", "#!/usr/bin/env wren"]
|
||||
]
|
|
@ -0,0 +1,45 @@
|
|||
as;
|
||||
break;
|
||||
class;
|
||||
construct;
|
||||
continue;
|
||||
else;
|
||||
for;
|
||||
foreign;
|
||||
if;
|
||||
import;
|
||||
in;
|
||||
is;
|
||||
return;
|
||||
static;
|
||||
super;
|
||||
this;
|
||||
var;
|
||||
while;
|
||||
|
||||
null
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["keyword", "as"], ["punctuation", ";"],
|
||||
["keyword", "break"], ["punctuation", ";"],
|
||||
["keyword", "class"], ["punctuation", ";"],
|
||||
["keyword", "construct"], ["punctuation", ";"],
|
||||
["keyword", "continue"], ["punctuation", ";"],
|
||||
["keyword", "else"], ["punctuation", ";"],
|
||||
["keyword", "for"], ["punctuation", ";"],
|
||||
["keyword", "foreign"], ["punctuation", ";"],
|
||||
["keyword", "if"], ["punctuation", ";"],
|
||||
["keyword", "import"], ["punctuation", ";"],
|
||||
["keyword", "in"], ["punctuation", ";"],
|
||||
["keyword", "is"], ["punctuation", ";"],
|
||||
["keyword", "return"], ["punctuation", ";"],
|
||||
["keyword", "static"], ["punctuation", ";"],
|
||||
["keyword", "super"], ["punctuation", ";"],
|
||||
["keyword", "this"], ["punctuation", ";"],
|
||||
["keyword", "var"], ["punctuation", ";"],
|
||||
["keyword", "while"], ["punctuation", ";"],
|
||||
|
||||
["null", "null"]
|
||||
]
|
|
@ -0,0 +1,25 @@
|
|||
0
|
||||
1234
|
||||
-5678
|
||||
3.14159
|
||||
1.0
|
||||
-12.34
|
||||
0.0314159e02
|
||||
0.0314159e+02
|
||||
314.159e-02
|
||||
0xcaffe2
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["number", "0"],
|
||||
["number", "1234"],
|
||||
["operator", "-"], ["number", "5678"],
|
||||
["number", "3.14159"],
|
||||
["number", "1.0"],
|
||||
["operator", "-"], ["number", "12.34"],
|
||||
["number", "0.0314159e02"],
|
||||
["number", "0.0314159e+02"],
|
||||
["number", "314.159e-02"],
|
||||
["number", "0xcaffe2"]
|
||||
]
|
|
@ -0,0 +1,55 @@
|
|||
! ~ -
|
||||
* / % + -
|
||||
.. ...
|
||||
<< >>
|
||||
< <= > >= == !=
|
||||
& ^ |
|
||||
=
|
||||
|
||||
&& ||
|
||||
? :
|
||||
|
||||
1..2 1...3
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["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", ":"],
|
||||
|
||||
["number", "1"],
|
||||
["operator", ".."],
|
||||
["number", "2"],
|
||||
["number", "1"],
|
||||
["operator", "..."],
|
||||
["number", "3"]
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
( ) [ ] { }
|
||||
, ; .
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["punctuation", "["],
|
||||
["punctuation", "]"],
|
||||
["punctuation", "{"],
|
||||
["punctuation", "}"],
|
||||
|
||||
["punctuation", ","],
|
||||
["punctuation", ";"],
|
||||
["punctuation", "."]
|
||||
]
|
|
@ -0,0 +1,60 @@
|
|||
""
|
||||
"\"\\"
|
||||
"foo
|
||||
bar"
|
||||
|
||||
""""""
|
||||
"""
|
||||
foo
|
||||
bar
|
||||
"""
|
||||
"""
|
||||
{
|
||||
"hello": "wren",
|
||||
"from" : "json"
|
||||
}
|
||||
"""
|
||||
|
||||
"foo %(bar)"
|
||||
"foo * %(1 + 2) ~= bar"
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["string-literal", [
|
||||
["string", "\"\""]
|
||||
]],
|
||||
["string-literal", [
|
||||
["string", "\"\\\"\\\\\""]
|
||||
]],
|
||||
["string-literal", [
|
||||
["string", "\"foo\r\nbar\""]
|
||||
]],
|
||||
|
||||
["triple-quoted-string", "\"\"\"\"\"\""],
|
||||
["triple-quoted-string", "\"\"\"\r\nfoo\r\nbar\r\n\"\"\""],
|
||||
["triple-quoted-string", "\"\"\"\r\n {\r\n \"hello\": \"wren\",\r\n \"from\" : \"json\"\r\n }\r\n\"\"\""],
|
||||
|
||||
["string-literal", [
|
||||
["string", "\"foo "],
|
||||
["interpolation", [
|
||||
["interpolation-punctuation", "%("],
|
||||
["expression", ["bar"]],
|
||||
["interpolation-punctuation", ")"]
|
||||
]],
|
||||
["string", "\""]
|
||||
]],
|
||||
["string-literal", [
|
||||
["string", "\"foo * "],
|
||||
["interpolation", [
|
||||
["interpolation-punctuation", "%("],
|
||||
["expression", [
|
||||
["number", "1"],
|
||||
["operator", "+"],
|
||||
["number", "2"]
|
||||
]],
|
||||
["interpolation-punctuation", ")"]
|
||||
]],
|
||||
["string", " ~= bar\""]
|
||||
]]
|
||||
]
|
Loading…
Reference in New Issue