Skip to content

Commit 6a356d2

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

16 files changed

+507
-1
lines changed

components.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

Lines changed: 4 additions & 0 deletions
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

Lines changed: 100 additions & 0 deletions
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

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-wren.html

Lines changed: 17 additions & 0 deletions
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>
Lines changed: 91 additions & 0 deletions
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+
]
Lines changed: 9 additions & 0 deletions
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+
]
Lines changed: 35 additions & 0 deletions
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+
]
Lines changed: 21 additions & 0 deletions
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+
]
Lines changed: 19 additions & 0 deletions
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+
]
Lines changed: 7 additions & 0 deletions
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+
]
Lines changed: 45 additions & 0 deletions
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+
]
Lines changed: 25 additions & 0 deletions
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+
]

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy