UNPKG

2.98 kBJavaScriptView Raw
1/*
2Language: Monkey
3Description: Monkey2 is an easy to use, cross platform, games oriented programming language from Blitz Research.
4Author: Arthur Bikmullin <devolonter@gmail.com>
5Website: https://blitzresearch.itch.io/monkey2
6*/
7
8function monkey(hljs) {
9 const NUMBER = {
10 className: 'number',
11 relevance: 0,
12 variants: [
13 { begin: '[$][a-fA-F0-9]+' },
14 hljs.NUMBER_MODE
15 ]
16 };
17 const FUNC_DEFINITION = {
18 variants: [
19 { match: [
20 /(function|method)/,
21 /\s+/,
22 hljs.UNDERSCORE_IDENT_RE,
23 ] },
24 ],
25 scope: {
26 1: "keyword",
27 3: "title.function"
28 }
29 };
30 const CLASS_DEFINITION = {
31 variants: [
32 { match: [
33 /(class|interface|extends|implements)/,
34 /\s+/,
35 hljs.UNDERSCORE_IDENT_RE,
36 ] },
37 ],
38 scope: {
39 1: "keyword",
40 3: "title.class"
41 }
42 };
43 const BUILT_INS = [
44 "DebugLog",
45 "DebugStop",
46 "Error",
47 "Print",
48 "ACos",
49 "ACosr",
50 "ASin",
51 "ASinr",
52 "ATan",
53 "ATan2",
54 "ATan2r",
55 "ATanr",
56 "Abs",
57 "Abs",
58 "Ceil",
59 "Clamp",
60 "Clamp",
61 "Cos",
62 "Cosr",
63 "Exp",
64 "Floor",
65 "Log",
66 "Max",
67 "Max",
68 "Min",
69 "Min",
70 "Pow",
71 "Sgn",
72 "Sgn",
73 "Sin",
74 "Sinr",
75 "Sqrt",
76 "Tan",
77 "Tanr",
78 "Seed",
79 "PI",
80 "HALFPI",
81 "TWOPI"
82 ];
83 const LITERALS = [
84 "true",
85 "false",
86 "null"
87 ];
88 const KEYWORDS = [
89 "public",
90 "private",
91 "property",
92 "continue",
93 "exit",
94 "extern",
95 "new",
96 "try",
97 "catch",
98 "eachin",
99 "not",
100 "abstract",
101 "final",
102 "select",
103 "case",
104 "default",
105 "const",
106 "local",
107 "global",
108 "field",
109 "end",
110 "if",
111 "then",
112 "else",
113 "elseif",
114 "endif",
115 "while",
116 "wend",
117 "repeat",
118 "until",
119 "forever",
120 "for",
121 "to",
122 "step",
123 "next",
124 "return",
125 "module",
126 "inline",
127 "throw",
128 "import",
129 // not positive, but these are not literals
130 "and",
131 "or",
132 "shl",
133 "shr",
134 "mod"
135 ];
136
137 return {
138 name: 'Monkey',
139 case_insensitive: true,
140 keywords: {
141 keyword: KEYWORDS,
142 built_in: BUILT_INS,
143 literal: LITERALS
144 },
145 illegal: /\/\*/,
146 contains: [
147 hljs.COMMENT('#rem', '#end'),
148 hljs.COMMENT(
149 "'",
150 '$',
151 { relevance: 0 }
152 ),
153 FUNC_DEFINITION,
154 CLASS_DEFINITION,
155 {
156 className: 'variable.language',
157 begin: /\b(self|super)\b/
158 },
159 {
160 className: 'meta',
161 begin: /\s*#/,
162 end: '$',
163 keywords: { keyword: 'if else elseif endif end then' }
164 },
165 {
166 match: [
167 /^\s*/,
168 /strict\b/
169 ],
170 scope: { 2: "meta" }
171 },
172 {
173 beginKeywords: 'alias',
174 end: '=',
175 contains: [ hljs.UNDERSCORE_TITLE_MODE ]
176 },
177 hljs.QUOTE_STRING_MODE,
178 NUMBER
179 ]
180 };
181}
182
183module.exports = monkey;