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