30335c579bfc2de8dcf574523ef13020.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. ace.define("ace/mode/nim_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4. var NimHighlightRules = function () {
  5. var keywordMapper = this.createKeywordMapper({
  6. "variable": "var|let|const",
  7. "keyword": "assert|parallel|spawn|export|include|from|template|mixin|bind|import|concept|raise|defer|try|finally|except|converter|proc|func|macro|method|and|or|not|xor|shl|shr|div|mod|in|notin|is|isnot|of|static|if|elif|else|case|of|discard|when|return|yield|block|break|while|echo|continue|asm|using|cast|addr|unsafeAddr|type|ref|ptr|do|declared|defined|definedInScope|compiles|sizeOf|is|shallowCopy|getAst|astToStr|spawn|procCall|for|iterator|as",
  8. "storage.type": "newSeq|int|int8|int16|int32|int64|uint|uint8|uint16|uint32|uint64|float|char|bool|string|set|pointer|float32|float64|enum|object|cstring|array|seq|openArray|varargs|UncheckedArray|tuple|set|distinct|void|auto|openarray|range",
  9. "support.function": "lock|ze|toU8|toU16|toU32|ord|low|len|high|add|pop|contains|card|incl|excl|dealloc|inc",
  10. "constant.language": "nil|true|false"
  11. }, "identifier");
  12. var hexNumber = "(?:0[xX][\\dA-Fa-f][\\dA-Fa-f_]*)";
  13. var decNumber = "(?:[0-9][\\d_]*)";
  14. var octNumber = "(?:0o[0-7][0-7_]*)";
  15. var binNumber = "(?:0[bB][01][01_]*)";
  16. var intNumber = "(?:" + hexNumber + "|" + decNumber + "|" + octNumber + "|" + binNumber + ")(?:'?[iIuU](?:8|16|32|64)|u)?\\b";
  17. var exponent = "(?:[eE][+-]?[\\d][\\d_]*)";
  18. var floatNumber = "(?:[\\d][\\d_]*(?:[.][\\d](?:[\\d_]*)" + exponent + "?)|" + exponent + ")";
  19. var floatNumberExt = "(?:" + hexNumber + "(?:'(?:(?:[fF](?:32|64)?)|[dD])))|(?:" + floatNumber + "|" + decNumber + "|" + octNumber + "|" + binNumber + ")(?:'(?:(?:[fF](?:32|64)?)|[dD]))";
  20. var stringEscape = "\\\\([abeprcnlftv\\\"']|x[0-9A-Fa-f]{2}|[0-2][0-9]{2}|u[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})";
  21. var identifier = '[a-zA-Z][a-zA-Z0-9_]*';
  22. this.$rules = {
  23. "start": [{
  24. token: ["identifier", "keyword.operator", "support.function"],
  25. regex: "(" + identifier + ")([.]{1})(" + identifier + ")(?=\\()"
  26. }, {
  27. token: "paren.lparen",
  28. regex: "(\\{\\.)",
  29. next: [{
  30. token: "paren.rparen",
  31. regex: '(\\.\\}|\\})',
  32. next: "start"
  33. }, {
  34. include: "methods"
  35. }, {
  36. token: "identifier",
  37. regex: identifier
  38. }, {
  39. token: "punctuation",
  40. regex: /[,]/
  41. }, {
  42. token: "keyword.operator",
  43. regex: /[=:.]/
  44. }, {
  45. token: "paren.lparen",
  46. regex: /[[(]/
  47. }, {
  48. token: "paren.rparen",
  49. regex: /[\])]/
  50. }, {
  51. include: "math"
  52. }, {
  53. include: "strings"
  54. }, {
  55. defaultToken: "text"
  56. }]
  57. }, {
  58. token: "comment.doc.start",
  59. regex: /##\[(?!])/,
  60. push: "docBlockComment"
  61. }, {
  62. token: "comment.start",
  63. regex: /#\[(?!])/,
  64. push: "blockComment"
  65. }, {
  66. token: "comment.doc",
  67. regex: '##.*$'
  68. }, {
  69. token: "comment",
  70. regex: '#.*$'
  71. }, {
  72. include: "strings"
  73. }, {
  74. token: "string",
  75. regex: "'(?:\\\\(?:[abercnlftv]|x[0-9A-Fa-f]{2}|[0-2][0-9]{2}|u[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})|.{1})?'"
  76. }, {
  77. include: "methods"
  78. }, {
  79. token: keywordMapper,
  80. regex: "[a-zA-Z][a-zA-Z0-9_]*\\b"
  81. }, {
  82. token: ["keyword.operator", "text", "storage.type"],
  83. regex: "([:])(\\s+)(" + identifier + ")(?=$|\\)|\\[|,|\\s+=|;|\\s+\\{)"
  84. }, {
  85. token: "paren.lparen",
  86. regex: /\[\.|{\||\(\.|\[:|[[({`]/
  87. }, {
  88. token: "paren.rparen",
  89. regex: /\.\)|\|}|\.]|[\])}]/
  90. }, {
  91. token: "keyword.operator",
  92. regex: /[=+\-*\/<>@$~&%|!?^.:\\]/
  93. }, {
  94. token: "punctuation",
  95. regex: /[,;]/
  96. }, {
  97. include: "math"
  98. }],
  99. blockComment: [{
  100. regex: /#\[]/,
  101. token: "comment"
  102. }, {
  103. regex: /#\[(?!])/,
  104. token: "comment.start",
  105. push: "blockComment"
  106. }, {
  107. regex: /]#/,
  108. token: "comment.end",
  109. next: "pop"
  110. }, {
  111. defaultToken: "comment"
  112. }],
  113. docBlockComment: [{
  114. regex: /##\[]/,
  115. token: "comment.doc"
  116. }, {
  117. regex: /##\[(?!])/,
  118. token: "comment.doc.start",
  119. push: "docBlockComment"
  120. }, {
  121. regex: /]##/,
  122. token: "comment.doc.end",
  123. next: "pop"
  124. }, {
  125. defaultToken: "comment.doc"
  126. }],
  127. math: [{
  128. token: "constant.float",
  129. regex: floatNumberExt
  130. }, {
  131. token: "constant.float",
  132. regex: floatNumber
  133. }, {
  134. token: "constant.integer",
  135. regex: intNumber
  136. }],
  137. methods: [{
  138. token: "support.function",
  139. regex: "(\\w+)(?=\\()"
  140. }],
  141. strings: [{
  142. token: "string",
  143. regex: '(\\b' + identifier + ')?"""',
  144. push: [{
  145. token: "string",
  146. regex: '"""',
  147. next: "pop"
  148. }, {
  149. defaultToken: "string"
  150. }]
  151. }, {
  152. token: "string",
  153. regex: "\\b" + identifier + '"(?=.)',
  154. push: [{
  155. token: "string",
  156. regex: '"|$',
  157. next: "pop"
  158. }, {
  159. defaultToken: "string"
  160. }]
  161. }, {
  162. token: "string",
  163. regex: '"',
  164. push: [{
  165. token: "string",
  166. regex: '"|$',
  167. next: "pop"
  168. }, {
  169. token: "constant.language.escape",
  170. regex: stringEscape
  171. }, {
  172. defaultToken: "string"
  173. }]
  174. }]
  175. };
  176. this.normalizeRules();
  177. };
  178. oop.inherits(NimHighlightRules, TextHighlightRules);
  179. exports.NimHighlightRules = NimHighlightRules;
  180. });
  181. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
  182. var oop = require("../../lib/oop");
  183. var Range = require("../../range").Range;
  184. var BaseFoldMode = require("./fold_mode").FoldMode;
  185. var FoldMode = exports.FoldMode = function (commentRegex) {
  186. if (commentRegex) {
  187. this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
  188. this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
  189. }
  190. };
  191. oop.inherits(FoldMode, BaseFoldMode);
  192. (function () {
  193. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  194. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  195. this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
  196. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  197. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  198. this._getFoldWidgetBase = this.getFoldWidget;
  199. this.getFoldWidget = function (session, foldStyle, row) {
  200. var line = session.getLine(row);
  201. if (this.singleLineBlockCommentRe.test(line)) {
  202. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  203. return "";
  204. }
  205. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  206. if (!fw && this.startRegionRe.test(line))
  207. return "start"; // lineCommentRegionStart
  208. return fw;
  209. };
  210. this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
  211. var line = session.getLine(row);
  212. if (this.startRegionRe.test(line))
  213. return this.getCommentRegionBlock(session, line, row);
  214. var match = line.match(this.foldingStartMarker);
  215. if (match) {
  216. var i = match.index;
  217. if (match[1])
  218. return this.openingBracketBlock(session, match[1], row, i);
  219. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  220. if (range && !range.isMultiLine()) {
  221. if (forceMultiline) {
  222. range = this.getSectionRange(session, row);
  223. }
  224. else if (foldStyle != "all")
  225. range = null;
  226. }
  227. return range;
  228. }
  229. if (foldStyle === "markbegin")
  230. return;
  231. var match = line.match(this.foldingStopMarker);
  232. if (match) {
  233. var i = match.index + match[0].length;
  234. if (match[1])
  235. return this.closingBracketBlock(session, match[1], row, i);
  236. return session.getCommentFoldRange(row, i, -1);
  237. }
  238. };
  239. this.getSectionRange = function (session, row) {
  240. var line = session.getLine(row);
  241. var startIndent = line.search(/\S/);
  242. var startRow = row;
  243. var startColumn = line.length;
  244. row = row + 1;
  245. var endRow = row;
  246. var maxRow = session.getLength();
  247. while (++row < maxRow) {
  248. line = session.getLine(row);
  249. var indent = line.search(/\S/);
  250. if (indent === -1)
  251. continue;
  252. if (startIndent > indent)
  253. break;
  254. var subRange = this.getFoldWidgetRange(session, "all", row);
  255. if (subRange) {
  256. if (subRange.start.row <= startRow) {
  257. break;
  258. }
  259. else if (subRange.isMultiLine()) {
  260. row = subRange.end.row;
  261. }
  262. else if (startIndent == indent) {
  263. break;
  264. }
  265. }
  266. endRow = row;
  267. }
  268. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  269. };
  270. this.getCommentRegionBlock = function (session, line, row) {
  271. var startColumn = line.search(/\s*$/);
  272. var maxRow = session.getLength();
  273. var startRow = row;
  274. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  275. var depth = 1;
  276. while (++row < maxRow) {
  277. line = session.getLine(row);
  278. var m = re.exec(line);
  279. if (!m)
  280. continue;
  281. if (m[1])
  282. depth--;
  283. else
  284. depth++;
  285. if (!depth)
  286. break;
  287. }
  288. var endRow = row;
  289. if (endRow > startRow) {
  290. return new Range(startRow, startColumn, endRow, line.length);
  291. }
  292. };
  293. }).call(FoldMode.prototype);
  294. });
  295. ace.define("ace/mode/nim",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/nim_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module){"use strict";
  296. var oop = require("../lib/oop");
  297. var TextMode = require("./text").Mode;
  298. var NimHighlightRules = require("./nim_highlight_rules").NimHighlightRules;
  299. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  300. var Mode = function () {
  301. TextMode.call(this);
  302. this.HighlightRules = NimHighlightRules;
  303. this.foldingRules = new CStyleFoldMode();
  304. this.$behaviour = this.$defaultBehaviour;
  305. };
  306. oop.inherits(Mode, TextMode);
  307. (function () {
  308. this.lineCommentStart = "#";
  309. this.blockComment = { start: "#[", end: "]#", nestable: true };
  310. this.$id = "ace/mode/nim";
  311. }).call(Mode.prototype);
  312. exports.Mode = Mode;
  313. }); (function() {
  314. ace.require(["ace/mode/nim"], function(m) {
  315. if (typeof module == "object" && typeof exports == "object" && module) {
  316. module.exports = m;
  317. }
  318. });
  319. })();