966a0905960f7cf236a398b68d3a4c6c.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. ace.define("ace/mode/python_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){/*
  2. * TODO: python delimiters
  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. ace.define("ace/mode/folding/pythonic",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
  380. var oop = require("../../lib/oop");
  381. var BaseFoldMode = require("./fold_mode").FoldMode;
  382. var FoldMode = exports.FoldMode = function (markers) {
  383. this.foldingStartMarker = new RegExp("([\\[{])(?:\\s*)$|(" + markers + ")(?:\\s*)(?:#.*)?$");
  384. };
  385. oop.inherits(FoldMode, BaseFoldMode);
  386. (function () {
  387. this.getFoldWidgetRange = function (session, foldStyle, row) {
  388. var line = session.getLine(row);
  389. var match = line.match(this.foldingStartMarker);
  390. if (match) {
  391. if (match[1])
  392. return this.openingBracketBlock(session, match[1], row, match.index);
  393. if (match[2])
  394. return this.indentationBlock(session, row, match.index + match[2].length);
  395. return this.indentationBlock(session, row);
  396. }
  397. };
  398. }).call(FoldMode.prototype);
  399. });
  400. 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";
  401. var oop = require("../lib/oop");
  402. var TextMode = require("./text").Mode;
  403. var PythonHighlightRules = require("./python_highlight_rules").PythonHighlightRules;
  404. var PythonFoldMode = require("./folding/pythonic").FoldMode;
  405. var Range = require("../range").Range;
  406. var Mode = function () {
  407. this.HighlightRules = PythonHighlightRules;
  408. this.foldingRules = new PythonFoldMode("\\:");
  409. this.$behaviour = this.$defaultBehaviour;
  410. };
  411. oop.inherits(Mode, TextMode);
  412. (function () {
  413. this.lineCommentStart = "#";
  414. this.getNextLineIndent = function (state, line, tab) {
  415. var indent = this.$getIndent(line);
  416. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  417. var tokens = tokenizedLine.tokens;
  418. if (tokens.length && tokens[tokens.length - 1].type == "comment") {
  419. return indent;
  420. }
  421. if (state == "start") {
  422. var match = line.match(/^.*[\{\(\[:]\s*$/);
  423. if (match) {
  424. indent += tab;
  425. }
  426. }
  427. return indent;
  428. };
  429. var outdents = {
  430. "pass": 1,
  431. "return": 1,
  432. "raise": 1,
  433. "break": 1,
  434. "continue": 1
  435. };
  436. this.checkOutdent = function (state, line, input) {
  437. if (input !== "\r\n" && input !== "\r" && input !== "\n")
  438. return false;
  439. var tokens = this.getTokenizer().getLineTokens(line.trim(), state).tokens;
  440. if (!tokens)
  441. return false;
  442. do {
  443. var last = tokens.pop();
  444. } while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
  445. if (!last)
  446. return false;
  447. return (last.type == "keyword" && outdents[last.value]);
  448. };
  449. this.autoOutdent = function (state, doc, row) {
  450. row += 1;
  451. var indent = this.$getIndent(doc.getLine(row));
  452. var tab = doc.getTabString();
  453. if (indent.slice(-tab.length) == tab)
  454. doc.remove(new Range(row, indent.length - tab.length, row, indent.length));
  455. };
  456. this.$id = "ace/mode/python";
  457. this.snippetFileId = "ace/snippets/python";
  458. }).call(Mode.prototype);
  459. exports.Mode = Mode;
  460. }); (function() {
  461. ace.require(["ace/mode/python"], function(m) {
  462. if (typeof module == "object" && typeof exports == "object" && module) {
  463. module.exports = m;
  464. }
  465. });
  466. })();