1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | function moonscript(hljs) {
|
11 | const KEYWORDS = {
|
12 | keyword:
|
13 |
|
14 | 'if then not for in while do return else elseif break continue switch and or '
|
15 | + 'unless when class extends super local import export from using',
|
16 | literal:
|
17 | 'true false nil',
|
18 | built_in:
|
19 | '_G _VERSION assert collectgarbage dofile error getfenv getmetatable ipairs load '
|
20 | + 'loadfile loadstring module next pairs pcall print rawequal rawget rawset require '
|
21 | + 'select setfenv setmetatable tonumber tostring type unpack xpcall coroutine debug '
|
22 | + 'io math os package string table'
|
23 | };
|
24 | const JS_IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*';
|
25 | const SUBST = {
|
26 | className: 'subst',
|
27 | begin: /#\{/,
|
28 | end: /\}/,
|
29 | keywords: KEYWORDS
|
30 | };
|
31 | const EXPRESSIONS = [
|
32 | hljs.inherit(hljs.C_NUMBER_MODE,
|
33 | { starts: {
|
34 | end: '(\\s*/)?',
|
35 | relevance: 0
|
36 | } }),
|
37 | {
|
38 | className: 'string',
|
39 | variants: [
|
40 | {
|
41 | begin: /'/,
|
42 | end: /'/,
|
43 | contains: [ hljs.BACKSLASH_ESCAPE ]
|
44 | },
|
45 | {
|
46 | begin: /"/,
|
47 | end: /"/,
|
48 | contains: [
|
49 | hljs.BACKSLASH_ESCAPE,
|
50 | SUBST
|
51 | ]
|
52 | }
|
53 | ]
|
54 | },
|
55 | {
|
56 | className: 'built_in',
|
57 | begin: '@__' + hljs.IDENT_RE
|
58 | },
|
59 | { begin: '@' + hljs.IDENT_RE
|
60 | },
|
61 | { begin: hljs.IDENT_RE + '\\\\' + hljs.IDENT_RE
|
62 | }
|
63 | ];
|
64 | SUBST.contains = EXPRESSIONS;
|
65 |
|
66 | const TITLE = hljs.inherit(hljs.TITLE_MODE, { begin: JS_IDENT_RE });
|
67 | const POSSIBLE_PARAMS_RE = '(\\(.*\\)\\s*)?\\B[-=]>';
|
68 | const PARAMS = {
|
69 | className: 'params',
|
70 | begin: '\\([^\\(]',
|
71 | returnBegin: true,
|
72 | |
73 |
|
74 | contains: [
|
75 | {
|
76 | begin: /\(/,
|
77 | end: /\)/,
|
78 | keywords: KEYWORDS,
|
79 | contains: [ 'self' ].concat(EXPRESSIONS)
|
80 | }
|
81 | ]
|
82 | };
|
83 |
|
84 | return {
|
85 | name: 'MoonScript',
|
86 | aliases: [ 'moon' ],
|
87 | keywords: KEYWORDS,
|
88 | illegal: /\/\*/,
|
89 | contains: EXPRESSIONS.concat([
|
90 | hljs.COMMENT('--', '$'),
|
91 | {
|
92 | className: 'function',
|
93 | begin: '^\\s*' + JS_IDENT_RE + '\\s*=\\s*' + POSSIBLE_PARAMS_RE,
|
94 | end: '[-=]>',
|
95 | returnBegin: true,
|
96 | contains: [
|
97 | TITLE,
|
98 | PARAMS
|
99 | ]
|
100 | },
|
101 | {
|
102 | begin: /[\(,:=]\s*/,
|
103 | relevance: 0,
|
104 | contains: [
|
105 | {
|
106 | className: 'function',
|
107 | begin: POSSIBLE_PARAMS_RE,
|
108 | end: '[-=]>',
|
109 | returnBegin: true,
|
110 | contains: [ PARAMS ]
|
111 | }
|
112 | ]
|
113 | },
|
114 | {
|
115 | className: 'class',
|
116 | beginKeywords: 'class',
|
117 | end: '$',
|
118 | illegal: /[:="\[\]]/,
|
119 | contains: [
|
120 | {
|
121 | beginKeywords: 'extends',
|
122 | endsWithParent: true,
|
123 | illegal: /[:="\[\]]/,
|
124 | contains: [ TITLE ]
|
125 | },
|
126 | TITLE
|
127 | ]
|
128 | },
|
129 | {
|
130 | className: 'name',
|
131 | begin: JS_IDENT_RE + ':',
|
132 | end: ':',
|
133 | returnBegin: true,
|
134 | returnEnd: true,
|
135 | relevance: 0
|
136 | }
|
137 | ])
|
138 | };
|
139 | }
|
140 |
|
141 | module.exports = moonscript;
|