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 | {
|
34 | starts: {
|
35 | end: '(\\s*/)?',
|
36 | relevance: 0
|
37 | }
|
38 | }),
|
39 | {
|
40 | className: 'string',
|
41 | variants: [
|
42 | {
|
43 | begin: /'/,
|
44 | end: /'/,
|
45 | contains: [ hljs.BACKSLASH_ESCAPE ]
|
46 | },
|
47 | {
|
48 | begin: /"/,
|
49 | end: /"/,
|
50 | contains: [
|
51 | hljs.BACKSLASH_ESCAPE,
|
52 | SUBST
|
53 | ]
|
54 | }
|
55 | ]
|
56 | },
|
57 | {
|
58 | className: 'built_in',
|
59 | begin: '@__' + hljs.IDENT_RE
|
60 | },
|
61 | {
|
62 | begin: '@' + hljs.IDENT_RE
|
63 | },
|
64 | {
|
65 | begin: hljs.IDENT_RE + '\\\\' + hljs.IDENT_RE
|
66 | }
|
67 | ];
|
68 | SUBST.contains = EXPRESSIONS;
|
69 |
|
70 | const TITLE = hljs.inherit(hljs.TITLE_MODE, {
|
71 | begin: JS_IDENT_RE
|
72 | });
|
73 | const POSSIBLE_PARAMS_RE = '(\\(.*\\)\\s*)?\\B[-=]>';
|
74 | const PARAMS = {
|
75 | className: 'params',
|
76 | begin: '\\([^\\(]',
|
77 | returnBegin: true,
|
78 | |
79 |
|
80 | contains: [
|
81 | {
|
82 | begin: /\(/,
|
83 | end: /\)/,
|
84 | keywords: KEYWORDS,
|
85 | contains: [ 'self' ].concat(EXPRESSIONS)
|
86 | }
|
87 | ]
|
88 | };
|
89 |
|
90 | return {
|
91 | name: 'MoonScript',
|
92 | aliases: [ 'moon' ],
|
93 | keywords: KEYWORDS,
|
94 | illegal: /\/\*/,
|
95 | contains: EXPRESSIONS.concat([
|
96 | hljs.COMMENT('--', '$'),
|
97 | {
|
98 | className: 'function',
|
99 | begin: '^\\s*' + JS_IDENT_RE + '\\s*=\\s*' + POSSIBLE_PARAMS_RE,
|
100 | end: '[-=]>',
|
101 | returnBegin: true,
|
102 | contains: [
|
103 | TITLE,
|
104 | PARAMS
|
105 | ]
|
106 | },
|
107 | {
|
108 | begin: /[\(,:=]\s*/,
|
109 | relevance: 0,
|
110 | contains: [
|
111 | {
|
112 | className: 'function',
|
113 | begin: POSSIBLE_PARAMS_RE,
|
114 | end: '[-=]>',
|
115 | returnBegin: true,
|
116 | contains: [ PARAMS ]
|
117 | }
|
118 | ]
|
119 | },
|
120 | {
|
121 | className: 'class',
|
122 | beginKeywords: 'class',
|
123 | end: '$',
|
124 | illegal: /[:="\[\]]/,
|
125 | contains: [
|
126 | {
|
127 | beginKeywords: 'extends',
|
128 | endsWithParent: true,
|
129 | illegal: /[:="\[\]]/,
|
130 | contains: [ TITLE ]
|
131 | },
|
132 | TITLE
|
133 | ]
|
134 | },
|
135 | {
|
136 | className: 'name',
|
137 | begin: JS_IDENT_RE + ':',
|
138 | end: ':',
|
139 | returnBegin: true,
|
140 | returnEnd: true,
|
141 | relevance: 0
|
142 | }
|
143 | ])
|
144 | };
|
145 | }
|
146 |
|
147 | export { moonscript as default };
|