-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4fbdd2f
commit 6a356d2
Showing
16 changed files
with
507 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] / | ||
} | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,9 @@ | ||
true | ||
false | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["boolean", "true"], | ||
["boolean", "false"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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*/"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", "}"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,7 @@ | ||
#!/usr/bin/env wren | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["hashbang", "#!/usr/bin/env wren"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] | ||
] |
Oops, something went wrong.