-
Notifications
You must be signed in to change notification settings - Fork 0
/
syntax.js
109 lines (88 loc) · 3.74 KB
/
syntax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const syntax = {
defaultToken: 'invalid',
keywords: [
'proc', 'func', 'val', 'this',
'or', 'match', 'case',
'let', 'where', 'return', 'goto',
'if', 'then', 'else', 'do', 'call', 'continue',
'import', 'as', 'use', 'set', 'for',
'module', 'interface', 'inherit',
'infix', 'record', 'type', 'repeat'
],
typeKeywords: [
'bool', 'byte', 'i8', 'i16', 'i32', 'i64', 'u8', 'u16', 'u32', 'u64', 'char', 'void', 'f32', 'f64'
],
operators: [
'=', '>', '<', '!', '~', '?', ':', '==', '<=', '>=', '!=',
'&&', '||', '++', '--', '+', '-', '*', '/', '&', '|', '^', '%',
'<<', '>>', '>>>', '+=', '-=', '*=', '/=', '&=', '|=', '^=',
'%=', '<<=', '>>=', '>>>=', '=>', '<-'
],
keyOperators: [
'|>'
],
// we include these common regular expressions
symbols: /[=><!~?:&|+\-*\/\^%]+/,
// C# style strings
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
// The main tokenizer for our languages
tokenizer: {
root: [
// function and procedure definitions
[/(func\s+|proc\s+|val\s+)([a-z_][\w$]*)(\.)([a-z_][\w$]*)/, ['keyword', 'identifier', 'operator', 'definition' ] ],
[/(func\s+|proc\s+|val\s+)([a-z_][\w$]*)/, ['keyword', 'definition' ] ],
// labels
[/[a-z_$][\w$]*:/, 'label'],
// identifiers and keywords
[/[a-z_$][\w$]*(?=\()/, { cases: { '@typeKeywords': 'type.identifier',
'@keywords': 'keyword',
'@default': 'function.identifier' } } ],
[/[a-z_$][\w$]*/, { cases: { '@typeKeywords': 'type.identifier',
'@keywords': 'keyword',
'@default': 'identifier' } } ],
[/[A-Z][\w$]*/, 'type.identifier' ], // to show class names nicely
// whitespace
{ include: '@whitespace' },
// delimiters and operators
[/[{}()\[\]]/, '@brackets'],
[/[<>](?!@symbols)/, '@brackets'],
[/@symbols/, { cases: { '@keyOperators': 'keyword',
'@operators': 'operator',
'@default' : '' } } ],
// @ annotations.
// As an example, we emit a debugging log message on these tokens.
// Note: message are supressed during the first load -- change some lines to see them.
[/@\s*[a-zA-Z_\$][\w\$]*/, { token: 'annotation', log: 'annotation token: $0' }],
// numbers
[/\d*\.\d+([eE][\-+]?\d+)?/, 'number.float'],
[/0[xX][0-9a-fA-F]+/, 'number.hex'],
[/\d+/, 'number'],
// delimiter: after number because of .\d floats
[/[;,.]/, 'delimiter'],
// strings
[/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string
[/"/, { token: 'string.quote', bracket: '@open', next: '@string' } ],
// characters
[/'[^\\']'/, 'string'],
[/(')(@escapes)(')/, ['string','string.escape','string']],
[/'/, 'string.invalid']
],
comment: [
[/[^\/*]+/, 'comment' ],
[/\/\*/, 'comment', '@push' ], // nested comment
["\\*/", 'comment', '@pop' ],
[/[\/*]/, 'comment' ]
],
string: [
[/[^\\"]+/, 'string'],
[/@escapes/, 'string.escape'],
[/\\./, 'string.escape.invalid'],
[/"/, { token: 'string.quote', bracket: '@close', next: '@pop' } ]
],
whitespace: [
[/[ \t\r\n]+/, 'white'],
[/\/\*/, 'comment', '@comment' ],
[/\/\/.*$/, 'comment'],
],
},
}