Added support for ChaiScript (#2706)
This commit is contained in:
parent
04ef309c30
commit
3f7d74533f
File diff suppressed because one or more lines are too long
|
@ -238,6 +238,11 @@
|
|||
"require": "c",
|
||||
"owner": "zeitgeist87"
|
||||
},
|
||||
"chaiscript": {
|
||||
"title": "ChaiScript",
|
||||
"require": ["clike", "cpp"],
|
||||
"owner": "RunDevelopment"
|
||||
},
|
||||
"cil": {
|
||||
"title": "CIL",
|
||||
"owner": "sbrl"
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
Prism.languages.chaiscript = Prism.languages.extend('clike', {
|
||||
'string': {
|
||||
pattern: /(^|[^\\])'(?:[^'\\]|\\[\s\S])*'/,
|
||||
lookbehind: true,
|
||||
greedy: true
|
||||
},
|
||||
'class-name': [
|
||||
{
|
||||
// e.g. class Rectangle { ... }
|
||||
pattern: /(\bclass\s+)\w+/,
|
||||
lookbehind: true
|
||||
},
|
||||
{
|
||||
// e.g. attr Rectangle::height, def Rectangle::area() { ... }
|
||||
pattern: /(\b(?:attr|def)\s+)\w+(?=\s*::)/,
|
||||
lookbehind: true
|
||||
}
|
||||
],
|
||||
'keyword': /\b(?:attr|auto|break|case|catch|class|continue|def|default|else|finally|for|fun|global|if|return|switch|this|try|var|while)\b/,
|
||||
'number': [
|
||||
Prism.languages.cpp.number,
|
||||
/\b(?:Infinity|NaN)\b/
|
||||
],
|
||||
'operator': />>=?|<<=?|\|\||&&|:[:=]?|--|\+\+|[=!<>+\-*/%|&^]=?|[?~]|`[^`\r\n]{1,4}`/,
|
||||
});
|
||||
|
||||
Prism.languages.insertBefore('chaiscript', 'operator', {
|
||||
'parameter-type': {
|
||||
// e.g. def foo(int x, Vector y) {...}
|
||||
pattern: /([,(]\s*)\w+(?=\s+\w)/,
|
||||
lookbehind: true,
|
||||
alias: 'class-name'
|
||||
},
|
||||
});
|
||||
|
||||
Prism.languages.insertBefore('chaiscript', 'string', {
|
||||
'string-interpolation': {
|
||||
pattern: /(^|[^\\])"(?:[^"$\\]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})*"/,
|
||||
lookbehind: true,
|
||||
greedy: true,
|
||||
inside: {
|
||||
'interpolation': {
|
||||
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}/,
|
||||
lookbehind: true,
|
||||
inside: {
|
||||
'interpolation-expression': {
|
||||
pattern: /(^\$\{)[\s\S]+(?=\}$)/,
|
||||
lookbehind: true,
|
||||
inside: Prism.languages.chaiscript
|
||||
},
|
||||
'interpolation-punctuation': {
|
||||
pattern: /^\$\{|\}$/,
|
||||
alias: 'punctuation'
|
||||
}
|
||||
}
|
||||
},
|
||||
'string': /[\s\S]+/
|
||||
}
|
||||
},
|
||||
});
|
|
@ -0,0 +1 @@
|
|||
Prism.languages.chaiscript=Prism.languages.extend("clike",{string:{pattern:/(^|[^\\])'(?:[^'\\]|\\[\s\S])*'/,lookbehind:!0,greedy:!0},"class-name":[{pattern:/(\bclass\s+)\w+/,lookbehind:!0},{pattern:/(\b(?:attr|def)\s+)\w+(?=\s*::)/,lookbehind:!0}],keyword:/\b(?:attr|auto|break|case|catch|class|continue|def|default|else|finally|for|fun|global|if|return|switch|this|try|var|while)\b/,number:[Prism.languages.cpp.number,/\b(?:Infinity|NaN)\b/],operator:/>>=?|<<=?|\|\||&&|:[:=]?|--|\+\+|[=!<>+\-*/%|&^]=?|[?~]|`[^`\r\n]{1,4}`/}),Prism.languages.insertBefore("chaiscript","operator",{"parameter-type":{pattern:/([,(]\s*)\w+(?=\s+\w)/,lookbehind:!0,alias:"class-name"}}),Prism.languages.insertBefore("chaiscript","string",{"string-interpolation":{pattern:/(^|[^\\])"(?:[^"$\\]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})*"/,lookbehind:!0,greedy:!0,inside:{interpolation:{pattern:/((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}/,lookbehind:!0,inside:{"interpolation-expression":{pattern:/(^\$\{)[\s\S]+(?=\}$)/,lookbehind:!0,inside:Prism.languages.chaiscript},"interpolation-punctuation":{pattern:/^\$\{|\}$/,alias:"punctuation"}}},string:/[\s\S]+/}}});
|
|
@ -0,0 +1,56 @@
|
|||
<h2>Full example</h2>
|
||||
<pre><code>// http://chaiscript.com/examples.html#ChaiScript_Language_Examples
|
||||
// Source: https://gist.github.com/lefticus/cf058f2927fef68d58e0#file-chaiscript_overview-chai
|
||||
|
||||
// ChaiScript supports the normal kind of control blocks you've come to expect from
|
||||
// C++ and JavaScript
|
||||
|
||||
|
||||
if (5 > 2) {
|
||||
print("Yup, 5 > 2");
|
||||
} else if (2 > 5) {
|
||||
// never gonna happen
|
||||
} else {
|
||||
// really not going to happen
|
||||
}
|
||||
|
||||
var x = true;
|
||||
|
||||
while (x)
|
||||
{
|
||||
print("x was true")
|
||||
x = false;
|
||||
}
|
||||
|
||||
for (var i = 1; i < 10; ++i)
|
||||
{
|
||||
print(i); // prints 1 through 9
|
||||
}
|
||||
|
||||
|
||||
// function definition
|
||||
|
||||
def myFunc(x) {
|
||||
print(x);
|
||||
}
|
||||
|
||||
// function definition with function guards
|
||||
def myFunc(x) : x > 2 && x < 5 {
|
||||
print(to_string(x) + " is between 2 and 5")
|
||||
}
|
||||
|
||||
def myFunc(x) : x >= 5 {
|
||||
print(t_string(x) + " is greater than or equal to 5")
|
||||
}
|
||||
|
||||
myFunc(3)
|
||||
|
||||
// ChaiScript also supports in string evaluation, which C++ does not
|
||||
|
||||
print("${3 + 5} is 8");
|
||||
|
||||
// And dynamic code evaluation
|
||||
|
||||
var value = eval("4 + 2 + 12");
|
||||
|
||||
// value is equal to 18</code></pre>
|
|
@ -25,6 +25,10 @@
|
|||
"c": "clike",
|
||||
"csharp": "clike",
|
||||
"cpp": "c",
|
||||
"chaiscript": [
|
||||
"clike",
|
||||
"cpp"
|
||||
],
|
||||
"coffeescript": "javascript",
|
||||
"crystal": "ruby",
|
||||
"css-extras": "css",
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,9 @@
|
|||
true
|
||||
false
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["boolean", "true"],
|
||||
["boolean", "false"]
|
||||
]
|
|
@ -0,0 +1,16 @@
|
|||
// comment
|
||||
/*
|
||||
comment
|
||||
*/
|
||||
|
||||
/*
|
||||
comment
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["comment", "// comment"],
|
||||
["comment", "/*\r\n comment\r\n*/"],
|
||||
|
||||
["comment", "/*\r\n comment"]
|
||||
]
|
|
@ -0,0 +1,190 @@
|
|||
attr Rectangle::height
|
||||
attr Rectangle::width
|
||||
def Rectangle::Rectangle() { this.height = 10; this.width = 20 }
|
||||
def Rectangle::area() { this.height * this.width }
|
||||
var rect = Rectangle()
|
||||
rect.height = 30
|
||||
print(rect.area())
|
||||
|
||||
class Rectangle {
|
||||
attr height
|
||||
attr width
|
||||
def Rectangle() { this.height = 10; this.width = 20 }
|
||||
def area() { this.height * this.width }
|
||||
}
|
||||
var rect = Rectangle()
|
||||
rect.height = 30
|
||||
print(rect.area())
|
||||
|
||||
def update(dt) {
|
||||
x = x + 20.0f * dt
|
||||
}
|
||||
|
||||
def foo(int x, Vector y) {}
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["keyword", "attr"],
|
||||
["class-name", "Rectangle"],
|
||||
["operator", "::"],
|
||||
"height\r\n",
|
||||
|
||||
["keyword", "attr"],
|
||||
["class-name", "Rectangle"],
|
||||
["operator", "::"],
|
||||
"width\r\n",
|
||||
|
||||
["keyword", "def"],
|
||||
["class-name", "Rectangle"],
|
||||
["operator", "::"],
|
||||
["function", "Rectangle"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["punctuation", "{"],
|
||||
["keyword", "this"],
|
||||
["punctuation", "."],
|
||||
"height ",
|
||||
["operator", "="],
|
||||
["number", "10"],
|
||||
["punctuation", ";"],
|
||||
["keyword", "this"],
|
||||
["punctuation", "."],
|
||||
"width ",
|
||||
["operator", "="],
|
||||
["number", "20"],
|
||||
["punctuation", "}"],
|
||||
|
||||
["keyword", "def"],
|
||||
["class-name", "Rectangle"],
|
||||
["operator", "::"],
|
||||
["function", "area"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["punctuation", "{"],
|
||||
["keyword", "this"],
|
||||
["punctuation", "."],
|
||||
"height ",
|
||||
["operator", "*"],
|
||||
["keyword", "this"],
|
||||
["punctuation", "."],
|
||||
"width ",
|
||||
["punctuation", "}"],
|
||||
|
||||
["keyword", "var"],
|
||||
" rect ",
|
||||
["operator", "="],
|
||||
["function", "Rectangle"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
|
||||
"\r\nrect",
|
||||
["punctuation", "."],
|
||||
"height ",
|
||||
["operator", "="],
|
||||
["number", "30"],
|
||||
|
||||
["function", "print"],
|
||||
["punctuation", "("],
|
||||
"rect",
|
||||
["punctuation", "."],
|
||||
["function", "area"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["punctuation", ")"],
|
||||
|
||||
["keyword", "class"],
|
||||
["class-name", "Rectangle"],
|
||||
["punctuation", "{"],
|
||||
|
||||
["keyword", "attr"],
|
||||
" height\r\n ",
|
||||
|
||||
["keyword", "attr"],
|
||||
" width\r\n ",
|
||||
|
||||
["keyword", "def"],
|
||||
["function", "Rectangle"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["punctuation", "{"],
|
||||
["keyword", "this"],
|
||||
["punctuation", "."],
|
||||
"height ",
|
||||
["operator", "="],
|
||||
["number", "10"],
|
||||
["punctuation", ";"],
|
||||
["keyword", "this"],
|
||||
["punctuation", "."],
|
||||
"width ",
|
||||
["operator", "="],
|
||||
["number", "20"],
|
||||
["punctuation", "}"],
|
||||
|
||||
["keyword", "def"],
|
||||
["function", "area"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["punctuation", "{"],
|
||||
["keyword", "this"],
|
||||
["punctuation", "."],
|
||||
"height ",
|
||||
["operator", "*"],
|
||||
["keyword", "this"],
|
||||
["punctuation", "."],
|
||||
"width ",
|
||||
["punctuation", "}"],
|
||||
|
||||
["punctuation", "}"],
|
||||
|
||||
["keyword", "var"],
|
||||
" rect ",
|
||||
["operator", "="],
|
||||
["function", "Rectangle"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
|
||||
"\r\nrect",
|
||||
["punctuation", "."],
|
||||
"height ",
|
||||
["operator", "="],
|
||||
["number", "30"],
|
||||
|
||||
["function", "print"],
|
||||
["punctuation", "("],
|
||||
"rect",
|
||||
["punctuation", "."],
|
||||
["function", "area"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["punctuation", ")"],
|
||||
|
||||
["keyword", "def"],
|
||||
["function", "update"],
|
||||
["punctuation", "("],
|
||||
"dt",
|
||||
["punctuation", ")"],
|
||||
["punctuation", "{"],
|
||||
|
||||
"\r\n x ",
|
||||
["operator", "="],
|
||||
" x ",
|
||||
["operator", "+"],
|
||||
["number", "20.0f"],
|
||||
["operator", "*"],
|
||||
" dt\r\n",
|
||||
|
||||
["punctuation", "}"],
|
||||
|
||||
["keyword", "def"],
|
||||
["function", "foo"],
|
||||
["punctuation", "("],
|
||||
["parameter-type", "int"],
|
||||
" x",
|
||||
["punctuation", ","],
|
||||
["parameter-type", "Vector"],
|
||||
" y",
|
||||
["punctuation", ")"],
|
||||
["punctuation", "{"],
|
||||
["punctuation", "}"]
|
||||
]
|
|
@ -0,0 +1,47 @@
|
|||
attr;
|
||||
auto;
|
||||
break;
|
||||
case;
|
||||
catch;
|
||||
class;
|
||||
continue;
|
||||
def;
|
||||
default;
|
||||
else;
|
||||
finally;
|
||||
for;
|
||||
fun;
|
||||
global;
|
||||
if;
|
||||
return;
|
||||
switch;
|
||||
this;
|
||||
try;
|
||||
var;
|
||||
while;
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["keyword", "attr"], ["punctuation", ";"],
|
||||
["keyword", "auto"], ["punctuation", ";"],
|
||||
["keyword", "break"], ["punctuation", ";"],
|
||||
["keyword", "case"], ["punctuation", ";"],
|
||||
["keyword", "catch"], ["punctuation", ";"],
|
||||
["keyword", "class"], ["punctuation", ";"],
|
||||
["keyword", "continue"], ["punctuation", ";"],
|
||||
["keyword", "def"], ["punctuation", ";"],
|
||||
["keyword", "default"], ["punctuation", ";"],
|
||||
["keyword", "else"], ["punctuation", ";"],
|
||||
["keyword", "finally"], ["punctuation", ";"],
|
||||
["keyword", "for"], ["punctuation", ";"],
|
||||
["keyword", "fun"], ["punctuation", ";"],
|
||||
["keyword", "global"], ["punctuation", ";"],
|
||||
["keyword", "if"], ["punctuation", ";"],
|
||||
["keyword", "return"], ["punctuation", ";"],
|
||||
["keyword", "switch"], ["punctuation", ";"],
|
||||
["keyword", "this"], ["punctuation", ";"],
|
||||
["keyword", "try"], ["punctuation", ";"],
|
||||
["keyword", "var"], ["punctuation", ";"],
|
||||
["keyword", "while"], ["punctuation", ";"]
|
||||
]
|
|
@ -0,0 +1,19 @@
|
|||
Infinity
|
||||
NaN
|
||||
|
||||
1e-5
|
||||
35.5E+8
|
||||
0.01e19
|
||||
1.2f
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["number", "Infinity"],
|
||||
["number", "NaN"],
|
||||
|
||||
["number", "1e-5"],
|
||||
["number", "35.5E+8"],
|
||||
["number", "0.01e19"],
|
||||
["number", "1.2f"]
|
||||
]
|
|
@ -0,0 +1,74 @@
|
|||
?
|
||||
|| &&
|
||||
| ^ &
|
||||
== !=
|
||||
< <= > >=
|
||||
<< >>
|
||||
+ -
|
||||
* / %
|
||||
++ -- - + ! ~
|
||||
|
||||
= :=
|
||||
+= -= *= /= %= <<= >>= &= ^= |=
|
||||
: ::
|
||||
|
||||
// operator references
|
||||
`+`
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["operator", "?"],
|
||||
|
||||
["operator", "||"],
|
||||
["operator", "&&"],
|
||||
|
||||
["operator", "|"],
|
||||
["operator", "^"],
|
||||
["operator", "&"],
|
||||
|
||||
["operator", "=="],
|
||||
["operator", "!="],
|
||||
|
||||
["operator", "<"],
|
||||
["operator", "<="],
|
||||
["operator", ">"],
|
||||
["operator", ">="],
|
||||
|
||||
["operator", "<<"],
|
||||
["operator", ">>"],
|
||||
|
||||
["operator", "+"],
|
||||
["operator", "-"],
|
||||
|
||||
["operator", "*"],
|
||||
["operator", "/"],
|
||||
["operator", "%"],
|
||||
|
||||
["operator", "++"],
|
||||
["operator", "--"],
|
||||
["operator", "-"],
|
||||
["operator", "+"],
|
||||
["operator", "!"],
|
||||
["operator", "~"],
|
||||
|
||||
["operator", "="],
|
||||
["operator", ":="],
|
||||
|
||||
["operator", "+="],
|
||||
["operator", "-="],
|
||||
["operator", "*="],
|
||||
["operator", "/="],
|
||||
["operator", "%="],
|
||||
["operator", "<<="],
|
||||
["operator", ">>="],
|
||||
["operator", "&="],
|
||||
["operator", "^="],
|
||||
["operator", "|="],
|
||||
|
||||
["operator", ":"],
|
||||
["operator", "::"],
|
||||
|
||||
["comment", "// operator references"],
|
||||
["operator", "`+`"]
|
||||
]
|
|
@ -0,0 +1,17 @@
|
|||
( ) [ ] { }
|
||||
; , .
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"],
|
||||
["punctuation", "["],
|
||||
["punctuation", "]"],
|
||||
["punctuation", "{"],
|
||||
["punctuation", "}"],
|
||||
|
||||
["punctuation", ";"],
|
||||
["punctuation", ","],
|
||||
["punctuation", "."]
|
||||
]
|
|
@ -0,0 +1,71 @@
|
|||
"string"
|
||||
"lhs: ${lhs}, rhs: ${rhs}"
|
||||
"${3 + 5} is 8"
|
||||
"method_missing(${i}, ${name}), ${v.size()} params"
|
||||
|
||||
'f'
|
||||
|
||||
----------------------------------------------------
|
||||
|
||||
[
|
||||
["string-interpolation", [
|
||||
["string", "\"string\""]
|
||||
]],
|
||||
["string-interpolation", [
|
||||
["string", "\"lhs: "],
|
||||
["interpolation", [
|
||||
["interpolation-punctuation", "${"],
|
||||
["interpolation-expression", ["lhs"]],
|
||||
["interpolation-punctuation", "}"]
|
||||
]],
|
||||
["string", ", rhs: "],
|
||||
["interpolation", [
|
||||
["interpolation-punctuation", "${"],
|
||||
["interpolation-expression", ["rhs"]],
|
||||
["interpolation-punctuation", "}"]
|
||||
]],
|
||||
["string", "\""]
|
||||
]],
|
||||
["string-interpolation", [
|
||||
["string", "\""],
|
||||
["interpolation", [
|
||||
["interpolation-punctuation", "${"],
|
||||
["interpolation-expression", [
|
||||
["number", "3"],
|
||||
["operator", "+"],
|
||||
["number", "5"]
|
||||
]],
|
||||
["interpolation-punctuation", "}"]
|
||||
]],
|
||||
["string", " is 8\""]
|
||||
]],
|
||||
["string-interpolation", [
|
||||
["string", "\"method_missing("],
|
||||
["interpolation", [
|
||||
["interpolation-punctuation", "${"],
|
||||
["interpolation-expression", ["i"]],
|
||||
["interpolation-punctuation", "}"]
|
||||
]],
|
||||
["string", ", "],
|
||||
["interpolation", [
|
||||
["interpolation-punctuation", "${"],
|
||||
["interpolation-expression", ["name"]],
|
||||
["interpolation-punctuation", "}"]
|
||||
]],
|
||||
["string", "), "],
|
||||
["interpolation", [
|
||||
["interpolation-punctuation", "${"],
|
||||
["interpolation-expression", [
|
||||
"v",
|
||||
["punctuation", "."],
|
||||
["function", "size"],
|
||||
["punctuation", "("],
|
||||
["punctuation", ")"]
|
||||
]],
|
||||
["interpolation-punctuation", "}"]
|
||||
]],
|
||||
["string", " params\""]
|
||||
]],
|
||||
|
||||
["string", "'f'"]
|
||||
]
|
Loading…
Reference in New Issue