-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmonaco-saz.js
176 lines (158 loc) · 4.76 KB
/
monaco-saz.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
function sazTokensProvider() {
// Difficulty: "Easy"
// Language definition for Java
return {
// Set defaultToken to invalid to see what you do not tokenize yet
// defaultToken: 'invalid',
keywords: [
'ali', 'başqa', 'doğru', 'heç', 'işləv', 'nəqədərki', 'qaytar', 'sinif', 'və', 'vəya',
'yanlış', 'yerli', 'üçün', 'əgər'
],
typeKeywords: [
'boolean', 'double', 'byte', 'int', 'short', 'char', 'void', 'long', 'float'
],
operators: [
'=', '>', '<', '!', '~', '?', ':',
'==', '<=', '>=', '!=', '&&', '||', '++', '--',
'+', '-', '*', '/', '&', '|', '^', '%', '<<',
'>>', '>>>', '+=', '-=', '*=', '/=', '&=', '|=',
'^=', '%=', '<<=', '>>=', '>>>='
],
// we include these common regular expressions
symbols: /[=><!~?:&|+\-*\/\^%]+/,
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: [
// identifiers and keywords
[/([a-z_$]|[^\x00-\x7F])([\w$]|[^\x00-\x7F])*/, { cases: { '@typeKeywords': 'keyword',
'@keywords': 'keyword',
'@default': 'identifier' } }],
[/[A-Z]([\w\$]|[^\x00-\x7F])*/, 'type.identifier' ], // to show class names nicely
// whitespace
{ include: '@whitespace' },
// delimiters and operators
[/[{}()\[\]]/, '@brackets'],
[/[<>](?!@symbols)/, '@brackets'],
[/@symbols/, { cases: { '@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+)?[fFdD]?/, 'number.float'],
[/0[xX][0-9a-fA-F_]*[0-9a-fA-F][Ll]?/, 'number.hex'],
[/0[0-7_]*[0-7][Ll]?/, 'number.octal'],
[/0[bB][0-1_]*[0-1][Ll]?/, 'number.binary'],
[/\d+[lL]?/, 'number'],
// delimiter: after number because of .\d floats
[/[;,.]/, 'delimiter'],
// strings
[/"([^"\\]|\\.)*$/, 'string.invalid' ], // non-teminated string
[/"/, 'string', '@string' ],
// characters
[/'[^\\']'/, 'string'],
[/(')(@escapes)(')/, ['string','string.escape','string']],
[/'/, 'string.invalid']
],
whitespace: [
[/[ \t\r\n]+/, 'white'],
[/\/\*/, 'comment', '@comment' ],
[/\/\/.*$/, 'comment'],
],
comment: [
[/[^\/*]+/, 'comment' ],
// [/\/\*/, 'comment', '@push' ], // nested comment not allowed :-(
[/\/\*/, 'comment.invalid' ],
["\\*/", 'comment', '@pop' ],
[/[\/*]/, 'comment' ]
],
string: [
[/[^\\"]+/, 'string'],
[/@escapes/, 'string.escape'],
[/\\./, 'string.escape.invalid'],
[/"/, 'string', '@pop' ]
],
},
};
}
function sazCompletionProvider()
{
return {
provideCompletionItems: () => {
return [
{
label: 'əgərbaşqa',
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: {
value: [
'əgər (${1:şərt}) {',
'\t$0',
'} başqa {',
'\t',
'}'
].join('\n')
}
},
{
label: 'əgər',
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: {
value: [
'əgər (${1:doğru}) {',
'\t${0:// gövdə...}',
'}'
].join('\n')
}
},
{
label: 'işləv',
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: {
value: [
'işləv ${1:ad}(${2:arqument}) {',
'\t${0:// gövdə...}',
'}'
].join('\n')
}
},
{
label: 'nəqədərki',
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: {
value: [
'nəqədərki (${1:doğru}) {',
'\t${0:// gövdə...}',
'}'
].join('\n')
}
},
{
label: 'üçün',
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: {
value: [
'üçün (yerli ${1:i} = 0; ${1:i} < ${2:10}; ${1:i}++) {',
'\t${0:// gövdə...}',
'}'
].join('\n')
}
},
{
label: 'sinif',
kind: monaco.languages.CompletionItemKind.Snippet,
insertText: {
value: [
'sinif ${1:A}${2: < ${3:B}} {',
'\tqurucu(${4:arg}) {',
'\t\t${0}',
'\t}',
'}'
].join('\n')
}
}
]
}
}
}