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