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