diff options
Diffstat (limited to 'addons/web/static/lib/ace/mode-python.js')
| -rw-r--r-- | addons/web/static/lib/ace/mode-python.js | 448 |
1 files changed, 263 insertions, 185 deletions
diff --git a/addons/web/static/lib/ace/mode-python.js b/addons/web/static/lib/ace/mode-python.js index 65087ebd86d..ec709a73952 100644 --- a/addons/web/static/lib/ace/mode-python.js +++ b/addons/web/static/lib/ace/mode-python.js @@ -1,187 +1,265 @@ -(function() {var define = ace.define, require = ace.require; -define("ace/mode/python_highlight_rules", ["require", "exports", "module", "ace/lib/oop", "ace/mode/text_highlight_rules"], function(e, t, n) { - "use strict"; - var r = e("../lib/oop"), - i = e("./text_highlight_rules").TextHighlightRules, - s = function() { - var e = "and|as|assert|break|class|continue|def|del|elif|else|except|exec|finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|raise|return|try|while|with|yield", - t = "True|False|None|NotImplemented|Ellipsis|__debug__", - n = "abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|binfile|iter|property|tuple|bool|filter|len|range|type|bytearray|float|list|raw_input|unichr|callable|format|locals|reduce|unicode|chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|__import__|complex|hash|min|set|apply|delattr|help|next|setattr|buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern", - r = this.createKeywordMapper({ - "invalid.deprecated": "debugger", - "support.function": n, - "constant.language": t, - keyword: e - }, "identifier"), - i = "(?:r|u|ur|R|U|UR|Ur|uR)?", - s = "(?:(?:[1-9]\\d*)|(?:0))", - o = "(?:0[oO]?[0-7]+)", - u = "(?:0[xX][\\dA-Fa-f]+)", - a = "(?:0[bB][01]+)", - f = "(?:" + s + "|" + o + "|" + u + "|" + a + ")", - l = "(?:[eE][+-]?\\d+)", - c = "(?:\\.\\d+)", - h = "(?:\\d+)", - p = "(?:(?:" + h + "?" + c + ")|(?:" + h + "\\.))", - d = "(?:(?:" + p + "|" + h + ")" + l + ")", - v = "(?:" + d + "|" + p + ")", - m = "\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})"; - this.$rules = { - start: [{ - token: "comment", - regex: "#.*$" - }, { - token: "string", - regex: i + '"{3}', - next: "qqstring3" - }, { - token: "string", - regex: i + '"(?=.)', - next: "qqstring" - }, { - token: "string", - regex: i + "'{3}", - next: "qstring3" - }, { - token: "string", - regex: i + "'(?=.)", - next: "qstring" - }, { - token: "constant.numeric", - regex: "(?:" + v + "|\\d+)[jJ]\\b" - }, { - token: "constant.numeric", - regex: v - }, { - token: "constant.numeric", - regex: f + "[lL]\\b" - }, { - token: "constant.numeric", - regex: f + "\\b" - }, { - token: r, - regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" - }, { - token: "keyword.operator", - regex: "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|=" - }, { - token: "paren.lparen", - regex: "[\\[\\(\\{]" - }, { - token: "paren.rparen", - regex: "[\\]\\)\\}]" - }, { - token: "text", - regex: "\\s+" - }], - qqstring3: [{ - token: "constant.language.escape", - regex: m - }, { - token: "string", - regex: '"{3}', - next: "start" - }, { - defaultToken: "string" - }], - qstring3: [{ - token: "constant.language.escape", - regex: m - }, { - token: "string", - regex: "'{3}", - next: "start" - }, { - defaultToken: "string" - }], - qqstring: [{ - token: "constant.language.escape", - regex: m - }, { - token: "string", - regex: "\\\\$", - next: "qqstring" - }, { - token: "string", - regex: '"|$', - next: "start" - }, { - defaultToken: "string" - }], - qstring: [{ - token: "constant.language.escape", - regex: m - }, { - token: "string", - regex: "\\\\$", - next: "qstring" - }, { - token: "string", - regex: "'|$", - next: "start" - }, { - defaultToken: "string" - }] - } - }; - r.inherits(s, i), t.PythonHighlightRules = s -}), define("ace/mode/folding/pythonic", ["require", "exports", "module", "ace/lib/oop", "ace/mode/folding/fold_mode"], function(e, t, n) { - "use strict"; - var r = e("../../lib/oop"), - i = e("./fold_mode").FoldMode, - s = t.FoldMode = function(e) { - this.foldingStartMarker = new RegExp("([\\[{])(?:\\s*)$|(" + e + ")(?:\\s*)(?:#.*)?$") - }; - r.inherits(s, i), - function() { - this.getFoldWidgetRange = function(e, t, n) { - var r = e.getLine(n), - i = r.match(this.foldingStartMarker); - if (i) return i[1] ? this.openingBracketBlock(e, i[1], n, i.index) : i[2] ? this.indentationBlock(e, n, i.index + i[2].length) : this.indentationBlock(e, n) +define("ace/mode/python_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) { +"use strict"; + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; + +var PythonHighlightRules = function() { + + var keywords = ( + "and|as|assert|break|class|continue|def|del|elif|else|except|exec|" + + "finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|" + + "raise|return|try|while|with|yield|async|await" + ); + + var builtinConstants = ( + "True|False|None|NotImplemented|Ellipsis|__debug__" + ); + + var builtinFunctions = ( + "abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|" + + "eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|" + + "binfile|iter|property|tuple|bool|filter|len|range|type|bytearray|" + + "float|list|raw_input|unichr|callable|format|locals|reduce|unicode|" + + "chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|" + + "cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|" + + "__import__|complex|hash|min|set|apply|delattr|help|next|setattr|" + + "buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern" + ); + var keywordMapper = this.createKeywordMapper({ + "invalid.deprecated": "debugger", + "support.function": builtinFunctions, + "constant.language": builtinConstants, + "keyword": keywords + }, "identifier"); + + var strPre = "(?:r|u|ur|R|U|UR|Ur|uR)?"; + + var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))"; + var octInteger = "(?:0[oO]?[0-7]+)"; + var hexInteger = "(?:0[xX][\\dA-Fa-f]+)"; + var binInteger = "(?:0[bB][01]+)"; + var integer = "(?:" + decimalInteger + "|" + octInteger + "|" + hexInteger + "|" + binInteger + ")"; + + var exponent = "(?:[eE][+-]?\\d+)"; + var fraction = "(?:\\.\\d+)"; + var intPart = "(?:\\d+)"; + var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))"; + var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + exponent + ")"; + var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")"; + + var stringEscape = "\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})"; + + this.$rules = { + "start" : [ { + token : "comment", + regex : "#.*$" + }, { + token : "string", // multi line """ string start + regex : strPre + '"{3}', + next : "qqstring3" + }, { + token : "string", // " string + regex : strPre + '"(?=.)', + next : "qqstring" + }, { + token : "string", // multi line ''' string start + regex : strPre + "'{3}", + next : "qstring3" + }, { + token : "string", // ' string + regex : strPre + "'(?=.)", + next : "qstring" + }, { + token : "constant.numeric", // imaginary + regex : "(?:" + floatNumber + "|\\d+)[jJ]\\b" + }, { + token : "constant.numeric", // float + regex : floatNumber + }, { + token : "constant.numeric", // long integer + regex : integer + "[lL]\\b" + }, { + token : "constant.numeric", // integer + regex : integer + "\\b" + }, { + token : keywordMapper, + regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" + }, { + token : "keyword.operator", + regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|=" + }, { + token : "paren.lparen", + regex : "[\\[\\(\\{]" + }, { + token : "paren.rparen", + regex : "[\\]\\)\\}]" + }, { + token : "text", + regex : "\\s+" + } ], + "qqstring3" : [ { + token : "constant.language.escape", + regex : stringEscape + }, { + token : "string", // multi line """ string end + regex : '"{3}', + next : "start" + }, { + defaultToken : "string" + } ], + "qstring3" : [ { + token : "constant.language.escape", + regex : stringEscape + }, { + token : "string", // multi line ''' string end + regex : "'{3}", + next : "start" + }, { + defaultToken : "string" + } ], + "qqstring" : [{ + token : "constant.language.escape", + regex : stringEscape + }, { + token : "string", + regex : "\\\\$", + next : "qqstring" + }, { + token : "string", + regex : '"|$', + next : "start" + }, { + defaultToken: "string" + }], + "qstring" : [{ + token : "constant.language.escape", + regex : stringEscape + }, { + token : "string", + regex : "\\\\$", + next : "qstring" + }, { + token : "string", + regex : "'|$", + next : "start" + }, { + defaultToken: "string" + }] + }; +}; + +oop.inherits(PythonHighlightRules, TextHighlightRules); + +exports.PythonHighlightRules = PythonHighlightRules; +}); + +define("ace/mode/folding/pythonic",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode"], function(require, exports, module) { +"use strict"; + +var oop = require("../../lib/oop"); +var BaseFoldMode = require("./fold_mode").FoldMode; + +var FoldMode = exports.FoldMode = function(markers) { + this.foldingStartMarker = new RegExp("([\\[{])(?:\\s*)$|(" + markers + ")(?:\\s*)(?:#.*)?$"); +}; +oop.inherits(FoldMode, BaseFoldMode); + +(function() { + + this.getFoldWidgetRange = function(session, foldStyle, row) { + var line = session.getLine(row); + var match = line.match(this.foldingStartMarker); + if (match) { + if (match[1]) + return this.openingBracketBlock(session, match[1], row, match.index); + if (match[2]) + return this.indentationBlock(session, row, match.index + match[2].length); + return this.indentationBlock(session, row); + } + }; + +}).call(FoldMode.prototype); + +}); + +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"; + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var PythonHighlightRules = require("./python_highlight_rules").PythonHighlightRules; +var PythonFoldMode = require("./folding/pythonic").FoldMode; +var Range = require("../range").Range; + +var Mode = function() { + this.HighlightRules = PythonHighlightRules; + this.foldingRules = new PythonFoldMode("\\:"); + this.$behaviour = this.$defaultBehaviour; +}; +oop.inherits(Mode, TextMode); + +(function() { + + this.lineCommentStart = "#"; + + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + + var tokenizedLine = this.getTokenizer().getLineTokens(line, state); + var tokens = tokenizedLine.tokens; + + if (tokens.length && tokens[tokens.length-1].type == "comment") { + return indent; + } + + if (state == "start") { + var match = line.match(/^.*[\{\(\[:]\s*$/); + if (match) { + indent += tab; } - }.call(s.prototype) -}), 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(e, t, n) { - "use strict"; - var r = e("../lib/oop"), - i = e("./text").Mode, - s = e("./python_highlight_rules").PythonHighlightRules, - o = e("./folding/pythonic").FoldMode, - u = e("../range").Range, - a = function() { - this.HighlightRules = s, this.foldingRules = new o("\\:") - }; - r.inherits(a, i), - function() { - this.lineCommentStart = "#", this.getNextLineIndent = function(e, t, n) { - var r = this.$getIndent(t), - i = this.getTokenizer().getLineTokens(t, e), - s = i.tokens; - if (s.length && s[s.length - 1].type == "comment") return r; - if (e == "start") { - var o = t.match(/^.*[\{\(\[\:]\s*$/); - o && (r += n) - } - return r - }; - var e = { - pass: 1, - "return": 1, - raise: 1, - "break": 1, - "continue": 1 - }; - this.checkOutdent = function(t, n, r) { - if (r !== "\r\n" && r !== "\r" && r !== "\n") return !1; - var i = this.getTokenizer().getLineTokens(n.trim(), t).tokens; - if (!i) return !1; - do var s = i.pop(); while (s && (s.type == "comment" || s.type == "text" && s.value.match(/^\s+$/))); - return s ? s.type == "keyword" && e[s.value] : !1 - }, this.autoOutdent = function(e, t, n) { - n += 1; - var r = this.$getIndent(t.getLine(n)), - i = t.getTabString(); - r.slice(-i.length) == i && t.remove(new u(n, r.length - i.length, n, r.length)) - }, this.$id = "ace/mode/python" - }.call(a.prototype), t.Mode = a + } + + return indent; + }; + + var outdents = { + "pass": 1, + "return": 1, + "raise": 1, + "break": 1, + "continue": 1 + }; + + this.checkOutdent = function(state, line, input) { + if (input !== "\r\n" && input !== "\r" && input !== "\n") + return false; + + var tokens = this.getTokenizer().getLineTokens(line.trim(), state).tokens; + + if (!tokens) + return false; + do { + var last = tokens.pop(); + } while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/)))); + + if (!last) + return false; + + return (last.type == "keyword" && outdents[last.value]); + }; + + this.autoOutdent = function(state, doc, row) { + + row += 1; + var indent = this.$getIndent(doc.getLine(row)); + var tab = doc.getTabString(); + if (indent.slice(-tab.length) == tab) + doc.remove(new Range(row, indent.length-tab.length, row, indent.length)); + }; + + this.$id = "ace/mode/python"; +}).call(Mode.prototype); + +exports.Mode = Mode; }); -})(); |
