Skip to content

Commit 3f7d745

Browse files
Added support for ChaiScript (#2706)
1 parent 04ef309 commit 3f7d745

15 files changed

+571
-2
lines changed

Diff for: components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: components.json

+5
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@
238238
"require": "c",
239239
"owner": "zeitgeist87"
240240
},
241+
"chaiscript": {
242+
"title": "ChaiScript",
243+
"require": ["clike", "cpp"],
244+
"owner": "RunDevelopment"
245+
},
241246
"cil": {
242247
"title": "CIL",
243248
"owner": "sbrl"

Diff for: components/prism-chaiscript.js

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
Prism.languages.chaiscript = Prism.languages.extend('clike', {
2+
'string': {
3+
pattern: /(^|[^\\])'(?:[^'\\]|\\[\s\S])*'/,
4+
lookbehind: true,
5+
greedy: true
6+
},
7+
'class-name': [
8+
{
9+
// e.g. class Rectangle { ... }
10+
pattern: /(\bclass\s+)\w+/,
11+
lookbehind: true
12+
},
13+
{
14+
// e.g. attr Rectangle::height, def Rectangle::area() { ... }
15+
pattern: /(\b(?:attr|def)\s+)\w+(?=\s*::)/,
16+
lookbehind: true
17+
}
18+
],
19+
'keyword': /\b(?:attr|auto|break|case|catch|class|continue|def|default|else|finally|for|fun|global|if|return|switch|this|try|var|while)\b/,
20+
'number': [
21+
Prism.languages.cpp.number,
22+
/\b(?:Infinity|NaN)\b/
23+
],
24+
'operator': />>=?|<<=?|\|\||&&|:[:=]?|--|\+\+|[=!<>+\-*/%|&^]=?|[?~]|`[^`\r\n]{1,4}`/,
25+
});
26+
27+
Prism.languages.insertBefore('chaiscript', 'operator', {
28+
'parameter-type': {
29+
// e.g. def foo(int x, Vector y) {...}
30+
pattern: /([,(]\s*)\w+(?=\s+\w)/,
31+
lookbehind: true,
32+
alias: 'class-name'
33+
},
34+
});
35+
36+
Prism.languages.insertBefore('chaiscript', 'string', {
37+
'string-interpolation': {
38+
pattern: /(^|[^\\])"(?:[^"$\\]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\})*"/,
39+
lookbehind: true,
40+
greedy: true,
41+
inside: {
42+
'interpolation': {
43+
pattern: /((?:^|[^\\])(?:\\{2})*)\$\{(?:[^{}]|\{(?:[^{}]|\{[^{}]*\})*\})*\}/,
44+
lookbehind: true,
45+
inside: {
46+
'interpolation-expression': {
47+
pattern: /(^\$\{)[\s\S]+(?=\}$)/,
48+
lookbehind: true,
49+
inside: Prism.languages.chaiscript
50+
},
51+
'interpolation-punctuation': {
52+
pattern: /^\$\{|\}$/,
53+
alias: 'punctuation'
54+
}
55+
}
56+
},
57+
'string': /[\s\S]+/
58+
}
59+
},
60+
});

Diff for: components/prism-chaiscript.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: examples/prism-chaiscript.html

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<h2>Full example</h2>
2+
<pre><code>// http://chaiscript.com/examples.html#ChaiScript_Language_Examples
3+
// Source: https://gist.github.com/lefticus/cf058f2927fef68d58e0#file-chaiscript_overview-chai
4+
5+
// ChaiScript supports the normal kind of control blocks you've come to expect from
6+
// C++ and JavaScript
7+
8+
9+
if (5 > 2) {
10+
print("Yup, 5 > 2");
11+
} else if (2 > 5) {
12+
// never gonna happen
13+
} else {
14+
// really not going to happen
15+
}
16+
17+
var x = true;
18+
19+
while (x)
20+
{
21+
print("x was true")
22+
x = false;
23+
}
24+
25+
for (var i = 1; i &lt; 10; ++i)
26+
{
27+
print(i); // prints 1 through 9
28+
}
29+
30+
31+
// function definition
32+
33+
def myFunc(x) {
34+
print(x);
35+
}
36+
37+
// function definition with function guards
38+
def myFunc(x) : x > 2 && x &lt; 5 {
39+
print(to_string(x) + " is between 2 and 5")
40+
}
41+
42+
def myFunc(x) : x >= 5 {
43+
print(t_string(x) + " is greater than or equal to 5")
44+
}
45+
46+
myFunc(3)
47+
48+
// ChaiScript also supports in string evaluation, which C++ does not
49+
50+
print("${3 + 5} is 8");
51+
52+
// And dynamic code evaluation
53+
54+
var value = eval("4 + 2 + 12");
55+
56+
// value is equal to 18</code></pre>

Diff for: plugins/autoloader/prism-autoloader.js

+4
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
"c": "clike",
2626
"csharp": "clike",
2727
"cpp": "c",
28+
"chaiscript": [
29+
"clike",
30+
"cpp"
31+
],
2832
"coffeescript": "javascript",
2933
"crystal": "ruby",
3034
"css-extras": "css",

Diff for: plugins/autoloader/prism-autoloader.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tests/languages/chaiscript/boolean_feature.test

+9
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+
]

Diff for: tests/languages/chaiscript/comment_feature.test

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// comment
2+
/*
3+
comment
4+
*/
5+
6+
/*
7+
comment
8+
9+
----------------------------------------------------
10+
11+
[
12+
["comment", "// comment"],
13+
["comment", "/*\r\n comment\r\n*/"],
14+
15+
["comment", "/*\r\n comment"]
16+
]

Diff for: tests/languages/chaiscript/function_feature.test

+190
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,190 @@
1+
attr Rectangle::height
2+
attr Rectangle::width
3+
def Rectangle::Rectangle() { this.height = 10; this.width = 20 }
4+
def Rectangle::area() { this.height * this.width }
5+
var rect = Rectangle()
6+
rect.height = 30
7+
print(rect.area())
8+
9+
class Rectangle {
10+
attr height
11+
attr width
12+
def Rectangle() { this.height = 10; this.width = 20 }
13+
def area() { this.height * this.width }
14+
}
15+
var rect = Rectangle()
16+
rect.height = 30
17+
print(rect.area())
18+
19+
def update(dt) {
20+
x = x + 20.0f * dt
21+
}
22+
23+
def foo(int x, Vector y) {}
24+
25+
----------------------------------------------------
26+
27+
[
28+
["keyword", "attr"],
29+
["class-name", "Rectangle"],
30+
["operator", "::"],
31+
"height\r\n",
32+
33+
["keyword", "attr"],
34+
["class-name", "Rectangle"],
35+
["operator", "::"],
36+
"width\r\n",
37+
38+
["keyword", "def"],
39+
["class-name", "Rectangle"],
40+
["operator", "::"],
41+
["function", "Rectangle"],
42+
["punctuation", "("],
43+
["punctuation", ")"],
44+
["punctuation", "{"],
45+
["keyword", "this"],
46+
["punctuation", "."],
47+
"height ",
48+
["operator", "="],
49+
["number", "10"],
50+
["punctuation", ";"],
51+
["keyword", "this"],
52+
["punctuation", "."],
53+
"width ",
54+
["operator", "="],
55+
["number", "20"],
56+
["punctuation", "}"],
57+
58+
["keyword", "def"],
59+
["class-name", "Rectangle"],
60+
["operator", "::"],
61+
["function", "area"],
62+
["punctuation", "("],
63+
["punctuation", ")"],
64+
["punctuation", "{"],
65+
["keyword", "this"],
66+
["punctuation", "."],
67+
"height ",
68+
["operator", "*"],
69+
["keyword", "this"],
70+
["punctuation", "."],
71+
"width ",
72+
["punctuation", "}"],
73+
74+
["keyword", "var"],
75+
" rect ",
76+
["operator", "="],
77+
["function", "Rectangle"],
78+
["punctuation", "("],
79+
["punctuation", ")"],
80+
81+
"\r\nrect",
82+
["punctuation", "."],
83+
"height ",
84+
["operator", "="],
85+
["number", "30"],
86+
87+
["function", "print"],
88+
["punctuation", "("],
89+
"rect",
90+
["punctuation", "."],
91+
["function", "area"],
92+
["punctuation", "("],
93+
["punctuation", ")"],
94+
["punctuation", ")"],
95+
96+
["keyword", "class"],
97+
["class-name", "Rectangle"],
98+
["punctuation", "{"],
99+
100+
["keyword", "attr"],
101+
" height\r\n ",
102+
103+
["keyword", "attr"],
104+
" width\r\n ",
105+
106+
["keyword", "def"],
107+
["function", "Rectangle"],
108+
["punctuation", "("],
109+
["punctuation", ")"],
110+
["punctuation", "{"],
111+
["keyword", "this"],
112+
["punctuation", "."],
113+
"height ",
114+
["operator", "="],
115+
["number", "10"],
116+
["punctuation", ";"],
117+
["keyword", "this"],
118+
["punctuation", "."],
119+
"width ",
120+
["operator", "="],
121+
["number", "20"],
122+
["punctuation", "}"],
123+
124+
["keyword", "def"],
125+
["function", "area"],
126+
["punctuation", "("],
127+
["punctuation", ")"],
128+
["punctuation", "{"],
129+
["keyword", "this"],
130+
["punctuation", "."],
131+
"height ",
132+
["operator", "*"],
133+
["keyword", "this"],
134+
["punctuation", "."],
135+
"width ",
136+
["punctuation", "}"],
137+
138+
["punctuation", "}"],
139+
140+
["keyword", "var"],
141+
" rect ",
142+
["operator", "="],
143+
["function", "Rectangle"],
144+
["punctuation", "("],
145+
["punctuation", ")"],
146+
147+
"\r\nrect",
148+
["punctuation", "."],
149+
"height ",
150+
["operator", "="],
151+
["number", "30"],
152+
153+
["function", "print"],
154+
["punctuation", "("],
155+
"rect",
156+
["punctuation", "."],
157+
["function", "area"],
158+
["punctuation", "("],
159+
["punctuation", ")"],
160+
["punctuation", ")"],
161+
162+
["keyword", "def"],
163+
["function", "update"],
164+
["punctuation", "("],
165+
"dt",
166+
["punctuation", ")"],
167+
["punctuation", "{"],
168+
169+
"\r\n x ",
170+
["operator", "="],
171+
" x ",
172+
["operator", "+"],
173+
["number", "20.0f"],
174+
["operator", "*"],
175+
" dt\r\n",
176+
177+
["punctuation", "}"],
178+
179+
["keyword", "def"],
180+
["function", "foo"],
181+
["punctuation", "("],
182+
["parameter-type", "int"],
183+
" x",
184+
["punctuation", ","],
185+
["parameter-type", "Vector"],
186+
" y",
187+
["punctuation", ")"],
188+
["punctuation", "{"],
189+
["punctuation", "}"]
190+
]

0 commit comments

Comments
 (0)