corrade-nucleus-nucleons – Blame information for rev 20
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
20 | office | 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 "comment"; |
||
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 "comment"; |
||
113 | }, |
||
114 | |||
115 | regex : /\]=*\]/, |
||
116 | next : "start" |
||
117 | }, { |
||
118 | defaultToken : "comment" |
||
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) { |
||
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 | var row = stream.getCurrentTokenRow(); |
||
284 | if (dir === -1) |
||
285 | return new Range(row, session.getLine(row).length, startRow, startColumn); |
||
286 | else |
||
287 | return new Range(startRow, startColumn, row, stream.getCurrentTokenColumn()); |
||
288 | }; |
||
289 | |||
290 | }).call(FoldMode.prototype); |
||
291 | |||
292 | }); |
||
293 | |||
294 | 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) { |
||
295 | "use strict"; |
||
296 | |||
297 | var oop = require("../lib/oop"); |
||
298 | var TextMode = require("./text").Mode; |
||
299 | var LuaHighlightRules = require("./lua_highlight_rules").LuaHighlightRules; |
||
300 | var LuaFoldMode = require("./folding/lua").FoldMode; |
||
301 | var Range = require("../range").Range; |
||
302 | var WorkerClient = require("../worker/worker_client").WorkerClient; |
||
303 | |||
304 | var Mode = function() { |
||
305 | this.HighlightRules = LuaHighlightRules; |
||
306 | |||
307 | this.foldingRules = new LuaFoldMode(); |
||
308 | this.$behaviour = this.$defaultBehaviour; |
||
309 | }; |
||
310 | oop.inherits(Mode, TextMode); |
||
311 | |||
312 | (function() { |
||
313 | |||
314 | this.lineCommentStart = "--"; |
||
315 | this.blockComment = {start: "--[", end: "]--"}; |
||
316 | |||
317 | var indentKeywords = { |
||
318 | "function": 1, |
||
319 | "then": 1, |
||
320 | "do": 1, |
||
321 | "else": 1, |
||
322 | "elseif": 1, |
||
323 | "repeat": 1, |
||
324 | "end": -1, |
||
325 | "until": -1 |
||
326 | }; |
||
327 | var outdentKeywords = [ |
||
328 | "else", |
||
329 | "elseif", |
||
330 | "end", |
||
331 | "until" |
||
332 | ]; |
||
333 | |||
334 | function getNetIndentLevel(tokens) { |
||
335 | var level = 0; |
||
336 | for (var i = 0; i < tokens.length; i++) { |
||
337 | var token = tokens[i]; |
||
338 | if (token.type == "keyword") { |
||
339 | if (token.value in indentKeywords) { |
||
340 | level += indentKeywords[token.value]; |
||
341 | } |
||
342 | } else if (token.type == "paren.lparen") { |
||
343 | level += token.value.length; |
||
344 | } else if (token.type == "paren.rparen") { |
||
345 | level -= token.value.length; |
||
346 | } |
||
347 | } |
||
348 | if (level < 0) { |
||
349 | return -1; |
||
350 | } else if (level > 0) { |
||
351 | return 1; |
||
352 | } else { |
||
353 | return 0; |
||
354 | } |
||
355 | } |
||
356 | |||
357 | this.getNextLineIndent = function(state, line, tab) { |
||
358 | var indent = this.$getIndent(line); |
||
359 | var level = 0; |
||
360 | |||
361 | var tokenizedLine = this.getTokenizer().getLineTokens(line, state); |
||
362 | var tokens = tokenizedLine.tokens; |
||
363 | |||
364 | if (state == "start") { |
||
365 | level = getNetIndentLevel(tokens); |
||
366 | } |
||
367 | if (level > 0) { |
||
368 | return indent + tab; |
||
369 | } else if (level < 0 && indent.substr(indent.length - tab.length) == tab) { |
||
370 | if (!this.checkOutdent(state, line, "\n")) { |
||
371 | return indent.substr(0, indent.length - tab.length); |
||
372 | } |
||
373 | } |
||
374 | return indent; |
||
375 | }; |
||
376 | |||
377 | this.checkOutdent = function(state, line, input) { |
||
378 | if (input != "\n" && input != "\r" && input != "\r\n") |
||
379 | return false; |
||
380 | |||
381 | if (line.match(/^\s*[\)\}\]]$/)) |
||
382 | return true; |
||
383 | |||
384 | var tokens = this.getTokenizer().getLineTokens(line.trim(), state).tokens; |
||
385 | |||
386 | if (!tokens || !tokens.length) |
||
387 | return false; |
||
388 | |||
389 | return (tokens[0].type == "keyword" && outdentKeywords.indexOf(tokens[0].value) != -1); |
||
390 | }; |
||
391 | |||
392 | this.autoOutdent = function(state, session, row) { |
||
393 | var prevLine = session.getLine(row - 1); |
||
394 | var prevIndent = this.$getIndent(prevLine).length; |
||
395 | var prevTokens = this.getTokenizer().getLineTokens(prevLine, "start").tokens; |
||
396 | var tabLength = session.getTabString().length; |
||
397 | var expectedIndent = prevIndent + tabLength * getNetIndentLevel(prevTokens); |
||
398 | var curIndent = this.$getIndent(session.getLine(row)).length; |
||
399 | if (curIndent < expectedIndent) { |
||
400 | return; |
||
401 | } |
||
402 | session.outdentRows(new Range(row, 0, row + 2, 0)); |
||
403 | }; |
||
404 | |||
405 | this.createWorker = function(session) { |
||
406 | var worker = new WorkerClient(["ace"], "ace/mode/lua_worker", "Worker"); |
||
407 | worker.attachToDocument(session.getDocument()); |
||
408 | |||
409 | worker.on("annotate", function(e) { |
||
410 | session.setAnnotations(e.data); |
||
411 | }); |
||
412 | |||
413 | worker.on("terminate", function() { |
||
414 | session.clearAnnotations(); |
||
415 | }); |
||
416 | |||
417 | return worker; |
||
418 | }; |
||
419 | |||
420 | this.$id = "ace/mode/lua"; |
||
421 | }).call(Mode.prototype); |
||
422 | |||
423 | exports.Mode = Mode; |
||
424 | }); |