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