UNPKG

3.53 kBJavaScriptView Raw
1/*
2Language: AngelScript
3Author: Melissa Geels <melissa@nimble.tools>
4Category: scripting
5Website: https://www.angelcode.com/angelscript/
6*/
7
8/** @type LanguageFn */
9function angelscript(hljs) {
10 const builtInTypeMode = {
11 className: 'built_in',
12 begin: '\\b(void|bool|int8|int16|int32|int64|int|uint8|uint16|uint32|uint64|uint|string|ref|array|double|float|auto|dictionary)'
13 };
14
15 const objectHandleMode = {
16 className: 'symbol',
17 begin: '[a-zA-Z0-9_]+@'
18 };
19
20 const genericMode = {
21 className: 'keyword',
22 begin: '<',
23 end: '>',
24 contains: [
25 builtInTypeMode,
26 objectHandleMode
27 ]
28 };
29
30 builtInTypeMode.contains = [ genericMode ];
31 objectHandleMode.contains = [ genericMode ];
32
33 const KEYWORDS = [
34 "for",
35 "in|0",
36 "break",
37 "continue",
38 "while",
39 "do|0",
40 "return",
41 "if",
42 "else",
43 "case",
44 "switch",
45 "namespace",
46 "is",
47 "cast",
48 "or",
49 "and",
50 "xor",
51 "not",
52 "get|0",
53 "in",
54 "inout|10",
55 "out",
56 "override",
57 "set|0",
58 "private",
59 "public",
60 "const",
61 "default|0",
62 "final",
63 "shared",
64 "external",
65 "mixin|10",
66 "enum",
67 "typedef",
68 "funcdef",
69 "this",
70 "super",
71 "import",
72 "from",
73 "interface",
74 "abstract|0",
75 "try",
76 "catch",
77 "protected",
78 "explicit",
79 "property"
80 ];
81
82 return {
83 name: 'AngelScript',
84 aliases: [ 'asc' ],
85
86 keywords: KEYWORDS,
87
88 // avoid close detection with C# and JS
89 illegal: '(^using\\s+[A-Za-z0-9_\\.]+;$|\\bfunction\\s*[^\\(])',
90
91 contains: [
92 { // 'strings'
93 className: 'string',
94 begin: '\'',
95 end: '\'',
96 illegal: '\\n',
97 contains: [ hljs.BACKSLASH_ESCAPE ],
98 relevance: 0
99 },
100
101 // """heredoc strings"""
102 {
103 className: 'string',
104 begin: '"""',
105 end: '"""'
106 },
107
108 { // "strings"
109 className: 'string',
110 begin: '"',
111 end: '"',
112 illegal: '\\n',
113 contains: [ hljs.BACKSLASH_ESCAPE ],
114 relevance: 0
115 },
116
117 hljs.C_LINE_COMMENT_MODE, // single-line comments
118 hljs.C_BLOCK_COMMENT_MODE, // comment blocks
119
120 { // metadata
121 className: 'string',
122 begin: '^\\s*\\[',
123 end: '\\]'
124 },
125
126 { // interface or namespace declaration
127 beginKeywords: 'interface namespace',
128 end: /\{/,
129 illegal: '[;.\\-]',
130 contains: [
131 { // interface or namespace name
132 className: 'symbol',
133 begin: '[a-zA-Z0-9_]+'
134 }
135 ]
136 },
137
138 { // class declaration
139 beginKeywords: 'class',
140 end: /\{/,
141 illegal: '[;.\\-]',
142 contains: [
143 { // class name
144 className: 'symbol',
145 begin: '[a-zA-Z0-9_]+',
146 contains: [
147 {
148 begin: '[:,]\\s*',
149 contains: [
150 {
151 className: 'symbol',
152 begin: '[a-zA-Z0-9_]+'
153 }
154 ]
155 }
156 ]
157 }
158 ]
159 },
160
161 builtInTypeMode, // built-in types
162 objectHandleMode, // object handles
163
164 { // literals
165 className: 'literal',
166 begin: '\\b(null|true|false)'
167 },
168
169 { // numbers
170 className: 'number',
171 relevance: 0,
172 begin: '(-?)(\\b0[xXbBoOdD][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?f?|\\.\\d+f?)([eE][-+]?\\d+f?)?)'
173 }
174 ]
175 };
176}
177
178module.exports = angelscript;