| 1 |
ace.define("ace/mode/python_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){ |
| 2 |
|
| 3 |
|
| 4 |
"use strict"; |
| 5 |
var oop = require("../lib/oop"); |
| 6 |
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; |
| 7 |
var PythonHighlightRules = function () { |
| 8 |
var keywords = ("and|as|assert|break|class|continue|def|del|elif|else|except|exec|" + |
| 9 |
"finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|" + |
| 10 |
"raise|return|try|while|with|yield|async|await|nonlocal"); |
| 11 |
var builtinConstants = ("True|False|None|NotImplemented|Ellipsis|__debug__"); |
| 12 |
var builtinFunctions = ("abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|" + |
| 13 |
"eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|" + |
| 14 |
"binfile|bin|iter|property|tuple|bool|filter|len|range|type|bytearray|" + |
| 15 |
"float|list|raw_input|unichr|callable|format|locals|reduce|unicode|" + |
| 16 |
"chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|" + |
| 17 |
"cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|" + |
| 18 |
"__import__|complex|hash|min|apply|delattr|help|next|setattr|set|" + |
| 19 |
"buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern|" + |
| 20 |
"ascii|breakpoint|bytes"); |
| 21 |
var keywordMapper = this.createKeywordMapper({ |
| 22 |
"invalid.deprecated": "debugger", |
| 23 |
"support.function": builtinFunctions, |
| 24 |
"variable.language": "self|cls", |
| 25 |
"constant.language": builtinConstants, |
| 26 |
"keyword": keywords |
| 27 |
}, "identifier"); |
| 28 |
var strPre = "[uU]?"; |
| 29 |
var strRawPre = "[rR]"; |
| 30 |
var strFormatPre = "[fF]"; |
| 31 |
var strRawFormatPre = "(?:[rR][fF]|[fF][rR])"; |
| 32 |
var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))"; |
| 33 |
var octInteger = "(?:0[oO]?[0-7]+)"; |
| 34 |
var hexInteger = "(?:0[xX][\\dA-Fa-f]+)"; |
| 35 |
var binInteger = "(?:0[bB][01]+)"; |
| 36 |
var integer = "(?:" + decimalInteger + "|" + octInteger + "|" + hexInteger + "|" + binInteger + ")"; |
| 37 |
var exponent = "(?:[eE][+-]?\\d+)"; |
| 38 |
var fraction = "(?:\\.\\d+)"; |
| 39 |
var intPart = "(?:\\d+)"; |
| 40 |
var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))"; |
| 41 |
var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + exponent + ")"; |
| 42 |
var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")"; |
| 43 |
var stringEscape = "\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})"; |
| 44 |
this.$rules = { |
| 45 |
"start": [{ |
| 46 |
token: "comment", |
| 47 |
regex: "#.*$" |
| 48 |
}, { |
| 49 |
token: "string", |
| 50 |
regex: strPre + '"{3}', |
| 51 |
next: "qqstring3" |
| 52 |
}, { |
| 53 |
token: "string", |
| 54 |
regex: strPre + '"(?=.)', |
| 55 |
next: "qqstring" |
| 56 |
}, { |
| 57 |
token: "string", |
| 58 |
regex: strPre + "'{3}", |
| 59 |
next: "qstring3" |
| 60 |
}, { |
| 61 |
token: "string", |
| 62 |
regex: strPre + "'(?=.)", |
| 63 |
next: "qstring" |
| 64 |
}, { |
| 65 |
token: "string", |
| 66 |
regex: strRawPre + '"{3}', |
| 67 |
next: "rawqqstring3" |
| 68 |
}, { |
| 69 |
token: "string", |
| 70 |
regex: strRawPre + '"(?=.)', |
| 71 |
next: "rawqqstring" |
| 72 |
}, { |
| 73 |
token: "string", |
| 74 |
regex: strRawPre + "'{3}", |
| 75 |
next: "rawqstring3" |
| 76 |
}, { |
| 77 |
token: "string", |
| 78 |
regex: strRawPre + "'(?=.)", |
| 79 |
next: "rawqstring" |
| 80 |
}, { |
| 81 |
token: "string", |
| 82 |
regex: strFormatPre + '"{3}', |
| 83 |
next: "fqqstring3" |
| 84 |
}, { |
| 85 |
token: "string", |
| 86 |
regex: strFormatPre + '"(?=.)', |
| 87 |
next: "fqqstring" |
| 88 |
}, { |
| 89 |
token: "string", |
| 90 |
regex: strFormatPre + "'{3}", |
| 91 |
next: "fqstring3" |
| 92 |
}, { |
| 93 |
token: "string", |
| 94 |
regex: strFormatPre + "'(?=.)", |
| 95 |
next: "fqstring" |
| 96 |
}, { |
| 97 |
token: "string", |
| 98 |
regex: strRawFormatPre + '"{3}', |
| 99 |
next: "rfqqstring3" |
| 100 |
}, { |
| 101 |
token: "string", |
| 102 |
regex: strRawFormatPre + '"(?=.)', |
| 103 |
next: "rfqqstring" |
| 104 |
}, { |
| 105 |
token: "string", |
| 106 |
regex: strRawFormatPre + "'{3}", |
| 107 |
next: "rfqstring3" |
| 108 |
}, { |
| 109 |
token: "string", |
| 110 |
regex: strRawFormatPre + "'(?=.)", |
| 111 |
next: "rfqstring" |
| 112 |
}, { |
| 113 |
token: "keyword.operator", |
| 114 |
regex: "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|@|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|=" |
| 115 |
}, { |
| 116 |
token: "punctuation", |
| 117 |
regex: ",|:|;|\\->|\\+=|\\-=|\\*=|\\/=|\\/\\/=|%=|@=|&=|\\|=|^=|>>=|<<=|\\*\\*=" |
| 118 |
}, { |
| 119 |
token: "paren.lparen", |
| 120 |
regex: "[\\[\\(\\{]" |
| 121 |
}, { |
| 122 |
token: "paren.rparen", |
| 123 |
regex: "[\\]\\)\\}]" |
| 124 |
}, { |
| 125 |
token: ["keyword", "text", "entity.name.function"], |
| 126 |
regex: "(def|class)(\\s+)([\\u00BF-\\u1FFF\\u2C00-\\uD7FF\\w]+)" |
| 127 |
}, { |
| 128 |
token: "text", |
| 129 |
regex: "\\s+" |
| 130 |
}, { |
| 131 |
include: "constants" |
| 132 |
}], |
| 133 |
"qqstring3": [{ |
| 134 |
token: "constant.language.escape", |
| 135 |
regex: stringEscape |
| 136 |
}, { |
| 137 |
token: "string", |
| 138 |
regex: '"{3}', |
| 139 |
next: "start" |
| 140 |
}, { |
| 141 |
defaultToken: "string" |
| 142 |
}], |
| 143 |
"qstring3": [{ |
| 144 |
token: "constant.language.escape", |
| 145 |
regex: stringEscape |
| 146 |
}, { |
| 147 |
token: "string", |
| 148 |
regex: "'{3}", |
| 149 |
next: "start" |
| 150 |
}, { |
| 151 |
defaultToken: "string" |
| 152 |
}], |
| 153 |
"qqstring": [{ |
| 154 |
token: "constant.language.escape", |
| 155 |
regex: stringEscape |
| 156 |
}, { |
| 157 |
token: "string", |
| 158 |
regex: "\\\\$", |
| 159 |
next: "qqstring" |
| 160 |
}, { |
| 161 |
token: "string", |
| 162 |
regex: '"|$', |
| 163 |
next: "start" |
| 164 |
}, { |
| 165 |
defaultToken: "string" |
| 166 |
}], |
| 167 |
"qstring": [{ |
| 168 |
token: "constant.language.escape", |
| 169 |
regex: stringEscape |
| 170 |
}, { |
| 171 |
token: "string", |
| 172 |
regex: "\\\\$", |
| 173 |
next: "qstring" |
| 174 |
}, { |
| 175 |
token: "string", |
| 176 |
regex: "'|$", |
| 177 |
next: "start" |
| 178 |
}, { |
| 179 |
defaultToken: "string" |
| 180 |
}], |
| 181 |
"rawqqstring3": [{ |
| 182 |
token: "string", |
| 183 |
regex: '"{3}', |
| 184 |
next: "start" |
| 185 |
}, { |
| 186 |
defaultToken: "string" |
| 187 |
}], |
| 188 |
"rawqstring3": [{ |
| 189 |
token: "string", |
| 190 |
regex: "'{3}", |
| 191 |
next: "start" |
| 192 |
}, { |
| 193 |
defaultToken: "string" |
| 194 |
}], |
| 195 |
"rawqqstring": [{ |
| 196 |
token: "string", |
| 197 |
regex: "\\\\$", |
| 198 |
next: "rawqqstring" |
| 199 |
}, { |
| 200 |
token: "string", |
| 201 |
regex: '"|$', |
| 202 |
next: "start" |
| 203 |
}, { |
| 204 |
defaultToken: "string" |
| 205 |
}], |
| 206 |
"rawqstring": [{ |
| 207 |
token: "string", |
| 208 |
regex: "\\\\$", |
| 209 |
next: "rawqstring" |
| 210 |
}, { |
| 211 |
token: "string", |
| 212 |
regex: "'|$", |
| 213 |
next: "start" |
| 214 |
}, { |
| 215 |
defaultToken: "string" |
| 216 |
}], |
| 217 |
"fqqstring3": [{ |
| 218 |
token: "constant.language.escape", |
| 219 |
regex: stringEscape |
| 220 |
}, { |
| 221 |
token: "string", |
| 222 |
regex: '"{3}', |
| 223 |
next: "start" |
| 224 |
}, { |
| 225 |
token: "paren.lparen", |
| 226 |
regex: "{", |
| 227 |
push: "fqstringParRules" |
| 228 |
}, { |
| 229 |
defaultToken: "string" |
| 230 |
}], |
| 231 |
"fqstring3": [{ |
| 232 |
token: "constant.language.escape", |
| 233 |
regex: stringEscape |
| 234 |
}, { |
| 235 |
token: "string", |
| 236 |
regex: "'{3}", |
| 237 |
next: "start" |
| 238 |
}, { |
| 239 |
token: "paren.lparen", |
| 240 |
regex: "{", |
| 241 |
push: "fqstringParRules" |
| 242 |
}, { |
| 243 |
defaultToken: "string" |
| 244 |
}], |
| 245 |
"fqqstring": [{ |
| 246 |
token: "constant.language.escape", |
| 247 |
regex: stringEscape |
| 248 |
}, { |
| 249 |
token: "string", |
| 250 |
regex: "\\\\$", |
| 251 |
next: "fqqstring" |
| 252 |
}, { |
| 253 |
token: "string", |
| 254 |
regex: '"|$', |
| 255 |
next: "start" |
| 256 |
}, { |
| 257 |
token: "paren.lparen", |
| 258 |
regex: "{", |
| 259 |
push: "fqstringParRules" |
| 260 |
}, { |
| 261 |
defaultToken: "string" |
| 262 |
}], |
| 263 |
"fqstring": [{ |
| 264 |
token: "constant.language.escape", |
| 265 |
regex: stringEscape |
| 266 |
}, { |
| 267 |
token: "string", |
| 268 |
regex: "'|$", |
| 269 |
next: "start" |
| 270 |
}, { |
| 271 |
token: "paren.lparen", |
| 272 |
regex: "{", |
| 273 |
push: "fqstringParRules" |
| 274 |
}, { |
| 275 |
defaultToken: "string" |
| 276 |
}], |
| 277 |
"rfqqstring3": [{ |
| 278 |
token: "string", |
| 279 |
regex: '"{3}', |
| 280 |
next: "start" |
| 281 |
}, { |
| 282 |
token: "paren.lparen", |
| 283 |
regex: "{", |
| 284 |
push: "fqstringParRules" |
| 285 |
}, { |
| 286 |
defaultToken: "string" |
| 287 |
}], |
| 288 |
"rfqstring3": [{ |
| 289 |
token: "string", |
| 290 |
regex: "'{3}", |
| 291 |
next: "start" |
| 292 |
}, { |
| 293 |
token: "paren.lparen", |
| 294 |
regex: "{", |
| 295 |
push: "fqstringParRules" |
| 296 |
}, { |
| 297 |
defaultToken: "string" |
| 298 |
}], |
| 299 |
"rfqqstring": [{ |
| 300 |
token: "string", |
| 301 |
regex: "\\\\$", |
| 302 |
next: "rfqqstring" |
| 303 |
}, { |
| 304 |
token: "string", |
| 305 |
regex: '"|$', |
| 306 |
next: "start" |
| 307 |
}, { |
| 308 |
token: "paren.lparen", |
| 309 |
regex: "{", |
| 310 |
push: "fqstringParRules" |
| 311 |
}, { |
| 312 |
defaultToken: "string" |
| 313 |
}], |
| 314 |
"rfqstring": [{ |
| 315 |
token: "string", |
| 316 |
regex: "'|$", |
| 317 |
next: "start" |
| 318 |
}, { |
| 319 |
token: "paren.lparen", |
| 320 |
regex: "{", |
| 321 |
push: "fqstringParRules" |
| 322 |
}, { |
| 323 |
defaultToken: "string" |
| 324 |
}], |
| 325 |
"fqstringParRules": [{ |
| 326 |
token: "paren.lparen", |
| 327 |
regex: "[\\[\\(]" |
| 328 |
}, { |
| 329 |
token: "paren.rparen", |
| 330 |
regex: "[\\]\\)]" |
| 331 |
}, { |
| 332 |
token: "string", |
| 333 |
regex: "\\s+" |
| 334 |
}, { |
| 335 |
token: "string", |
| 336 |
regex: "'[^']*'" |
| 337 |
}, { |
| 338 |
token: "string", |
| 339 |
regex: '"[^"]*"' |
| 340 |
}, { |
| 341 |
token: "function.support", |
| 342 |
regex: "(!s|!r|!a)" |
| 343 |
}, { |
| 344 |
include: "constants" |
| 345 |
}, { |
| 346 |
token: 'paren.rparen', |
| 347 |
regex: "}", |
| 348 |
next: 'pop' |
| 349 |
}, { |
| 350 |
token: 'paren.lparen', |
| 351 |
regex: "{", |
| 352 |
push: "fqstringParRules" |
| 353 |
}], |
| 354 |
"constants": [{ |
| 355 |
token: "constant.numeric", |
| 356 |
regex: "(?:" + floatNumber + "|\\d+)[jJ]\\b" |
| 357 |
}, { |
| 358 |
token: "constant.numeric", |
| 359 |
regex: floatNumber |
| 360 |
}, { |
| 361 |
token: "constant.numeric", |
| 362 |
regex: integer + "[lL]\\b" |
| 363 |
}, { |
| 364 |
token: "constant.numeric", |
| 365 |
regex: integer + "\\b" |
| 366 |
}, { |
| 367 |
token: ["punctuation", "function.support"], |
| 368 |
regex: "(\\.)([a-zA-Z_]+)\\b" |
| 369 |
}, { |
| 370 |
token: keywordMapper, |
| 371 |
regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" |
| 372 |
}] |
| 373 |
}; |
| 374 |
this.normalizeRules(); |
| 375 |
}; |
| 376 |
oop.inherits(PythonHighlightRules, TextHighlightRules); |
| 377 |
exports.PythonHighlightRules = PythonHighlightRules; |
| 378 |
|
| 379 |
}); |
| 380 |
|
| 381 |
ace.define("ace/mode/folding/pythonic",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict"; |
| 382 |
var oop = require("../../lib/oop"); |
| 383 |
var BaseFoldMode = require("./fold_mode").FoldMode; |
| 384 |
var FoldMode = exports.FoldMode = function (markers) { |
| 385 |
this.foldingStartMarker = new RegExp("([\\[{])(?:\\s*)$|(" + markers + ")(?:\\s*)(?:#.*)?$"); |
| 386 |
}; |
| 387 |
oop.inherits(FoldMode, BaseFoldMode); |
| 388 |
(function () { |
| 389 |
this.getFoldWidgetRange = function (session, foldStyle, row) { |
| 390 |
var line = session.getLine(row); |
| 391 |
var match = line.match(this.foldingStartMarker); |
| 392 |
if (match) { |
| 393 |
if (match[1]) |
| 394 |
return this.openingBracketBlock(session, match[1], row, match.index); |
| 395 |
if (match[2]) |
| 396 |
return this.indentationBlock(session, row, match.index + match[2].length); |
| 397 |
return this.indentationBlock(session, row); |
| 398 |
} |
| 399 |
}; |
| 400 |
}).call(FoldMode.prototype); |
| 401 |
|
| 402 |
}); |
| 403 |
|
| 404 |
ace.define("ace/mode/python",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/python_highlight_rules","ace/mode/folding/pythonic","ace/range"], function(require, exports, module){"use strict"; |
| 405 |
var oop = require("../lib/oop"); |
| 406 |
var TextMode = require("./text").Mode; |
| 407 |
var PythonHighlightRules = require("./python_highlight_rules").PythonHighlightRules; |
| 408 |
var PythonFoldMode = require("./folding/pythonic").FoldMode; |
| 409 |
var Range = require("../range").Range; |
| 410 |
var Mode = function () { |
| 411 |
this.HighlightRules = PythonHighlightRules; |
| 412 |
this.foldingRules = new PythonFoldMode("\\:"); |
| 413 |
this.$behaviour = this.$defaultBehaviour; |
| 414 |
}; |
| 415 |
oop.inherits(Mode, TextMode); |
| 416 |
(function () { |
| 417 |
this.lineCommentStart = "#"; |
| 418 |
this.$pairQuotesAfter = { |
| 419 |
"'": /[ruf]/i, |
| 420 |
'"': /[ruf]/i |
| 421 |
}; |
| 422 |
this.getNextLineIndent = function (state, line, tab) { |
| 423 |
var indent = this.$getIndent(line); |
| 424 |
var tokenizedLine = this.getTokenizer().getLineTokens(line, state); |
| 425 |
var tokens = tokenizedLine.tokens; |
| 426 |
if (tokens.length && tokens[tokens.length - 1].type == "comment") { |
| 427 |
return indent; |
| 428 |
} |
| 429 |
if (state == "start") { |
| 430 |
var match = line.match(/^.*[\{\(\[:]\s*$/); |
| 431 |
if (match) { |
| 432 |
indent += tab; |
| 433 |
} |
| 434 |
} |
| 435 |
return indent; |
| 436 |
}; |
| 437 |
var outdents = { |
| 438 |
"pass": 1, |
| 439 |
"return": 1, |
| 440 |
"raise": 1, |
| 441 |
"break": 1, |
| 442 |
"continue": 1 |
| 443 |
}; |
| 444 |
this.checkOutdent = function (state, line, input) { |
| 445 |
if (input !== "\r\n" && input !== "\r" && input !== "\n") |
| 446 |
return false; |
| 447 |
var tokens = this.getTokenizer().getLineTokens(line.trim(), state).tokens; |
| 448 |
if (!tokens) |
| 449 |
return false; |
| 450 |
do { |
| 451 |
var last = tokens.pop(); |
| 452 |
} while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/)))); |
| 453 |
if (!last) |
| 454 |
return false; |
| 455 |
return (last.type == "keyword" && outdents[last.value]); |
| 456 |
}; |
| 457 |
this.autoOutdent = function (state, doc, row) { |
| 458 |
row += 1; |
| 459 |
var indent = this.$getIndent(doc.getLine(row)); |
| 460 |
var tab = doc.getTabString(); |
| 461 |
if (indent.slice(-tab.length) == tab) |
| 462 |
doc.remove(new Range(row, indent.length - tab.length, row, indent.length)); |
| 463 |
}; |
| 464 |
this.$id = "ace/mode/python"; |
| 465 |
this.snippetFileId = "ace/snippets/python"; |
| 466 |
}).call(Mode.prototype); |
| 467 |
exports.Mode = Mode; |
| 468 |
|
| 469 |
}); (function() { |
| 470 |
ace.require(["ace/mode/python"], function(m) { |
| 471 |
if (typeof module == "object" && typeof exports == "object" && module) { |
| 472 |
module.exports = m; |
| 473 |
} |
| 474 |
}); |
| 475 |
})(); |
| 476 |
|