source: node_modules/highlight.js/lib/languages/livescript.js@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

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