]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/wren.js
Initial commit.
[flow-web.git] / static / highlight / languages / wren.js
1 /*! `wren` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 /*
7 Language: Wren
8 Description: Think Smalltalk in a Lua-sized package with a dash of Erlang and wrapped up in a familiar, modern syntax.
9 Category: scripting
10 Author: @joshgoebel
11 Maintainer: @joshgoebel
12 Website: https://wren.io/
13 */
14
15 /** @type LanguageFn */
16 function wren(hljs) {
17 const regex = hljs.regex;
18 const IDENT_RE = /[a-zA-Z]\w*/;
19 const KEYWORDS = [
20 "as",
21 "break",
22 "class",
23 "construct",
24 "continue",
25 "else",
26 "for",
27 "foreign",
28 "if",
29 "import",
30 "in",
31 "is",
32 "return",
33 "static",
34 "var",
35 "while"
36 ];
37 const LITERALS = [
38 "true",
39 "false",
40 "null"
41 ];
42 const LANGUAGE_VARS = [
43 "this",
44 "super"
45 ];
46 const CORE_CLASSES = [
47 "Bool",
48 "Class",
49 "Fiber",
50 "Fn",
51 "List",
52 "Map",
53 "Null",
54 "Num",
55 "Object",
56 "Range",
57 "Sequence",
58 "String",
59 "System"
60 ];
61 const OPERATORS = [
62 "-",
63 "~",
64 /\*/,
65 "%",
66 /\.\.\./,
67 /\.\./,
68 /\+/,
69 "<<",
70 ">>",
71 ">=",
72 "<=",
73 "<",
74 ">",
75 /\^/,
76 /!=/,
77 /!/,
78 /\bis\b/,
79 "==",
80 "&&",
81 "&",
82 /\|\|/,
83 /\|/,
84 /\?:/,
85 "="
86 ];
87 const FUNCTION = {
88 relevance: 0,
89 match: regex.concat(/\b(?!(if|while|for|else|super)\b)/, IDENT_RE, /(?=\s*[({])/),
90 className: "title.function"
91 };
92 const FUNCTION_DEFINITION = {
93 match: regex.concat(
94 regex.either(
95 regex.concat(/\b(?!(if|while|for|else|super)\b)/, IDENT_RE),
96 regex.either(...OPERATORS)
97 ),
98 /(?=\s*\([^)]+\)\s*\{)/),
99 className: "title.function",
100 starts: { contains: [
101 {
102 begin: /\(/,
103 end: /\)/,
104 contains: [
105 {
106 relevance: 0,
107 scope: "params",
108 match: IDENT_RE
109 }
110 ]
111 }
112 ] }
113 };
114 const CLASS_DEFINITION = {
115 variants: [
116 { match: [
117 /class\s+/,
118 IDENT_RE,
119 /\s+is\s+/,
120 IDENT_RE
121 ] },
122 { match: [
123 /class\s+/,
124 IDENT_RE
125 ] }
126 ],
127 scope: {
128 2: "title.class",
129 4: "title.class.inherited"
130 },
131 keywords: KEYWORDS
132 };
133
134 const OPERATOR = {
135 relevance: 0,
136 match: regex.either(...OPERATORS),
137 className: "operator"
138 };
139
140 const TRIPLE_STRING = {
141 className: "string",
142 begin: /"""/,
143 end: /"""/
144 };
145
146 const PROPERTY = {
147 className: "property",
148 begin: regex.concat(/\./, regex.lookahead(IDENT_RE)),
149 end: IDENT_RE,
150 excludeBegin: true,
151 relevance: 0
152 };
153
154 const FIELD = {
155 relevance: 0,
156 match: regex.concat(/\b_/, IDENT_RE),
157 scope: "variable"
158 };
159
160 // CamelCase
161 const CLASS_REFERENCE = {
162 relevance: 0,
163 match: /\b[A-Z]+[a-z]+([A-Z]+[a-z]+)*/,
164 scope: "title.class",
165 keywords: { _: CORE_CLASSES }
166 };
167
168 // TODO: add custom number modes
169 const NUMBER = hljs.C_NUMBER_MODE;
170
171 const SETTER = {
172 match: [
173 IDENT_RE,
174 /\s*/,
175 /=/,
176 /\s*/,
177 /\(/,
178 IDENT_RE,
179 /\)\s*\{/
180 ],
181 scope: {
182 1: "title.function",
183 3: "operator",
184 6: "params"
185 }
186 };
187
188 const COMMENT_DOCS = hljs.COMMENT(
189 /\/\*\*/,
190 /\*\//,
191 { contains: [
192 {
193 match: /@[a-z]+/,
194 scope: "doctag"
195 },
196 "self"
197 ] }
198 );
199 const SUBST = {
200 scope: "subst",
201 begin: /%\(/,
202 end: /\)/,
203 contains: [
204 NUMBER,
205 CLASS_REFERENCE,
206 FUNCTION,
207 FIELD,
208 OPERATOR
209 ]
210 };
211 const STRING = {
212 scope: "string",
213 begin: /"/,
214 end: /"/,
215 contains: [
216 SUBST,
217 {
218 scope: "char.escape",
219 variants: [
220 { match: /\\\\|\\["0%abefnrtv]/ },
221 { match: /\\x[0-9A-F]{2}/ },
222 { match: /\\u[0-9A-F]{4}/ },
223 { match: /\\U[0-9A-F]{8}/ }
224 ]
225 }
226 ]
227 };
228 SUBST.contains.push(STRING);
229
230 const ALL_KWS = [
231 ...KEYWORDS,
232 ...LANGUAGE_VARS,
233 ...LITERALS
234 ];
235 const VARIABLE = {
236 relevance: 0,
237 match: regex.concat(
238 "\\b(?!",
239 ALL_KWS.join("|"),
240 "\\b)",
241 /[a-zA-Z_]\w*(?:[?!]|\b)/
242 ),
243 className: "variable"
244 };
245
246 // TODO: reconsider this in the future
247 const ATTRIBUTE = {
248 // scope: "meta",
249 scope: "comment",
250 variants: [
251 {
252 begin: [
253 /#!?/,
254 /[A-Za-z_]+(?=\()/
255 ],
256 beginScope: {
257 // 2: "attr"
258 },
259 keywords: { literal: LITERALS },
260 contains: [
261 // NUMBER,
262 // VARIABLE
263 ],
264 end: /\)/
265 },
266 {
267 begin: [
268 /#!?/,
269 /[A-Za-z_]+/
270 ],
271 beginScope: {
272 // 2: "attr"
273 },
274 end: /$/
275 }
276 ]
277 };
278
279 return {
280 name: "Wren",
281 keywords: {
282 keyword: KEYWORDS,
283 "variable.language": LANGUAGE_VARS,
284 literal: LITERALS
285 },
286 contains: [
287 ATTRIBUTE,
288 NUMBER,
289 STRING,
290 TRIPLE_STRING,
291 COMMENT_DOCS,
292 hljs.C_LINE_COMMENT_MODE,
293 hljs.C_BLOCK_COMMENT_MODE,
294 CLASS_REFERENCE,
295 CLASS_DEFINITION,
296 SETTER,
297 FUNCTION_DEFINITION,
298 FUNCTION,
299 OPERATOR,
300 FIELD,
301 PROPERTY,
302 VARIABLE
303 ]
304 };
305 }
306
307 return wren;
308
309 })();
310
311 hljs.registerLanguage('wren', hljsGrammar);
312 })();