Skip to content

Commit

Permalink
Added support for Wren (#3063)
Browse files Browse the repository at this point in the history
  • Loading branch information
RunDevelopment authored Sep 15, 2021
1 parent 4fbdd2f commit 6a356d2
Show file tree
Hide file tree
Showing 16 changed files with 507 additions and 1 deletion.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -1401,6 +1401,10 @@
},
"owner": "msollami"
},
"wren": {
"title": "Wren",
"owner": "clsource"
},
"xeora": {
"title": "Xeora",
"require": "markup",
Expand Down
100 changes: 100 additions & 0 deletions components/prism-wren.js
Original file line number Diff line number Diff line change
@@ -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]+/
}
};
1 change: 1 addition & 0 deletions components/prism-wren.min.js

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

17 changes: 17 additions & 0 deletions examples/prism-wren.html
Original file line number Diff line number Diff line change
@@ -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>
91 changes: 91 additions & 0 deletions tests/languages/wren/attribute_feature.test
Original file line number Diff line number Diff line change
@@ -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"]
]
9 changes: 9 additions & 0 deletions tests/languages/wren/boolean_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
true
false

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

[
["boolean", "true"],
["boolean", "false"]
]
35 changes: 35 additions & 0 deletions tests/languages/wren/class-name_feature.test
Original file line number Diff line number Diff line change
@@ -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", "}"]
]
21 changes: 21 additions & 0 deletions tests/languages/wren/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// comment

/**/
/* comment */

/*
/*
nested comment
*/
*/

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

[
["comment", "// comment"],

["comment", "/**/"],
["comment", "/* comment */"],

["comment", "/*\r\n/*\r\nnested comment\r\n*/\r\n*/"]
]
19 changes: 19 additions & 0 deletions tests/languages/wren/function_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
foo()

foo {|x| x * 2}

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

[
["function", "foo"], ["punctuation", "("], ["punctuation", ")"],

["function", "foo"],
["punctuation", "{"],
["operator", "|"],
"x",
["operator", "|"],
" x ",
["operator", "*"],
["number", "2"],
["punctuation", "}"]
]
7 changes: 7 additions & 0 deletions tests/languages/wren/hashbang_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env wren

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

[
["hashbang", "#!/usr/bin/env wren"]
]
45 changes: 45 additions & 0 deletions tests/languages/wren/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -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"]
]
25 changes: 25 additions & 0 deletions tests/languages/wren/number_feature.test
Original file line number Diff line number Diff line change
@@ -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"]
]
Loading

0 comments on commit 6a356d2

Please sign in to comment.