mode-nim.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. ace.define("ace/mode/nim_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function (require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var NimHighlightRules = function () {
  6. var keywordMapper = this.createKeywordMapper({
  7. "variable": "var|let|const",
  8. "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",
  9. "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",
  10. "support.function": "lock|ze|toU8|toU16|toU32|ord|low|len|high|add|pop|contains|card|incl|excl|dealloc|inc",
  11. "constant.language": "nil|true|false"
  12. }, "identifier");
  13. var hexNumber = "(?:0[xX][\\dA-Fa-f][\\dA-Fa-f_]*)";
  14. var decNumber = "(?:[0-9][\\d_]*)";
  15. var octNumber = "(?:0o[0-7][0-7_]*)";
  16. var binNumber = "(?:0[bB][01][01_]*)";
  17. var intNumber = "(?:" + hexNumber + "|" + decNumber + "|" + octNumber + "|" + binNumber + ")(?:'?[iIuU](?:8|16|32|64)|u)?\\b";
  18. var exponent = "(?:[eE][+-]?[\\d][\\d_]*)";
  19. var floatNumber = "(?:[\\d][\\d_]*(?:[.][\\d](?:[\\d_]*)" + exponent + "?)|" + exponent + ")";
  20. var floatNumberExt = "(?:" + hexNumber + "(?:'(?:(?:[fF](?:32|64)?)|[dD])))|(?:" + floatNumber + "|" + decNumber + "|" + octNumber + "|" + binNumber + ")(?:'(?:(?:[fF](?:32|64)?)|[dD]))";
  21. 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})";
  22. var identifier = '[a-zA-Z][a-zA-Z0-9_]*';
  23. this.$rules = {
  24. "start": [{
  25. token: ["identifier", "keyword.operator", "support.function"],
  26. regex: "(" + identifier + ")([.]{1})(" + identifier + ")(?=\\()"
  27. }, {//pragmas
  28. token: "paren.lparen",
  29. regex: "(\\{\\.)",
  30. next: [{
  31. token: "paren.rparen",
  32. regex: '(\\.\\}|\\})',
  33. next: "start"
  34. }, {
  35. include: "methods"
  36. }, {
  37. token: "identifier",
  38. regex: identifier
  39. }, {
  40. token: "punctuation",
  41. regex: /[,]/
  42. }, {
  43. token: "keyword.operator",
  44. regex: /[=:.]/
  45. }, {
  46. token: "paren.lparen",
  47. regex: /[[(]/
  48. }, {
  49. token: "paren.rparen",
  50. regex: /[\])]/
  51. }, {
  52. include: "math"
  53. }, {
  54. include: "strings"
  55. }, {
  56. defaultToken: "text"
  57. }]
  58. }, {
  59. token: "comment.doc.start",
  60. regex: /##\[(?!])/,
  61. push: "docBlockComment"
  62. }, {
  63. token: "comment.start",
  64. regex: /#\[(?!])/,
  65. push: "blockComment"
  66. }, {
  67. token: "comment.doc",
  68. regex: '##.*$'
  69. }, {
  70. token: "comment",
  71. regex: '#.*$'
  72. }, {
  73. include: "strings"
  74. }, {// character
  75. token: "string",
  76. 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})?'"
  77. }, {
  78. include: "methods"
  79. }, {
  80. token: keywordMapper,
  81. regex: "[a-zA-Z][a-zA-Z0-9_]*\\b"
  82. }, {
  83. token: ["keyword.operator", "text", "storage.type"],
  84. regex: "([:])(\\s+)(" + identifier + ")(?=$|\\)|\\[|,|\\s+=|;|\\s+\\{)"
  85. }, {
  86. token: "paren.lparen",
  87. regex: /\[\.|{\||\(\.|\[:|[[({`]/
  88. }, {
  89. token: "paren.rparen",
  90. regex: /\.\)|\|}|\.]|[\])}]/
  91. }, {
  92. token: "keyword.operator",
  93. regex: /[=+\-*\/<>@$~&%|!?^.:\\]/
  94. }, {
  95. token: "punctuation",
  96. regex: /[,;]/
  97. }, {
  98. include: "math"
  99. }],
  100. blockComment: [{
  101. regex: /#\[]/,
  102. token: "comment"
  103. }, {
  104. regex: /#\[(?!])/,
  105. token: "comment.start",
  106. push: "blockComment"
  107. }, {
  108. regex: /]#/,
  109. token: "comment.end",
  110. next: "pop"
  111. }, {
  112. defaultToken: "comment"
  113. }],
  114. docBlockComment: [{
  115. regex: /##\[]/,
  116. token: "comment.doc"
  117. }, {
  118. regex: /##\[(?!])/,
  119. token: "comment.doc.start",
  120. push: "docBlockComment"
  121. }, {
  122. regex: /]##/,
  123. token: "comment.doc.end",
  124. next: "pop"
  125. }, {
  126. defaultToken: "comment.doc"
  127. }],
  128. math: [{
  129. token: "constant.float",
  130. regex: floatNumberExt
  131. }, {
  132. token: "constant.float",
  133. regex: floatNumber
  134. }, {
  135. token: "constant.integer",
  136. regex: intNumber
  137. }],
  138. methods: [{
  139. token: "support.function",
  140. regex: "(\\w+)(?=\\()"
  141. }],
  142. strings: [{
  143. token: "string",
  144. regex: '(\\b' + identifier + ')?"""',
  145. push: [{
  146. token: "string",
  147. regex: '"""',
  148. next: "pop"
  149. }, {
  150. defaultToken: "string"
  151. }]
  152. }, {
  153. token: "string",
  154. regex: "\\b" + identifier + '"(?=.)',
  155. push: [{
  156. token: "string",
  157. regex: '"|$',
  158. next: "pop"
  159. }, {
  160. defaultToken: "string"
  161. }]
  162. }, {
  163. token: "string",
  164. regex: '"',
  165. push: [{
  166. token: "string",
  167. regex: '"|$',
  168. next: "pop"
  169. }, {
  170. token: "constant.language.escape",
  171. regex: stringEscape
  172. }, {
  173. defaultToken: "string"
  174. }]
  175. }]
  176. };
  177. this.normalizeRules();
  178. };
  179. oop.inherits(NimHighlightRules, TextHighlightRules);
  180. exports.NimHighlightRules = NimHighlightRules;
  181. });
  182. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  183. "use strict";
  184. var oop = require("../../lib/oop");
  185. var Range = require("../../range").Range;
  186. var BaseFoldMode = require("./fold_mode").FoldMode;
  187. var FoldMode = exports.FoldMode = function(commentRegex) {
  188. if (commentRegex) {
  189. this.foldingStartMarker = new RegExp(
  190. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  191. );
  192. this.foldingStopMarker = new RegExp(
  193. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  194. );
  195. }
  196. };
  197. oop.inherits(FoldMode, BaseFoldMode);
  198. (function() {
  199. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  200. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  201. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  202. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  203. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  204. this._getFoldWidgetBase = this.getFoldWidget;
  205. this.getFoldWidget = function(session, foldStyle, row) {
  206. var line = session.getLine(row);
  207. if (this.singleLineBlockCommentRe.test(line)) {
  208. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  209. return "";
  210. }
  211. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  212. if (!fw && this.startRegionRe.test(line))
  213. return "start"; // lineCommentRegionStart
  214. return fw;
  215. };
  216. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  217. var line = session.getLine(row);
  218. if (this.startRegionRe.test(line))
  219. return this.getCommentRegionBlock(session, line, row);
  220. var match = line.match(this.foldingStartMarker);
  221. if (match) {
  222. var i = match.index;
  223. if (match[1])
  224. return this.openingBracketBlock(session, match[1], row, i);
  225. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  226. if (range && !range.isMultiLine()) {
  227. if (forceMultiline) {
  228. range = this.getSectionRange(session, row);
  229. } else if (foldStyle != "all")
  230. range = null;
  231. }
  232. return range;
  233. }
  234. if (foldStyle === "markbegin")
  235. return;
  236. var match = line.match(this.foldingStopMarker);
  237. if (match) {
  238. var i = match.index + match[0].length;
  239. if (match[1])
  240. return this.closingBracketBlock(session, match[1], row, i);
  241. return session.getCommentFoldRange(row, i, -1);
  242. }
  243. };
  244. this.getSectionRange = function(session, row) {
  245. var line = session.getLine(row);
  246. var startIndent = line.search(/\S/);
  247. var startRow = row;
  248. var startColumn = line.length;
  249. row = row + 1;
  250. var endRow = row;
  251. var maxRow = session.getLength();
  252. while (++row < maxRow) {
  253. line = session.getLine(row);
  254. var indent = line.search(/\S/);
  255. if (indent === -1)
  256. continue;
  257. if (startIndent > indent)
  258. break;
  259. var subRange = this.getFoldWidgetRange(session, "all", row);
  260. if (subRange) {
  261. if (subRange.start.row <= startRow) {
  262. break;
  263. } else if (subRange.isMultiLine()) {
  264. row = subRange.end.row;
  265. } else if (startIndent == indent) {
  266. break;
  267. }
  268. }
  269. endRow = row;
  270. }
  271. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  272. };
  273. this.getCommentRegionBlock = function(session, line, row) {
  274. var startColumn = line.search(/\s*$/);
  275. var maxRow = session.getLength();
  276. var startRow = row;
  277. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  278. var depth = 1;
  279. while (++row < maxRow) {
  280. line = session.getLine(row);
  281. var m = re.exec(line);
  282. if (!m) continue;
  283. if (m[1]) depth--;
  284. else depth++;
  285. if (!depth) break;
  286. }
  287. var endRow = row;
  288. if (endRow > startRow) {
  289. return new Range(startRow, startColumn, endRow, line.length);
  290. }
  291. };
  292. }).call(FoldMode.prototype);
  293. });
  294. 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) {
  295. "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. })();