]> luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/moonscript.js
Initial commit.
[flow-web.git] / static / highlight / es / languages / moonscript.js
1 /*! `moonscript` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar = (function () {
3 'use strict';
4
5 /*
6 Language: MoonScript
7 Author: Billy Quith <chinbillybilbo@gmail.com>
8 Description: MoonScript is a programming language that transcompiles to Lua.
9 Origin: coffeescript.js
10 Website: http://moonscript.org/
11 Category: scripting
12 */
13
14 function moonscript(hljs) {
15 const KEYWORDS = {
16 keyword:
17 // Moonscript keywords
18 'if then not for in while do return else elseif break continue switch and or '
19 + 'unless when class extends super local import export from using',
20 literal:
21 'true false nil',
22 built_in:
23 '_G _VERSION assert collectgarbage dofile error getfenv getmetatable ipairs load '
24 + 'loadfile loadstring module next pairs pcall print rawequal rawget rawset require '
25 + 'select setfenv setmetatable tonumber tostring type unpack xpcall coroutine debug '
26 + 'io math os package string table'
27 };
28 const JS_IDENT_RE = '[A-Za-z$_][0-9A-Za-z$_]*';
29 const SUBST = {
30 className: 'subst',
31 begin: /#\{/,
32 end: /\}/,
33 keywords: KEYWORDS
34 };
35 const EXPRESSIONS = [
36 hljs.inherit(hljs.C_NUMBER_MODE,
37 { starts: {
38 end: '(\\s*/)?',
39 relevance: 0
40 } }), // a number tries to eat the following slash to prevent treating it as a regexp
41 {
42 className: 'string',
43 variants: [
44 {
45 begin: /'/,
46 end: /'/,
47 contains: [ hljs.BACKSLASH_ESCAPE ]
48 },
49 {
50 begin: /"/,
51 end: /"/,
52 contains: [
53 hljs.BACKSLASH_ESCAPE,
54 SUBST
55 ]
56 }
57 ]
58 },
59 {
60 className: 'built_in',
61 begin: '@__' + hljs.IDENT_RE
62 },
63 { begin: '@' + hljs.IDENT_RE // relevance booster on par with CoffeeScript
64 },
65 { begin: hljs.IDENT_RE + '\\\\' + hljs.IDENT_RE // inst\method
66 }
67 ];
68 SUBST.contains = EXPRESSIONS;
69
70 const TITLE = hljs.inherit(hljs.TITLE_MODE, { begin: JS_IDENT_RE });
71 const POSSIBLE_PARAMS_RE = '(\\(.*\\)\\s*)?\\B[-=]>';
72 const PARAMS = {
73 className: 'params',
74 begin: '\\([^\\(]',
75 returnBegin: true,
76 /* We need another contained nameless mode to not have every nested
77 pair of parens to be called "params" */
78 contains: [
79 {
80 begin: /\(/,
81 end: /\)/,
82 keywords: KEYWORDS,
83 contains: [ 'self' ].concat(EXPRESSIONS)
84 }
85 ]
86 };
87
88 return {
89 name: 'MoonScript',
90 aliases: [ 'moon' ],
91 keywords: KEYWORDS,
92 illegal: /\/\*/,
93 contains: EXPRESSIONS.concat([
94 hljs.COMMENT('--', '$'),
95 {
96 className: 'function', // function: -> =>
97 begin: '^\\s*' + JS_IDENT_RE + '\\s*=\\s*' + POSSIBLE_PARAMS_RE,
98 end: '[-=]>',
99 returnBegin: true,
100 contains: [
101 TITLE,
102 PARAMS
103 ]
104 },
105 {
106 begin: /[\(,:=]\s*/, // anonymous function start
107 relevance: 0,
108 contains: [
109 {
110 className: 'function',
111 begin: POSSIBLE_PARAMS_RE,
112 end: '[-=]>',
113 returnBegin: true,
114 contains: [ PARAMS ]
115 }
116 ]
117 },
118 {
119 className: 'class',
120 beginKeywords: 'class',
121 end: '$',
122 illegal: /[:="\[\]]/,
123 contains: [
124 {
125 beginKeywords: 'extends',
126 endsWithParent: true,
127 illegal: /[:="\[\]]/,
128 contains: [ TITLE ]
129 },
130 TITLE
131 ]
132 },
133 {
134 className: 'name', // table
135 begin: JS_IDENT_RE + ':',
136 end: ':',
137 returnBegin: true,
138 returnEnd: true,
139 relevance: 0
140 }
141 ])
142 };
143 }
144
145 return moonscript;
146
147 })();
148 ;
149 export default hljsGrammar;