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