Skip to content

Commit 6a356d2

Browse files
authoredSep 15, 2021
Added support for Wren (#3063)
1 parent 4fbdd2f commit 6a356d2

16 files changed

+507
-1
lines changed
 

‎components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎components.json

+4
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,10 @@
14011401
},
14021402
"owner": "msollami"
14031403
},
1404+
"wren": {
1405+
"title": "Wren",
1406+
"owner": "clsource"
1407+
},
14041408
"xeora": {
14051409
"title": "Xeora",
14061410
"require": "markup",

‎components/prism-wren.js

+100
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
// https://wren.io/
2+
3+
Prism.languages.wren = {
4+
// Multiline comments in Wren can have nested multiline comments
5+
// Comments: // and /* */
6+
'comment': [
7+
{
8+
// support 3 levels of nesting
9+
// regex: \/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\/
10+
pattern: /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|\/\*(?:[^*/]|\*(?!\/)|\/(?!\*))*\*\/)*\*\/)*\*\//,
11+
greedy: true
12+
},
13+
{
14+
pattern: /(^|[^\\:])\/\/.*/,
15+
lookbehind: true,
16+
greedy: true
17+
}
18+
],
19+
20+
// Triple quoted strings are multiline but cannot have interpolation (raw strings)
21+
// Based on prism-python.js
22+
'triple-quoted-string': {
23+
pattern: /"""[\s\S]*?"""/,
24+
greedy: true,
25+
alias: 'string'
26+
},
27+
28+
// see below
29+
'string-literal': null,
30+
31+
// #!/usr/bin/env wren on the first line
32+
'hashbang': {
33+
pattern: /^#!\/.+/,
34+
greedy: true,
35+
alias: 'comment'
36+
},
37+
38+
// Attributes are special keywords to add meta data to classes
39+
'attribute': {
40+
// #! attributes are stored in class properties
41+
// #!myvar = true
42+
// #attributes are not stored and dismissed at compilation
43+
pattern: /#!?[ \t\u3000]*\w+/,
44+
alias: 'keyword'
45+
},
46+
'class-name': [
47+
{
48+
// class definition
49+
// class Meta {}
50+
pattern: /(\bclass\s+)\w+/,
51+
lookbehind: true
52+
},
53+
// A class must always start with an uppercase.
54+
// File.read
55+
/\b[A-Z][a-z\d_]*\b/,
56+
],
57+
58+
// A constant can be a variable, class, property or method. Just named in all uppercase letters
59+
'constant': /\b[A-Z][A-Z\d_]*\b/,
60+
61+
'null': {
62+
pattern: /\bnull\b/,
63+
alias: 'keyword'
64+
},
65+
'keyword': /\b(?:as|break|class|construct|continue|else|for|foreign|if|import|in|is|return|static|super|this|var|while)\b/,
66+
'boolean': /\b(?:true|false)\b/,
67+
'number': /\b(?:0x[\da-f]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?)\b/i,
68+
69+
// Functions can be Class.method()
70+
'function': /\b[a-z_]\w*(?=\s*[({])/i,
71+
72+
'operator': /<<|>>|[=!<>]=?|&&|\|\||[-+*/%~^&|?:]|\.{2,3}/,
73+
'punctuation': /[\[\](){}.,;]/,
74+
};
75+
76+
Prism.languages.wren['string-literal'] = {
77+
// A single quote string is multiline and can have interpolation (similar to JS backticks ``)
78+
pattern: /(^|[^\\"])"(?:[^\\"%]|\\[\s\S]|%(?!\()|%\((?:[^()]|\((?:[^()]|\([^)]*\))*\))*\))*"/,
79+
lookbehind: true,
80+
greedy: true,
81+
inside: {
82+
'interpolation': {
83+
// "%(interpolation)"
84+
pattern: /((?:^|[^\\])(?:\\{2})*)%\((?:[^()]|\((?:[^()]|\([^)]*\))*\))*\)/,
85+
lookbehind: true,
86+
inside: {
87+
'expression': {
88+
pattern: /^(%\()[\s\S]+(?=\)$)/,
89+
lookbehind: true,
90+
inside: Prism.languages.wren
91+
},
92+
'interpolation-punctuation': {
93+
pattern: /^%\(|\)$/,
94+
alias: 'punctuation'
95+
},
96+
}
97+
},
98+
'string': /[\s\S]+/
99+
}
100+
};

‎components/prism-wren.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎examples/prism-wren.html

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<h2>Full example</h2>
2+
<pre><code>// Source: https://wren.io/
3+
4+
System.print("Hello, world!")
5+
6+
class Wren {
7+
flyTo(city) {
8+
System.print("Flying to %(city)")
9+
}
10+
}
11+
12+
var adjectives = Fiber.new {
13+
["small", "clean", "fast"].each {|word| Fiber.yield(word) }
14+
}
15+
16+
while (!adjectives.isDone) System.print(adjectives.call())
17+
</code></pre>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
#hidden = true
2+
class Example {}
3+
4+
#key
5+
#key = value
6+
#group(
7+
multiple,
8+
lines = true,
9+
lines = 0
10+
)
11+
class Example {
12+
#test(skip = true, iterations = 32)
13+
doStuff() {}
14+
}
15+
16+
#doc = "not runtime data"
17+
#!runtimeAccess = true
18+
#!maxIterations = 16
19+
20+
----------------------------------------------------
21+
22+
[
23+
["attribute", "#hidden"],
24+
["operator", "="],
25+
["boolean", "true"],
26+
27+
["keyword", "class"],
28+
["class-name", "Example"],
29+
["punctuation", "{"],
30+
["punctuation", "}"],
31+
32+
["attribute", "#key"],
33+
34+
["attribute", "#key"],
35+
["operator", "="],
36+
" value\r\n",
37+
38+
["attribute", "#group"],
39+
["punctuation", "("],
40+
41+
"\r\n multiple",
42+
["punctuation", ","],
43+
44+
"\r\n lines ",
45+
["operator", "="],
46+
["boolean", "true"],
47+
["punctuation", ","],
48+
49+
"\r\n lines ",
50+
["operator", "="],
51+
["number", "0"],
52+
53+
["punctuation", ")"],
54+
55+
["keyword", "class"],
56+
["class-name", "Example"],
57+
["punctuation", "{"],
58+
59+
["attribute", "#test"],
60+
["punctuation", "("],
61+
"skip ",
62+
["operator", "="],
63+
["boolean", "true"],
64+
["punctuation", ","],
65+
" iterations ",
66+
["operator", "="],
67+
["number", "32"],
68+
["punctuation", ")"],
69+
70+
["function", "doStuff"],
71+
["punctuation", "("],
72+
["punctuation", ")"],
73+
["punctuation", "{"],
74+
["punctuation", "}"],
75+
76+
["punctuation", "}"],
77+
78+
["attribute", "#doc"],
79+
["operator", "="],
80+
["string-literal", [
81+
["string", "\"not runtime data\""]
82+
]],
83+
84+
["attribute", "#!runtimeAccess"],
85+
["operator", "="],
86+
["boolean", "true"],
87+
88+
["attribute", "#!maxIterations"],
89+
["operator", "="],
90+
["number", "16"]
91+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
true
2+
false
3+
4+
----------------------------------------------------
5+
6+
[
7+
["boolean", "true"],
8+
["boolean", "false"]
9+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Foo.bar()
2+
3+
import "beverages" for Coffee, Tea
4+
5+
class Foo {}
6+
class foo {}
7+
8+
----------------------------------------------------
9+
10+
[
11+
["class-name", "Foo"],
12+
["punctuation", "."],
13+
["function", "bar"],
14+
["punctuation", "("],
15+
["punctuation", ")"],
16+
17+
["keyword", "import"],
18+
["string-literal", [
19+
["string", "\"beverages\""]
20+
]],
21+
["keyword", "for"],
22+
["class-name", "Coffee"],
23+
["punctuation", ","],
24+
["class-name", "Tea"],
25+
26+
["keyword", "class"],
27+
["class-name", "Foo"],
28+
["punctuation", "{"],
29+
["punctuation", "}"],
30+
31+
["keyword", "class"],
32+
["class-name", "foo"],
33+
["punctuation", "{"],
34+
["punctuation", "}"]
35+
]
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// comment
2+
3+
/**/
4+
/* comment */
5+
6+
/*
7+
/*
8+
nested comment
9+
*/
10+
*/
11+
12+
----------------------------------------------------
13+
14+
[
15+
["comment", "// comment"],
16+
17+
["comment", "/**/"],
18+
["comment", "/* comment */"],
19+
20+
["comment", "/*\r\n/*\r\nnested comment\r\n*/\r\n*/"]
21+
]
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
foo()
2+
3+
foo {|x| x * 2}
4+
5+
----------------------------------------------------
6+
7+
[
8+
["function", "foo"], ["punctuation", "("], ["punctuation", ")"],
9+
10+
["function", "foo"],
11+
["punctuation", "{"],
12+
["operator", "|"],
13+
"x",
14+
["operator", "|"],
15+
" x ",
16+
["operator", "*"],
17+
["number", "2"],
18+
["punctuation", "}"]
19+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env wren
2+
3+
----------------------------------------------------
4+
5+
[
6+
["hashbang", "#!/usr/bin/env wren"]
7+
]
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
as;
2+
break;
3+
class;
4+
construct;
5+
continue;
6+
else;
7+
for;
8+
foreign;
9+
if;
10+
import;
11+
in;
12+
is;
13+
return;
14+
static;
15+
super;
16+
this;
17+
var;
18+
while;
19+
20+
null
21+
22+
----------------------------------------------------
23+
24+
[
25+
["keyword", "as"], ["punctuation", ";"],
26+
["keyword", "break"], ["punctuation", ";"],
27+
["keyword", "class"], ["punctuation", ";"],
28+
["keyword", "construct"], ["punctuation", ";"],
29+
["keyword", "continue"], ["punctuation", ";"],
30+
["keyword", "else"], ["punctuation", ";"],
31+
["keyword", "for"], ["punctuation", ";"],
32+
["keyword", "foreign"], ["punctuation", ";"],
33+
["keyword", "if"], ["punctuation", ";"],
34+
["keyword", "import"], ["punctuation", ";"],
35+
["keyword", "in"], ["punctuation", ";"],
36+
["keyword", "is"], ["punctuation", ";"],
37+
["keyword", "return"], ["punctuation", ";"],
38+
["keyword", "static"], ["punctuation", ";"],
39+
["keyword", "super"], ["punctuation", ";"],
40+
["keyword", "this"], ["punctuation", ";"],
41+
["keyword", "var"], ["punctuation", ";"],
42+
["keyword", "while"], ["punctuation", ";"],
43+
44+
["null", "null"]
45+
]
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
0
2+
1234
3+
-5678
4+
3.14159
5+
1.0
6+
-12.34
7+
0.0314159e02
8+
0.0314159e+02
9+
314.159e-02
10+
0xcaffe2
11+
12+
----------------------------------------------------
13+
14+
[
15+
["number", "0"],
16+
["number", "1234"],
17+
["operator", "-"], ["number", "5678"],
18+
["number", "3.14159"],
19+
["number", "1.0"],
20+
["operator", "-"], ["number", "12.34"],
21+
["number", "0.0314159e02"],
22+
["number", "0.0314159e+02"],
23+
["number", "314.159e-02"],
24+
["number", "0xcaffe2"]
25+
]
+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
! ~ -
2+
* / % + -
3+
.. ...
4+
<< >>
5+
< <= > >= == !=
6+
& ^ |
7+
=
8+
9+
&& ||
10+
? :
11+
12+
1..2 1...3
13+
14+
----------------------------------------------------
15+
16+
[
17+
["operator", "!"],
18+
["operator", "~"],
19+
["operator", "-"],
20+
21+
["operator", "*"],
22+
["operator", "/"],
23+
["operator", "%"],
24+
["operator", "+"],
25+
["operator", "-"],
26+
27+
["operator", ".."],
28+
["operator", "..."],
29+
30+
["operator", "<<"],
31+
["operator", ">>"],
32+
33+
["operator", "<"],
34+
["operator", "<="],
35+
["operator", ">"],
36+
["operator", ">="],
37+
["operator", "=="],
38+
["operator", "!="],
39+
40+
["operator", "&"],
41+
["operator", "^"],
42+
["operator", "|"],
43+
44+
["operator", "="],
45+
46+
["operator", "&&"], ["operator", "||"],
47+
["operator", "?"], ["operator", ":"],
48+
49+
["number", "1"],
50+
["operator", ".."],
51+
["number", "2"],
52+
["number", "1"],
53+
["operator", "..."],
54+
["number", "3"]
55+
]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
( ) [ ] { }
2+
, ; .
3+
4+
----------------------------------------------------
5+
6+
[
7+
["punctuation", "("],
8+
["punctuation", ")"],
9+
["punctuation", "["],
10+
["punctuation", "]"],
11+
["punctuation", "{"],
12+
["punctuation", "}"],
13+
14+
["punctuation", ","],
15+
["punctuation", ";"],
16+
["punctuation", "."]
17+
]
+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
""
2+
"\"\\"
3+
"foo
4+
bar"
5+
6+
""""""
7+
"""
8+
foo
9+
bar
10+
"""
11+
"""
12+
{
13+
"hello": "wren",
14+
"from" : "json"
15+
}
16+
"""
17+
18+
"foo %(bar)"
19+
"foo * %(1 + 2) ~= bar"
20+
21+
----------------------------------------------------
22+
23+
[
24+
["string-literal", [
25+
["string", "\"\""]
26+
]],
27+
["string-literal", [
28+
["string", "\"\\\"\\\\\""]
29+
]],
30+
["string-literal", [
31+
["string", "\"foo\r\nbar\""]
32+
]],
33+
34+
["triple-quoted-string", "\"\"\"\"\"\""],
35+
["triple-quoted-string", "\"\"\"\r\nfoo\r\nbar\r\n\"\"\""],
36+
["triple-quoted-string", "\"\"\"\r\n {\r\n \"hello\": \"wren\",\r\n \"from\" : \"json\"\r\n }\r\n\"\"\""],
37+
38+
["string-literal", [
39+
["string", "\"foo "],
40+
["interpolation", [
41+
["interpolation-punctuation", "%("],
42+
["expression", ["bar"]],
43+
["interpolation-punctuation", ")"]
44+
]],
45+
["string", "\""]
46+
]],
47+
["string-literal", [
48+
["string", "\"foo * "],
49+
["interpolation", [
50+
["interpolation-punctuation", "%("],
51+
["expression", [
52+
["number", "1"],
53+
["operator", "+"],
54+
["number", "2"]
55+
]],
56+
["interpolation-punctuation", ")"]
57+
]],
58+
["string", " ~= bar\""]
59+
]]
60+
]

0 commit comments

Comments
 (0)
Please sign in to comment.