Repository navigation
Closed
Description
Wren Language
Wren is a small, fast, class-based concurrent scripting language
Think Smalltalk in a Lua-sized package with a dash of Erlang and wrapped up in a familiar, modern syntax.
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())Additional resources
- https://wren.io/
- https://github.com/wren-lang/wren
Possible Implementation
Butchered some available languages and came with something. But stills needs some testing 👍
// Prism.languages.wren
export default (function (Prism) {
var multilineComment = /\/\*(?:[^*/]|\*(?!\/)|\/(?!\*)|<self>)*\*\//.source;
for (var i = 0; i < 2; i++) {
// support 4 levels of nested comments
multilineComment = multilineComment.replace(/<self>/g, function () { return multilineComment; });
}
multilineComment = multilineComment.replace(/<self>/g, function () { return /[^\s\S]/.source; });
Prism.languages.wren = {
'hashbang': {
pattern: /^#!.*/,
greedy: true,
alias: 'comment'
},
'comment': [
{
pattern: RegExp(/(^|[^\\])/.source + multilineComment),
lookbehind: true,
greedy: true
},
{
pattern: /(^|[^\\:])\/\/.*/,
lookbehind: true,
greedy: true
}
],
'triple-quoted-string': {
pattern: /(?:[])?(""")[\s\S]*?\1/i,
greedy: true,
alias: 'string'
},
'string': {
pattern: /(?:[])?(")[\s\S]*?\1/i,
greedy: true
},
'class-name': {
pattern: /(\b(?:class|is|Num|System|Object|Sequence|List|Map|Bool|String|Range|Fn|Fiber)\s+|\bcatch\s+\()[\w.\\]+/i,
lookbehind: true,
inside: {
'punctuation': /[.\\]/
}
},
'keyword': /\b(?:if|else|while|for|return|in|is|as|null|break|continue|foreign|construct|static|var|class|this|super|#!|#)\b/,
'boolean': /\b(?:true|false)\b/,
'number': /\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,
'null': {
pattern: /\bnull\b/,
alias: 'keyword'
},
'function': /(?!\d)\w+(?=\s*(?:[({]))/,
'operator': [
/[-+*%^&|#]|\/\/?|<[<=]?|>[>=]?|[=~]=?/,
{
// Match ".." but don't break "..."
pattern: /(^|[^.])\.\.(?!\.)/,
lookbehind: true
}
],
'punctuation': /[\[\](){},;]|\.+|:+/
};
});Reacted by Aviv Beeri, Julian and Chris White
Activity
nailuj29 commentedon Apr 24, 2021
Wren is great!
joshgoebel commentedon Apr 24, 2021
@clsource Any chance you might be willing to work on a grammar for Highlight.js also? Wren is indeed cool, I'm vaguely familiar with it from TIC-80.
@RunDevelopment Do you mind post such questions if they are infrequent? :)
RunDevelopment commentedon Apr 24, 2021
@clsource Would you like to do a PR?
@joshgoebel I think it's ok. It's a little off-topic but you also contribute by responding to comments and sharing your experience, so I don't mind.
clsource commentedon Apr 25, 2021
Sure when a more polished and tested version is available I will do a PR 👍
maybe, for now I will focus on prism 👍
joshgoebel commentedon Apr 25, 2021
@clsource It seems
wren.iois already using Prism? Did anyone ask to see what grammar they are using? Or is that you?clsource commentedon Apr 25, 2021
The current syntax in wren.io is a modified lua and its not complete. Thats why I made a more tailored implementation
RunDevelopment commentedon Apr 26, 2021
@clsource Would it be alright with you if I make a PR based on your language definition?
nailuj29 commentedon Apr 26, 2021
@RunDevelopment I think they've updated it a bit, they've shared some screenshots in the wren discord
clsource commentedon Apr 26, 2021
The current version is this. But still needs a little more testing :)
RunDevelopment commentedon Apr 26, 2021
That looks better! Maybe a few point to improve:
triple-quoted-string: The(?:[])?can be removed. The backreference is also unnecessary since it can only match one string.attribute:greedyis false by default. The/^#!.*/pattern can never be matched because it is a subset of the above/^#.*/pattern.class-name: the/\b[A-Z](?:[_a-z]|\dx?)*\b/has an exponential worst case. Use/\b[A-Z][a-z\d_]*\b/instead (both patterns are equivalent).clsource commentedon Apr 26, 2021
Ok implemented your suggestions and added hashbangs 👍