]> luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/coffeescript.js
Initial commit.
[flow-web.git] / static / highlight / languages / coffeescript.js
1 /*! `coffeescript` grammar compiled for Highlight.js 11.11.1 */
2 (function(){
3 var hljsGrammar = (function () {
4 'use strict';
5
6 const KEYWORDS = [
7 "as", // for exports
8 "in",
9 "of",
10 "if",
11 "for",
12 "while",
13 "finally",
14 "var",
15 "new",
16 "function",
17 "do",
18 "return",
19 "void",
20 "else",
21 "break",
22 "catch",
23 "instanceof",
24 "with",
25 "throw",
26 "case",
27 "default",
28 "try",
29 "switch",
30 "continue",
31 "typeof",
32 "delete",
33 "let",
34 "yield",
35 "const",
36 "class",
37 // JS handles these with a special rule
38 // "get",
39 // "set",
40 "debugger",
41 "async",
42 "await",
43 "static",
44 "import",
45 "from",
46 "export",
47 "extends",
48 // It's reached stage 3, which is "recommended for implementation":
49 "using"
50 ];
51 const LITERALS = [
52 "true",
53 "false",
54 "null",
55 "undefined",
56 "NaN",
57 "Infinity"
58 ];
59
60 // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects
61 const TYPES = [
62 // Fundamental objects
63 "Object",
64 "Function",
65 "Boolean",
66 "Symbol",
67 // numbers and dates
68 "Math",
69 "Date",
70 "Number",
71 "BigInt",
72 // text
73 "String",
74 "RegExp",
75 // Indexed collections
76 "Array",
77 "Float32Array",
78 "Float64Array",
79 "Int8Array",
80 "Uint8Array",
81 "Uint8ClampedArray",
82 "Int16Array",
83 "Int32Array",
84 "Uint16Array",
85 "Uint32Array",
86 "BigInt64Array",
87 "BigUint64Array",
88 // Keyed collections
89 "Set",
90 "Map",
91 "WeakSet",
92 "WeakMap",
93 // Structured data
94 "ArrayBuffer",
95 "SharedArrayBuffer",
96 "Atomics",
97 "DataView",
98 "JSON",
99 // Control abstraction objects
100 "Promise",
101 "Generator",
102 "GeneratorFunction",
103 "AsyncFunction",
104 // Reflection
105 "Reflect",
106 "Proxy",
107 // Internationalization
108 "Intl",
109 // WebAssembly
110 "WebAssembly"
111 ];
112
113 const ERROR_TYPES = [
114 "Error",
115 "EvalError",
116 "InternalError",
117 "RangeError",
118 "ReferenceError",
119 "SyntaxError",
120 "TypeError",
121 "URIError"
122 ];
123
124 const BUILT_IN_GLOBALS = [
125 "setInterval",
126 "setTimeout",
127 "clearInterval",
128 "clearTimeout",
129
130 "require",
131 "exports",
132
133 "eval",
134 "isFinite",
135 "isNaN",
136 "parseFloat",
137 "parseInt",
138 "decodeURI",
139 "decodeURIComponent",
140 "encodeURI",
141 "encodeURIComponent",
142 "escape",
143 "unescape"
144 ];
145
146 const BUILT_INS = [].concat(
147 BUILT_IN_GLOBALS,
148 TYPES,
149 ERROR_TYPES
150 );
151
152 /*
153 Language: CoffeeScript
154 Author: Dmytrii Nagirniak <dnagir@gmail.com>
155 Contributors: Oleg Efimov <efimovov@gmail.com>, Cédric Néhémie <cedric.nehemie@gmail.com>
156 Description: CoffeeScript is a programming language that transcompiles to JavaScript. For info about language see http://coffeescript.org/
157 Category: scripting
158 Website: https://coffeescript.org
159 */
160
161
162 /** @type LanguageFn */
163 function coffeescript(hljs) {
164 const COFFEE_BUILT_INS = [
165 'npm',
166 'print'
167 ];
168 const COFFEE_LITERALS = [
169 'yes',
170 'no',
171 'on',
172 'off'
173 ];
174 const COFFEE_KEYWORDS = [
175 'then',
176 'unless',
177 'until',
178 'loop',
179 'by',
180 'when',
181 'and',
182 'or',
183 'is',
184 'isnt',
185 'not'
186 ];
187 const NOT_VALID_KEYWORDS = [
188 "var",
189 "const",
190 "let",
191 "function",
192 "static"
193 ];
194 const excluding = (list) =>
195 (kw) => !list.includes(kw);
196 const KEYWORDS$1 = {
197 keyword: KEYWORDS.concat(COFFEE_KEYWORDS).filter(excluding(NOT_VALID_KEYWORDS)),
198 literal: LITERALS.concat(COFFEE_LITERALS),
199 built_in: BUILT_INS.concat(COFFEE_BUILT_INS)
200 };
201 const JS_IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*';
202 const SUBST = {
203 className: 'subst',
204 begin: /#\{/,
205 end: /\}/,
206 keywords: KEYWORDS$1
207 };
208 const EXPRESSIONS = [
209 hljs.BINARY_NUMBER_MODE,
210 hljs.inherit(hljs.C_NUMBER_MODE, { starts: {
211 end: '(\\s*/)?',
212 relevance: 0
213 } }), // a number tries to eat the following slash to prevent treating it as a regexp
214 {
215 className: 'string',
216 variants: [
217 {
218 begin: /'''/,
219 end: /'''/,
220 contains: [ hljs.BACKSLASH_ESCAPE ]
221 },
222 {
223 begin: /'/,
224 end: /'/,
225 contains: [ hljs.BACKSLASH_ESCAPE ]
226 },
227 {
228 begin: /"""/,
229 end: /"""/,
230 contains: [
231 hljs.BACKSLASH_ESCAPE,
232 SUBST
233 ]
234 },
235 {
236 begin: /"/,
237 end: /"/,
238 contains: [
239 hljs.BACKSLASH_ESCAPE,
240 SUBST
241 ]
242 }
243 ]
244 },
245 {
246 className: 'regexp',
247 variants: [
248 {
249 begin: '///',
250 end: '///',
251 contains: [
252 SUBST,
253 hljs.HASH_COMMENT_MODE
254 ]
255 },
256 {
257 begin: '//[gim]{0,3}(?=\\W)',
258 relevance: 0
259 },
260 {
261 // regex can't start with space to parse x / 2 / 3 as two divisions
262 // regex can't start with *, and it supports an "illegal" in the main mode
263 begin: /\/(?![ *]).*?(?![\\]).\/[gim]{0,3}(?=\W)/ }
264 ]
265 },
266 { begin: '@' + JS_IDENT_RE // relevance booster
267 },
268 {
269 subLanguage: 'javascript',
270 excludeBegin: true,
271 excludeEnd: true,
272 variants: [
273 {
274 begin: '```',
275 end: '```'
276 },
277 {
278 begin: '`',
279 end: '`'
280 }
281 ]
282 }
283 ];
284 SUBST.contains = EXPRESSIONS;
285
286 const TITLE = hljs.inherit(hljs.TITLE_MODE, { begin: JS_IDENT_RE });
287 const POSSIBLE_PARAMS_RE = '(\\(.*\\)\\s*)?\\B[-=]>';
288 const PARAMS = {
289 className: 'params',
290 begin: '\\([^\\(]',
291 returnBegin: true,
292 /* We need another contained nameless mode to not have every nested
293 pair of parens to be called "params" */
294 contains: [
295 {
296 begin: /\(/,
297 end: /\)/,
298 keywords: KEYWORDS$1,
299 contains: [ 'self' ].concat(EXPRESSIONS)
300 }
301 ]
302 };
303
304 const CLASS_DEFINITION = {
305 variants: [
306 { match: [
307 /class\s+/,
308 JS_IDENT_RE,
309 /\s+extends\s+/,
310 JS_IDENT_RE
311 ] },
312 { match: [
313 /class\s+/,
314 JS_IDENT_RE
315 ] }
316 ],
317 scope: {
318 2: "title.class",
319 4: "title.class.inherited"
320 },
321 keywords: KEYWORDS$1
322 };
323
324 return {
325 name: 'CoffeeScript',
326 aliases: [
327 'coffee',
328 'cson',
329 'iced'
330 ],
331 keywords: KEYWORDS$1,
332 illegal: /\/\*/,
333 contains: [
334 ...EXPRESSIONS,
335 hljs.COMMENT('###', '###'),
336 hljs.HASH_COMMENT_MODE,
337 {
338 className: 'function',
339 begin: '^\\s*' + JS_IDENT_RE + '\\s*=\\s*' + POSSIBLE_PARAMS_RE,
340 end: '[-=]>',
341 returnBegin: true,
342 contains: [
343 TITLE,
344 PARAMS
345 ]
346 },
347 {
348 // anonymous function start
349 begin: /[:\(,=]\s*/,
350 relevance: 0,
351 contains: [
352 {
353 className: 'function',
354 begin: POSSIBLE_PARAMS_RE,
355 end: '[-=]>',
356 returnBegin: true,
357 contains: [ PARAMS ]
358 }
359 ]
360 },
361 CLASS_DEFINITION,
362 {
363 begin: JS_IDENT_RE + ':',
364 end: ':',
365 returnBegin: true,
366 returnEnd: true,
367 relevance: 0
368 }
369 ]
370 };
371 }
372
373 return coffeescript;
374
375 })();
376
377 hljs.registerLanguage('coffeescript', hljsGrammar);
378 })();