1
|
ace.define("ace/mode/lua_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
|
2
|
"use strict";
|
3
|
|
4
|
var oop = require("../lib/oop");
|
5
|
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
6
|
|
7
|
var LuaHighlightRules = function() {
|
8
|
|
9
|
var keywords = (
|
10
|
"break|do|else|elseif|end|for|function|if|in|local|repeat|"+
|
11
|
"return|then|until|while|or|and|not"
|
12
|
);
|
13
|
|
14
|
var builtinConstants = ("true|false|nil|_G|_VERSION");
|
15
|
|
16
|
var functions = (
|
17
|
"string|xpcall|package|tostring|print|os|unpack|require|"+
|
18
|
"getfenv|setmetatable|next|assert|tonumber|io|rawequal|"+
|
19
|
"collectgarbage|getmetatable|module|rawset|math|debug|"+
|
20
|
"pcall|table|newproxy|type|coroutine|_G|select|gcinfo|"+
|
21
|
"pairs|rawget|loadstring|ipairs|_VERSION|dofile|setfenv|"+
|
22
|
"load|error|loadfile|"+
|
23
|
|
24
|
"sub|upper|len|gfind|rep|find|match|char|dump|gmatch|"+
|
25
|
"reverse|byte|format|gsub|lower|preload|loadlib|loaded|"+
|
26
|
"loaders|cpath|config|path|seeall|exit|setlocale|date|"+
|
27
|
"getenv|difftime|remove|time|clock|tmpname|rename|execute|"+
|
28
|
"lines|write|close|flush|open|output|type|read|stderr|"+
|
29
|
"stdin|input|stdout|popen|tmpfile|log|max|acos|huge|"+
|
30
|
"ldexp|pi|cos|tanh|pow|deg|tan|cosh|sinh|random|randomseed|"+
|
31
|
"frexp|ceil|floor|rad|abs|sqrt|modf|asin|min|mod|fmod|log10|"+
|
32
|
"atan2|exp|sin|atan|getupvalue|debug|sethook|getmetatable|"+
|
33
|
"gethook|setmetatable|setlocal|traceback|setfenv|getinfo|"+
|
34
|
"setupvalue|getlocal|getregistry|getfenv|setn|insert|getn|"+
|
35
|
"foreachi|maxn|foreach|concat|sort|remove|resume|yield|"+
|
36
|
"status|wrap|create|running|"+
|
37
|
"__add|__sub|__mod|__unm|__concat|__lt|__index|__call|__gc|__metatable|"+
|
38
|
"__mul|__div|__pow|__len|__eq|__le|__newindex|__tostring|__mode|__tonumber"
|
39
|
);
|
40
|
|
41
|
var stdLibaries = ("string|package|os|io|math|debug|table|coroutine");
|
42
|
|
43
|
var deprecatedIn5152 = ("setn|foreach|foreachi|gcinfo|log10|maxn");
|
44
|
|
45
|
var keywordMapper = this.createKeywordMapper({
|
46
|
"keyword": keywords,
|
47
|
"support.function": functions,
|
48
|
"keyword.deprecated": deprecatedIn5152,
|
49
|
"constant.library": stdLibaries,
|
50
|
"constant.language": builtinConstants,
|
51
|
"variable.language": "self"
|
52
|
}, "identifier");
|
53
|
|
54
|
var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))";
|
55
|
var hexInteger = "(?:0[xX][\\dA-Fa-f]+)";
|
56
|
var integer = "(?:" + decimalInteger + "|" + hexInteger + ")";
|
57
|
|
58
|
var fraction = "(?:\\.\\d+)";
|
59
|
var intPart = "(?:\\d+)";
|
60
|
var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))";
|
61
|
var floatNumber = "(?:" + pointFloat + ")";
|
62
|
|
63
|
this.$rules = {
|
64
|
"start" : [{
|
65
|
stateName: "bracketedComment",
|
66
|
onMatch : function(value, currentState, stack){
|
67
|
stack.unshift(this.next, value.length - 2, currentState);
|
68
|
return "comment";
|
69
|
},
|
70
|
regex : /\-\-\[=*\[/,
|
71
|
next : [
|
72
|
{
|
73
|
onMatch : function(value, currentState, stack) {
|
74
|
if (value.length == stack[1]) {
|
75
|
stack.shift();
|
76
|
stack.shift();
|
77
|
this.next = stack.shift();
|
78
|
} else {
|
79
|
this.next = "";
|
80
|
}
|
81
|
return "comment";
|
82
|
},
|
83
|
regex : /\]=*\]/,
|
84
|
next : "start"
|
85
|
}, {
|
86
|
defaultToken : "comment"
|
87
|
}
|
88
|
]
|
89
|
},
|
90
|
|
91
|
{
|
92
|
token : "comment",
|
93
|
regex : "\\-\\-.*$"
|
94
|
},
|
95
|
{
|
96
|
stateName: "bracketedString",
|
97
|
onMatch : function(value, currentState, stack){
|
98
|
stack.unshift(this.next, value.length, currentState);
|
99
|
return "string.start";
|
100
|
},
|
101
|
regex : /\[=*\[/,
|
102
|
next : [
|
103
|
{
|
104
|
onMatch : function(value, currentState, stack) {
|
105
|
if (value.length == stack[1]) {
|
106
|
stack.shift();
|
107
|
stack.shift();
|
108
|
this.next = stack.shift();
|
109
|
} else {
|
110
|
this.next = "";
|
111
|
}
|
112
|
return "string.end";
|
113
|
},
|
114
|
|
115
|
regex : /\]=*\]/,
|
116
|
next : "start"
|
117
|
}, {
|
118
|
defaultToken : "string"
|
119
|
}
|
120
|
]
|
121
|
},
|
122
|
{
|
123
|
token : "string", // " string
|
124
|
regex : '"(?:[^\\\\]|\\\\.)*?"'
|
125
|
}, {
|
126
|
token : "string", // ' string
|
127
|
regex : "'(?:[^\\\\]|\\\\.)*?'"
|
128
|
}, {
|
129
|
token : "constant.numeric", // float
|
130
|
regex : floatNumber
|
131
|
}, {
|
132
|
token : "constant.numeric", // integer
|
133
|
regex : integer + "\\b"
|
134
|
}, {
|
135
|
token : keywordMapper,
|
136
|
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
|
137
|
}, {
|
138
|
token : "keyword.operator",
|
139
|
regex : "\\+|\\-|\\*|\\/|%|\\#|\\^|~|<|>|<=|=>|==|~=|=|\\:|\\.\\.\\.|\\.\\."
|
140
|
}, {
|
141
|
token : "paren.lparen",
|
142
|
regex : "[\\[\\(\\{]"
|
143
|
}, {
|
144
|
token : "paren.rparen",
|
145
|
regex : "[\\]\\)\\}]"
|
146
|
}, {
|
147
|
token : "text",
|
148
|
regex : "\\s+|\\w+"
|
149
|
} ]
|
150
|
};
|
151
|
|
152
|
this.normalizeRules();
|
153
|
};
|
154
|
|
155
|
oop.inherits(LuaHighlightRules, TextHighlightRules);
|
156
|
|
157
|
exports.LuaHighlightRules = LuaHighlightRules;
|
158
|
});
|
159
|
|
160
|
ace.define("ace/mode/folding/lua",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range","ace/token_iterator"], function(require, exports, module) {
|
161
|
"use strict";
|
162
|
|
163
|
var oop = require("../../lib/oop");
|
164
|
var BaseFoldMode = require("./fold_mode").FoldMode;
|
165
|
var Range = require("../../range").Range;
|
166
|
var TokenIterator = require("../../token_iterator").TokenIterator;
|
167
|
|
168
|
|
169
|
var FoldMode = exports.FoldMode = function() {};
|
170
|
|
171
|
oop.inherits(FoldMode, BaseFoldMode);
|
172
|
|
173
|
(function() {
|
174
|
|
175
|
this.foldingStartMarker = /\b(function|then|do|repeat)\b|{\s*$|(\[=*\[)/;
|
176
|
this.foldingStopMarker = /\bend\b|^\s*}|\]=*\]/;
|
177
|
|
178
|
this.getFoldWidget = function(session, foldStyle, row) {
|
179
|
var line = session.getLine(row);
|
180
|
var isStart = this.foldingStartMarker.test(line);
|
181
|
var isEnd = this.foldingStopMarker.test(line);
|
182
|
|
183
|
if (isStart && !isEnd) {
|
184
|
var match = line.match(this.foldingStartMarker);
|
185
|
if (match[1] == "then" && /\belseif\b/.test(line))
|
186
|
return;
|
187
|
if (match[1]) {
|
188
|
if (session.getTokenAt(row, match.index + 1).type === "keyword")
|
189
|
return "start";
|
190
|
} else if (match[2]) {
|
191
|
var type = session.bgTokenizer.getState(row) || "";
|
192
|
if (type[0] == "bracketedComment" || type[0] == "bracketedString")
|
193
|
return "start";
|
194
|
} else {
|
195
|
return "start";
|
196
|
}
|
197
|
}
|
198
|
if (foldStyle != "markbeginend" || !isEnd || isStart && isEnd)
|
199
|
return "";
|
200
|
|
201
|
var match = line.match(this.foldingStopMarker);
|
202
|
if (match[0] === "end") {
|
203
|
if (session.getTokenAt(row, match.index + 1).type === "keyword")
|
204
|
return "end";
|
205
|
} else if (match[0][0] === "]") {
|
206
|
var type = session.bgTokenizer.getState(row - 1) || "";
|
207
|
if (type[0] == "bracketedComment" || type[0] == "bracketedString")
|
208
|
return "end";
|
209
|
} else
|
210
|
return "end";
|
211
|
};
|
212
|
|
213
|
this.getFoldWidgetRange = function(session, foldStyle, row) {
|
214
|
var line = session.doc.getLine(row);
|
215
|
var match = this.foldingStartMarker.exec(line);
|
216
|
if (match) {
|
217
|
if (match[1])
|
218
|
return this.luaBlock(session, row, match.index + 1);
|
219
|
|
220
|
if (match[2])
|
221
|
return session.getCommentFoldRange(row, match.index + 1);
|
222
|
|
223
|
return this.openingBracketBlock(session, "{", row, match.index);
|
224
|
}
|
225
|
|
226
|
var match = this.foldingStopMarker.exec(line);
|
227
|
if (match) {
|
228
|
if (match[0] === "end") {
|
229
|
if (session.getTokenAt(row, match.index + 1).type === "keyword")
|
230
|
return this.luaBlock(session, row, match.index + 1);
|
231
|
}
|
232
|
|
233
|
if (match[0][0] === "]")
|
234
|
return session.getCommentFoldRange(row, match.index + 1);
|
235
|
|
236
|
return this.closingBracketBlock(session, "}", row, match.index + match[0].length);
|
237
|
}
|
238
|
};
|
239
|
|
240
|
this.luaBlock = function(session, row, column, tokenRange) {
|
241
|
var stream = new TokenIterator(session, row, column);
|
242
|
var indentKeywords = {
|
243
|
"function": 1,
|
244
|
"do": 1,
|
245
|
"then": 1,
|
246
|
"elseif": -1,
|
247
|
"end": -1,
|
248
|
"repeat": 1,
|
249
|
"until": -1
|
250
|
};
|
251
|
|
252
|
var token = stream.getCurrentToken();
|
253
|
if (!token || token.type != "keyword")
|
254
|
return;
|
255
|
|
256
|
var val = token.value;
|
257
|
var stack = [val];
|
258
|
var dir = indentKeywords[val];
|
259
|
|
260
|
if (!dir)
|
261
|
return;
|
262
|
|
263
|
var startColumn = dir === -1 ? stream.getCurrentTokenColumn() : session.getLine(row).length;
|
264
|
var startRow = row;
|
265
|
|
266
|
stream.step = dir === -1 ? stream.stepBackward : stream.stepForward;
|
267
|
while(token = stream.step()) {
|
268
|
if (token.type !== "keyword")
|
269
|
continue;
|
270
|
var level = dir * indentKeywords[token.value];
|
271
|
|
272
|
if (level > 0) {
|
273
|
stack.unshift(token.value);
|
274
|
} else if (level <= 0) {
|
275
|
stack.shift();
|
276
|
if (!stack.length && token.value != "elseif")
|
277
|
break;
|
278
|
if (level === 0)
|
279
|
stack.unshift(token.value);
|
280
|
}
|
281
|
}
|
282
|
|
283
|
if (!token)
|
284
|
return null;
|
285
|
|
286
|
if (tokenRange)
|
287
|
return stream.getCurrentTokenRange();
|
288
|
|
289
|
var row = stream.getCurrentTokenRow();
|
290
|
if (dir === -1)
|
291
|
return new Range(row, session.getLine(row).length, startRow, startColumn);
|
292
|
else
|
293
|
return new Range(startRow, startColumn, row, stream.getCurrentTokenColumn());
|
294
|
};
|
295
|
|
296
|
}).call(FoldMode.prototype);
|
297
|
|
298
|
});
|
299
|
|
300
|
ace.define("ace/mode/lua",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/lua_highlight_rules","ace/mode/folding/lua","ace/range","ace/worker/worker_client"], function(require, exports, module) {
|
301
|
"use strict";
|
302
|
|
303
|
var oop = require("../lib/oop");
|
304
|
var TextMode = require("./text").Mode;
|
305
|
var LuaHighlightRules = require("./lua_highlight_rules").LuaHighlightRules;
|
306
|
var LuaFoldMode = require("./folding/lua").FoldMode;
|
307
|
var Range = require("../range").Range;
|
308
|
var WorkerClient = require("../worker/worker_client").WorkerClient;
|
309
|
|
310
|
var Mode = function() {
|
311
|
this.HighlightRules = LuaHighlightRules;
|
312
|
|
313
|
this.foldingRules = new LuaFoldMode();
|
314
|
this.$behaviour = this.$defaultBehaviour;
|
315
|
};
|
316
|
oop.inherits(Mode, TextMode);
|
317
|
|
318
|
(function() {
|
319
|
|
320
|
this.lineCommentStart = "--";
|
321
|
this.blockComment = {start: "--[", end: "]--"};
|
322
|
|
323
|
var indentKeywords = {
|
324
|
"function": 1,
|
325
|
"then": 1,
|
326
|
"do": 1,
|
327
|
"else": 1,
|
328
|
"elseif": 1,
|
329
|
"repeat": 1,
|
330
|
"end": -1,
|
331
|
"until": -1
|
332
|
};
|
333
|
var outdentKeywords = [
|
334
|
"else",
|
335
|
"elseif",
|
336
|
"end",
|
337
|
"until"
|
338
|
];
|
339
|
|
340
|
function getNetIndentLevel(tokens) {
|
341
|
var level = 0;
|
342
|
for (var i = 0; i < tokens.length; i++) {
|
343
|
var token = tokens[i];
|
344
|
if (token.type == "keyword") {
|
345
|
if (token.value in indentKeywords) {
|
346
|
level += indentKeywords[token.value];
|
347
|
}
|
348
|
} else if (token.type == "paren.lparen") {
|
349
|
level += token.value.length;
|
350
|
} else if (token.type == "paren.rparen") {
|
351
|
level -= token.value.length;
|
352
|
}
|
353
|
}
|
354
|
if (level < 0) {
|
355
|
return -1;
|
356
|
} else if (level > 0) {
|
357
|
return 1;
|
358
|
} else {
|
359
|
return 0;
|
360
|
}
|
361
|
}
|
362
|
|
363
|
this.getNextLineIndent = function(state, line, tab) {
|
364
|
var indent = this.$getIndent(line);
|
365
|
var level = 0;
|
366
|
|
367
|
var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
|
368
|
var tokens = tokenizedLine.tokens;
|
369
|
|
370
|
if (state == "start") {
|
371
|
level = getNetIndentLevel(tokens);
|
372
|
}
|
373
|
if (level > 0) {
|
374
|
return indent + tab;
|
375
|
} else if (level < 0 && indent.substr(indent.length - tab.length) == tab) {
|
376
|
if (!this.checkOutdent(state, line, "\n")) {
|
377
|
return indent.substr(0, indent.length - tab.length);
|
378
|
}
|
379
|
}
|
380
|
return indent;
|
381
|
};
|
382
|
|
383
|
this.checkOutdent = function(state, line, input) {
|
384
|
if (input != "\n" && input != "\r" && input != "\r\n")
|
385
|
return false;
|
386
|
|
387
|
if (line.match(/^\s*[\)\}\]]$/))
|
388
|
return true;
|
389
|
|
390
|
var tokens = this.getTokenizer().getLineTokens(line.trim(), state).tokens;
|
391
|
|
392
|
if (!tokens || !tokens.length)
|
393
|
return false;
|
394
|
|
395
|
return (tokens[0].type == "keyword" && outdentKeywords.indexOf(tokens[0].value) != -1);
|
396
|
};
|
397
|
|
398
|
this.getMatching = function(session, row, column) {
|
399
|
if (row == undefined) {
|
400
|
var pos = session.selection.lead;
|
401
|
column = pos.column;
|
402
|
row = pos.row;
|
403
|
}
|
404
|
|
405
|
var startToken = session.getTokenAt(row, column);
|
406
|
if (startToken && startToken.value in indentKeywords)
|
407
|
return this.foldingRules.luaBlock(session, row, column, true);
|
408
|
};
|
409
|
|
410
|
this.autoOutdent = function(state, session, row) {
|
411
|
var line = session.getLine(row);
|
412
|
var column = line.match(/^\s*/)[0].length;
|
413
|
if (!column || !row) return;
|
414
|
|
415
|
var startRange = this.getMatching(session, row, column + 1);
|
416
|
if (!startRange || startRange.start.row == row)
|
417
|
return;
|
418
|
var indent = this.$getIndent(session.getLine(startRange.start.row));
|
419
|
if (indent.length != column) {
|
420
|
session.replace(new Range(row, 0, row, column), indent);
|
421
|
session.outdentRows(new Range(row + 1, 0, row + 1, 0));
|
422
|
}
|
423
|
};
|
424
|
|
425
|
this.createWorker = function(session) {
|
426
|
var worker = new WorkerClient(["ace"], "ace/mode/lua_worker", "Worker");
|
427
|
worker.attachToDocument(session.getDocument());
|
428
|
|
429
|
worker.on("annotate", function(e) {
|
430
|
session.setAnnotations(e.data);
|
431
|
});
|
432
|
|
433
|
worker.on("terminate", function() {
|
434
|
session.clearAnnotations();
|
435
|
});
|
436
|
|
437
|
return worker;
|
438
|
};
|
439
|
|
440
|
this.$id = "ace/mode/lua";
|
441
|
this.snippetFileId = "ace/snippets/lua";
|
442
|
}).call(Mode.prototype);
|
443
|
|
444
|
exports.Mode = Mode;
|
445
|
}); (function() {
|
446
|
ace.require(["ace/mode/lua"], function(m) {
|
447
|
if (typeof module == "object" && typeof exports == "object" && module) {
|
448
|
module.exports = m;
|
449
|
}
|
450
|
});
|
451
|
})();
|
452
|
|