1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2010, Ajax.org B.V.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* * Neither the name of Ajax.org B.V. nor the
15
* names of its contributors may be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
* ***** END LICENSE BLOCK ***** */
31
define('ace/mode/python', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/python_highlight_rules', 'ace/mode/folding/pythonic', 'ace/range'], function(require, exports, module) {
34
var oop = require("../lib/oop");
35
var TextMode = require("./text").Mode;
36
var Tokenizer = require("../tokenizer").Tokenizer;
37
var PythonHighlightRules = require("./python_highlight_rules").PythonHighlightRules;
38
var PythonFoldMode = require("./folding/pythonic").FoldMode;
39
var Range = require("../range").Range;
41
var Mode = function() {
42
this.$tokenizer = new Tokenizer(new PythonHighlightRules().getRules());
43
this.foldingRules = new PythonFoldMode("\\:");
45
oop.inherits(Mode, TextMode);
49
this.lineCommentStart = "#";
51
this.getNextLineIndent = function(state, line, tab) {
52
var indent = this.$getIndent(line);
54
var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
55
var tokens = tokenizedLine.tokens;
57
if (tokens.length && tokens[tokens.length-1].type == "comment") {
61
if (state == "start") {
62
var match = line.match(/^.*[\{\(\[\:]\s*$/);
79
this.checkOutdent = function(state, line, input) {
80
if (input !== "\r\n" && input !== "\r" && input !== "\n")
83
var tokens = this.$tokenizer.getLineTokens(line.trim(), state).tokens;
88
var last = tokens.pop();
89
} while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
94
return (last.type == "keyword" && outdents[last.value]);
97
this.autoOutdent = function(state, doc, row) {
100
var indent = this.$getIndent(doc.getLine(row));
101
var tab = doc.getTabString();
102
if (indent.slice(-tab.length) == tab)
103
doc.remove(new Range(row, indent.length-tab.length, row, indent.length));
106
}).call(Mode.prototype);
111
define('ace/mode/python_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
114
var oop = require("../lib/oop");
115
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
117
var PythonHighlightRules = function() {
120
"and|as|assert|break|class|continue|def|del|elif|else|except|exec|" +
121
"finally|for|from|global|if|import|in|is|lambda|not|or|pass|print|" +
122
"raise|return|try|while|with|yield"
125
var builtinConstants = (
126
"True|False|None|NotImplemented|Ellipsis|__debug__"
129
var builtinFunctions = (
130
"abs|divmod|input|open|staticmethod|all|enumerate|int|ord|str|any|" +
131
"eval|isinstance|pow|sum|basestring|execfile|issubclass|print|super|" +
132
"binfile|iter|property|tuple|bool|filter|len|range|type|bytearray|" +
133
"float|list|raw_input|unichr|callable|format|locals|reduce|unicode|" +
134
"chr|frozenset|long|reload|vars|classmethod|getattr|map|repr|xrange|" +
135
"cmp|globals|max|reversed|zip|compile|hasattr|memoryview|round|" +
136
"__import__|complex|hash|min|set|apply|delattr|help|next|setattr|" +
137
"buffer|dict|hex|object|slice|coerce|dir|id|oct|sorted|intern"
139
var keywordMapper = this.createKeywordMapper({
140
"invalid.deprecated": "debugger",
141
"support.function": builtinFunctions,
142
"constant.language": builtinConstants,
146
var strPre = "(?:r|u|ur|R|U|UR|Ur|uR)?";
148
var decimalInteger = "(?:(?:[1-9]\\d*)|(?:0))";
149
var octInteger = "(?:0[oO]?[0-7]+)";
150
var hexInteger = "(?:0[xX][\\dA-Fa-f]+)";
151
var binInteger = "(?:0[bB][01]+)";
152
var integer = "(?:" + decimalInteger + "|" + octInteger + "|" + hexInteger + "|" + binInteger + ")";
154
var exponent = "(?:[eE][+-]?\\d+)";
155
var fraction = "(?:\\.\\d+)";
156
var intPart = "(?:\\d+)";
157
var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))";
158
var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + exponent + ")";
159
var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")";
166
token : "string", // """ string
167
regex : strPre + '"{3}(?:[^\\\\]|\\\\.)*?"{3}'
169
token : "string", // multi line """ string start
170
regex : strPre + '"{3}.*$',
173
token : "string", // " string
174
regex : strPre + '"(?:[^\\\\]|\\\\.)*?"'
176
token : "string", // ''' string
177
regex : strPre + "'{3}(?:[^\\\\]|\\\\.)*?'{3}"
179
token : "string", // multi line ''' string start
180
regex : strPre + "'{3}.*$",
183
token : "string", // ' string
184
regex : strPre + "'(?:[^\\\\]|\\\\.)*?'"
186
token : "constant.numeric", // imaginary
187
regex : "(?:" + floatNumber + "|\\d+)[jJ]\\b"
189
token : "constant.numeric", // float
192
token : "constant.numeric", // long integer
193
regex : integer + "[lL]\\b"
195
token : "constant.numeric", // integer
196
regex : integer + "\\b"
198
token : keywordMapper,
199
regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
201
token : "keyword.operator",
202
regex : "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|%|<<|>>|&|\\||\\^|~|<|>|<=|=>|==|!=|<>|="
204
token : "paren.lparen",
205
regex : "[\\[\\(\\{]"
207
token : "paren.rparen",
208
regex : "[\\]\\)\\}]"
214
token : "string", // multi line """ string end
215
regex : '(?:[^\\\\]|\\\\.)*?"{3}',
222
token : "string", // multi line ''' string end
223
regex : "(?:[^\\\\]|\\\\.)*?'{3}",
232
oop.inherits(PythonHighlightRules, TextHighlightRules);
234
exports.PythonHighlightRules = PythonHighlightRules;
237
define('ace/mode/folding/pythonic', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
240
var oop = require("../../lib/oop");
241
var BaseFoldMode = require("./fold_mode").FoldMode;
243
var FoldMode = exports.FoldMode = function(markers) {
244
this.foldingStartMarker = new RegExp("([\\[{])(?:\\s*)$|(" + markers + ")(?:\\s*)(?:#.*)?$");
246
oop.inherits(FoldMode, BaseFoldMode);
250
this.getFoldWidgetRange = function(session, foldStyle, row) {
251
var line = session.getLine(row);
252
var match = line.match(this.foldingStartMarker);
255
return this.openingBracketBlock(session, match[1], row, match.index);
257
return this.indentationBlock(session, row, match.index + match[2].length);
258
return this.indentationBlock(session, row);
262
}).call(FoldMode.prototype);