]> luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/livescript.js
Initial commit.
[flow-web.git] / static / highlight / es / languages / livescript.js
1 /*! `livescript` 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: LiveScript
153 Author: Taneli Vatanen <taneli.vatanen@gmail.com>
154 Contributors: Jen Evers-Corvina <jen@sevvie.net>
155 Origin: coffeescript.js
156 Description: LiveScript is a programming language that transcompiles to JavaScript. For info about language see http://livescript.net/
157 Website: https://livescript.net
158 Category: scripting
159 */
160
161
162 function livescript(hljs) {
163 const LIVESCRIPT_BUILT_INS = [
164 'npm',
165 'print'
166 ];
167 const LIVESCRIPT_LITERALS = [
168 'yes',
169 'no',
170 'on',
171 'off',
172 'it',
173 'that',
174 'void'
175 ];
176 const LIVESCRIPT_KEYWORDS = [
177 'then',
178 'unless',
179 'until',
180 'loop',
181 'of',
182 'by',
183 'when',
184 'and',
185 'or',
186 'is',
187 'isnt',
188 'not',
189 'it',
190 'that',
191 'otherwise',
192 'from',
193 'to',
194 'til',
195 'fallthrough',
196 'case',
197 'enum',
198 'native',
199 'list',
200 'map',
201 '__hasProp',
202 '__extends',
203 '__slice',
204 '__bind',
205 '__indexOf'
206 ];
207 const KEYWORDS$1 = {
208 keyword: KEYWORDS.concat(LIVESCRIPT_KEYWORDS),
209 literal: LITERALS.concat(LIVESCRIPT_LITERALS),
210 built_in: BUILT_INS.concat(LIVESCRIPT_BUILT_INS)
211 };
212 const JS_IDENT_RE = '[A-Za-z$_](?:-[0-9A-Za-z$_]|[0-9A-Za-z$_])*';
213 const TITLE = hljs.inherit(hljs.TITLE_MODE, { begin: JS_IDENT_RE });
214 const SUBST = {
215 className: 'subst',
216 begin: /#\{/,
217 end: /\}/,
218 keywords: KEYWORDS$1
219 };
220 const SUBST_SIMPLE = {
221 className: 'subst',
222 begin: /#[A-Za-z$_]/,
223 end: /(?:-[0-9A-Za-z$_]|[0-9A-Za-z$_])*/,
224 keywords: KEYWORDS$1
225 };
226 const EXPRESSIONS = [
227 hljs.BINARY_NUMBER_MODE,
228 {
229 className: 'number',
230 begin: '(\\b0[xX][a-fA-F0-9_]+)|(\\b\\d(\\d|_\\d)*(\\.(\\d(\\d|_\\d)*)?)?(_*[eE]([-+]\\d(_\\d|\\d)*)?)?[_a-z]*)',
231 relevance: 0,
232 starts: {
233 end: '(\\s*/)?',
234 relevance: 0
235 } // a number tries to eat the following slash to prevent treating it as a regexp
236 },
237 {
238 className: 'string',
239 variants: [
240 {
241 begin: /'''/,
242 end: /'''/,
243 contains: [ hljs.BACKSLASH_ESCAPE ]
244 },
245 {
246 begin: /'/,
247 end: /'/,
248 contains: [ hljs.BACKSLASH_ESCAPE ]
249 },
250 {
251 begin: /"""/,
252 end: /"""/,
253 contains: [
254 hljs.BACKSLASH_ESCAPE,
255 SUBST,
256 SUBST_SIMPLE
257 ]
258 },
259 {
260 begin: /"/,
261 end: /"/,
262 contains: [
263 hljs.BACKSLASH_ESCAPE,
264 SUBST,
265 SUBST_SIMPLE
266 ]
267 },
268 {
269 begin: /\\/,
270 end: /(\s|$)/,
271 excludeEnd: true
272 }
273 ]
274 },
275 {
276 className: 'regexp',
277 variants: [
278 {
279 begin: '//',
280 end: '//[gim]*',
281 contains: [
282 SUBST,
283 hljs.HASH_COMMENT_MODE
284 ]
285 },
286 {
287 // regex can't start with space to parse x / 2 / 3 as two divisions
288 // regex can't start with *, and it supports an "illegal" in the main mode
289 begin: /\/(?![ *])(\\.|[^\\\n])*?\/[gim]*(?=\W)/ }
290 ]
291 },
292 { begin: '@' + JS_IDENT_RE },
293 {
294 begin: '``',
295 end: '``',
296 excludeBegin: true,
297 excludeEnd: true,
298 subLanguage: 'javascript'
299 }
300 ];
301 SUBST.contains = EXPRESSIONS;
302
303 const PARAMS = {
304 className: 'params',
305 begin: '\\(',
306 returnBegin: true,
307 /* We need another contained nameless mode to not have every nested
308 pair of parens to be called "params" */
309 contains: [
310 {
311 begin: /\(/,
312 end: /\)/,
313 keywords: KEYWORDS$1,
314 contains: [ 'self' ].concat(EXPRESSIONS)
315 }
316 ]
317 };
318
319 const SYMBOLS = { begin: '(#=>|=>|\\|>>|-?->|!->)' };
320
321 const CLASS_DEFINITION = {
322 variants: [
323 { match: [
324 /class\s+/,
325 JS_IDENT_RE,
326 /\s+extends\s+/,
327 JS_IDENT_RE
328 ] },
329 { match: [
330 /class\s+/,
331 JS_IDENT_RE
332 ] }
333 ],
334 scope: {
335 2: "title.class",
336 4: "title.class.inherited"
337 },
338 keywords: KEYWORDS$1
339 };
340
341 return {
342 name: 'LiveScript',
343 aliases: [ 'ls' ],
344 keywords: KEYWORDS$1,
345 illegal: /\/\*/,
346 contains: EXPRESSIONS.concat([
347 hljs.COMMENT('\\/\\*', '\\*\\/'),
348 hljs.HASH_COMMENT_MODE,
349 SYMBOLS, // relevance booster
350 {
351 className: 'function',
352 contains: [
353 TITLE,
354 PARAMS
355 ],
356 returnBegin: true,
357 variants: [
358 {
359 begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?(\\(.*\\)\\s*)?\\B->\\*?',
360 end: '->\\*?'
361 },
362 {
363 begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?!?(\\(.*\\)\\s*)?\\B[-~]{1,2}>\\*?',
364 end: '[-~]{1,2}>\\*?'
365 },
366 {
367 begin: '(' + JS_IDENT_RE + '\\s*(?:=|:=)\\s*)?(\\(.*\\)\\s*)?\\B!?[-~]{1,2}>\\*?',
368 end: '!?[-~]{1,2}>\\*?'
369 }
370 ]
371 },
372 CLASS_DEFINITION,
373 {
374 begin: JS_IDENT_RE + ':',
375 end: ':',
376 returnBegin: true,
377 returnEnd: true,
378 relevance: 0
379 }
380 ])
381 };
382 }
383
384 return livescript;
385
386 })();
387 ;
388 export default hljsGrammar;