mode-red.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  1. ace.define("ace/mode/red_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 RedHighlightRules = function() {
  6. var compoundKeywords = "";
  7. this.$rules = {
  8. "start" : [
  9. {token : "keyword.operator",
  10. regex: /\s([\-+%/=<>*]|(?:\*\*\|\/\/|==|>>>?|<>|<<|=>|<=|=\?))(\s|(?=:))/},
  11. {token : "string.email", regex : /\w[-\w._]*\@\w[-\w._]*/},
  12. {token : "value.time", regex : /\b\d+:\d+(:\d+)?/},
  13. {token : "string.url", regex : /\w[-\w_]*\:(\/\/)?\w[-\w._]*(:\d+)?/},
  14. {token : "value.date", regex : /(\b\d{1,4}[-/]\d{1,2}[-/]\d{1,2}|\d{1,2}[-/]\d{1,2}[-/]\d{1,4})\b/},
  15. {token : "value.tuple", regex : /\b\d{1,3}\.\d{1,3}\.\d{1,3}(\.\d{1,3}){0,9}/},
  16. {token : "value.pair", regex: /[+-]?\d+x[-+]?\d+/},
  17. {token : "value.binary", regex : /\b2#{([01]{8})+}/},
  18. {token : "value.binary", regex : /\b64#{([\w/=+])+}/},
  19. {token : "value.binary", regex : /(16)?#{([\dabcdefABCDEF][\dabcdefABCDEF])*}/},
  20. {token : "value.issue", regex : /#\w[-\w'*.]*/},
  21. {token : "value.numeric", regex: /[+-]?\d['\d]*(?:\.\d+)?e[-+]?\d{1,3}\%?(?!\w)/},
  22. {token : "invalid.illegal", regex: /[+-]?\d['\d]*(?:\.\d+)?\%?[a-zA-Z]/},
  23. {token : "value.numeric", regex: /[+-]?\d['\d]*(?:\.\d+)?\%?(?![a-zA-Z])/},
  24. {token : "value.character", regex : /#"(\^[-@/_~^"HKLM\[]|.)"/},
  25. {token : "string.file", regex : /%[-\w\.\/]+/},
  26. {token : "string.tag", regex : /</, next : "tag"},
  27. {token : "string", regex : /"/, next : "string"},
  28. {token : "string.other", regex : "{", next : "string.other"},
  29. {token : "comment", regex : "comment [{]", next : "comment"},
  30. {token : "comment", regex : /;.+$/},
  31. {token : "paren.map-start", regex : "#\\("},
  32. {token : "paren.block-start", regex : "[\\[]"},
  33. {token : "paren.block-end", regex : "[\\]]"},
  34. {token : "paren.parens-start", regex : "[(]"},
  35. {token : "paren.parens-end", regex : "\\)"},
  36. {token : "keyword", regex : "/local|/external"},
  37. {token : "keyword.preprocessor", regex : "#(if|either|" +
  38. "switch|case|include|do|macrolocal|reset|process|trace)"},
  39. {token : "constant.datatype!", regex :
  40. "(?:datatype|unset|none|logic|block|paren|string|" +
  41. "file|url|char|integer|float|word|set-word|lit-word|" +
  42. "get-word|refinement|issue|native|action|op|function|" +
  43. "path|lit-path|set-path|get-path|routine|bitset|point|" +
  44. "object|typeset|error|vector|hash|pair|percent|tuple|" +
  45. "map|binary|time|tag|email|handle|date|image|event|" +
  46. "series|any-type|number|any-object|scalar|" +
  47. "any-string|any-word|any-function|any-block|any-list|" +
  48. "any-path|immediate|all-word|internal|external|default)!(?![-!?\\w~])"},
  49. {token : "keyword.function", regex :
  50. "\\b(?:collect|quote|on-parse-event|math|last|source|expand|" +
  51. "show|context|object|input|quit|dir|make-dir|cause-error|" +
  52. "error\\?|none\\?|block\\?|any-list\\?|word\\?|char\\?|" +
  53. "any-string\\?|series\\?|binary\\?|attempt|url\\?|" +
  54. "string\\?|suffix\\?|file\\?|object\\?|body-of|first|" +
  55. "second|third|mod|clean-path|dir\\?|to-red-file|" +
  56. "normalize-dir|list-dir|pad|empty\\?|dirize|offset\\?|" +
  57. "what-dir|expand-directives|load|split-path|change-dir|" +
  58. "to-file|path-thru|save|load-thru|View|float\\?|to-float|" +
  59. "charset|\\?|probe|set-word\\?|q|words-of|replace|repend|" +
  60. "react|function\\?|spec-of|unset\\?|halt|op\\?|" +
  61. "any-function\\?|to-paren|tag\\?|routine|class-of|" +
  62. "size-text|draw|handle\\?|link-tabs-to-parent|" +
  63. "link-sub-to-parent|on-face-deep-change*|" +
  64. "update-font-faces|do-actor|do-safe|do-events|pair\\?|" +
  65. "foreach-face|hex-to-rgb|issue\\?|alter|path\\?|" +
  66. "typeset\\?|datatype\\?|set-flag|layout|extract|image\\?|" +
  67. "get-word\\?|to-logic|to-set-word|to-block|center-face|" +
  68. "dump-face|request-font|request-file|request-dir|rejoin|" +
  69. "ellipsize-at|any-block\\?|any-object\\?|map\\?|keys-of|" +
  70. "a-an|also|parse-func-spec|help-string|what|routine\\?|" +
  71. "action\\?|native\\?|refinement\\?|common-substr|" +
  72. "red-complete-file|red-complete-path|unview|comment|\\?\\?|" +
  73. "fourth|fifth|values-of|bitset\\?|email\\?|get-path\\?|" +
  74. "hash\\?|integer\\?|lit-path\\?|lit-word\\?|logic\\?|" +
  75. "paren\\?|percent\\?|set-path\\?|time\\?|tuple\\?|date\\?|" +
  76. "vector\\?|any-path\\?|any-word\\?|number\\?|immediate\\?|" +
  77. "scalar\\?|all-word\\?|to-bitset|to-binary|to-char|to-email|" +
  78. "to-get-path|to-get-word|to-hash|to-integer|to-issue|" +
  79. "to-lit-path|to-lit-word|to-map|to-none|to-pair|to-path|" +
  80. "to-percent|to-refinement|to-set-path|to-string|to-tag|" +
  81. "to-time|to-typeset|to-tuple|to-unset|to-url|to-word|" +
  82. "to-image|to-date|parse-trace|modulo|eval-set-path|" +
  83. "extract-boot-args|flip-exe-flag|split|do-file|" +
  84. "exists-thru\\?|read-thru|do-thru|cos|sin|tan|acos|asin|" +
  85. "atan|atan2|sqrt|clear-reactions|dump-reactions|react\\?|" +
  86. "within\\?|overlap\\?|distance\\?|face\\?|metrics\\?|" +
  87. "get-scroller|insert-event-func|remove-event-func|" +
  88. "set-focus|help|fetch-help|about|ls|ll|pwd|cd|" +
  89. "red-complete-input|matrix)(?![-!?\\w~])"},
  90. {token : "keyword.action", regex :
  91. "\\b(?:to|remove|copy|insert|change|clear|move|poke|put|" +
  92. "random|reverse|sort|swap|take|trim|add|subtract|" +
  93. "divide|multiply|make|reflect|form|mold|modify|" +
  94. "absolute|negate|power|remainder|round|even\\?|odd\\?|" +
  95. "and~|complement|or~|xor~|append|at|back|find|skip|" +
  96. "tail|head|head\\?|index\\?|length\\?|next|pick|" +
  97. "select|tail\\?|delete|read|write)(?![-_!?\\w~])"
  98. },
  99. {token : "keyword.native", regex :
  100. "\\b(?:not|any|set|uppercase|lowercase|checksum|" +
  101. "try|catch|browse|throw|all|as|" +
  102. "remove-each|func|function|does|has|do|reduce|" +
  103. "compose|get|print|prin|equal\\?|not-equal\\?|" +
  104. "strict-equal\\?|lesser\\?|greater\\?|lesser-or-equal\\?|" +
  105. "greater-or-equal\\?|same\\?|type\\?|stats|bind|in|parse|" +
  106. "union|unique|intersect|difference|exclude|" +
  107. "complement\\?|dehex|negative\\?|positive\\?|max|min|" +
  108. "shift|to-hex|sine|cosine|tangent|arcsine|arccosine|" +
  109. "arctangent|arctangent2|NaN\\?|zero\\?|log-2|log-10|log-e|" +
  110. "exp|square-root|construct|value\\?|as-pair|" +
  111. "extend|debase|enbase|to-local-file|" +
  112. "wait|unset|new-line|new-line\\?|context\\?|set-env|" +
  113. "get-env|list-env|now|sign\\?|call|size\\?)(?![-!?\\w~])"
  114. },
  115. {token : "keyword", regex :
  116. "\\b(?:Red(?=\\s+\\[)|object|context|make|self|keep)(?![-!?\\w~])"
  117. },
  118. {token: "variable.language", regex : "this"},
  119. {token: "keyword.control", regex :
  120. "(?:while|if|return|case|unless|either|until|loop|repeat|" +
  121. "forever|foreach|forall|switch|break|continue|exit)(?![-!?\\w~])"},
  122. {token: "constant.language", regex :
  123. "\\b(?:true|false|on|off|yes|none|no)(?![-!?\\w~])"},
  124. {token: "constant.numeric", regex : /\bpi(?![^-_])/},
  125. {token: "constant.character", regex : "\\b(space|tab|newline|cr|lf)(?![-!?\\w~])"},
  126. {token: "keyword.operator", regex : "\s(or|and|xor|is)\s"},
  127. {token : "variable.get-path", regex : /:\w[-\w'*.?!]*(\/\w[-\w'*.?!]*)(\/\w[-\w'*.?!]*)*/},
  128. {token : "variable.set-path", regex : /\w[-\w'*.?!]*(\/\w[-\w'*.?!]*)(\/\w[-\w'*.?!]*)*:/},
  129. {token : "variable.lit-path", regex : /'\w[-\w'*.?!]*(\/\w[-\w'*.?!]*)(\/\w[-\w'*.?!]*)*/},
  130. {token : "variable.path", regex : /\w[-\w'*.?!]*(\/\w[-\w'*.?!]*)(\/\w[-\w'*.?!]*)*/},
  131. {token : "variable.refinement", regex : /\/\w[-\w'*.?!]*/},
  132. {token : "keyword.view.style", regex :
  133. "\\b(?:window|base|button|text|field|area|check|" +
  134. "radio|progress|slider|camera|text-list|" +
  135. "drop-list|drop-down|panel|group-box|" +
  136. "tab-panel|h1|h2|h3|h4|h5|box|image|init)(?![-!?\\w~])"},
  137. {token : "keyword.view.event", regex :
  138. "\\b(?:detect|on-detect|time|on-time|drawing|on-drawing|" +
  139. "scroll|on-scroll|down|on-down|up|on-up|mid-down|" +
  140. "on-mid-down|mid-up|on-mid-up|alt-down|on-alt-down|" +
  141. "alt-up|on-alt-up|aux-down|on-aux-down|aux-up|" +
  142. "on-aux-up|wheel|on-wheel|drag-start|on-drag-start|" +
  143. "drag|on-drag|drop|on-drop|click|on-click|dbl-click|" +
  144. "on-dbl-click|over|on-over|key|on-key|key-down|" +
  145. "on-key-down|key-up|on-key-up|ime|on-ime|focus|" +
  146. "on-focus|unfocus|on-unfocus|select|on-select|" +
  147. "change|on-change|enter|on-enter|menu|on-menu|close|" +
  148. "on-close|move|on-move|resize|on-resize|moving|" +
  149. "on-moving|resizing|on-resizing|zoom|on-zoom|pan|" +
  150. "on-pan|rotate|on-rotate|two-tap|on-two-tap|" +
  151. "press-tap|on-press-tap|create|on-create|created|on-created)(?![-!?\\w~])"},
  152. {token : "keyword.view.option", regex :
  153. "\\b(?:all-over|center|color|default|disabled|down|" +
  154. "flags|focus|font|font-color|font-name|" +
  155. "font-size|hidden|hint|left|loose|name|" +
  156. "no-border|now|rate|react|select|size|space)(?![-!?\\w~])"},
  157. {token : "constant.other.colour", regex : "\\b(?:Red|white|transparent|" +
  158. "black|gray|aqua|beige|blue|brick|brown|coal|coffee|" +
  159. "crimson|cyan|forest|gold|green|ivory|khaki|leaf|linen|" +
  160. "magenta|maroon|mint|navy|oldrab|olive|orange|papaya|" +
  161. "pewter|pink|purple|reblue|rebolor|sienna|silver|sky|" +
  162. "snow|tanned|teal|violet|water|wheat|yello|yellow|glass)(?![-!?\\w~])"},
  163. {token : "variable.get-word", regex : /\:\w[-\w'*.?!]*/},
  164. {token : "variable.set-word", regex : /\w[-\w'*.?!]*\:/},
  165. {token : "variable.lit-word", regex : /'\w[-\w'*.?!]*/},
  166. {token : "variable.word", regex : /\b\w+[-\w'*.!?]*/},
  167. {caseInsensitive: true}
  168. ],
  169. "string" : [
  170. {token : "string", regex : /"/, next : "start"},
  171. {defaultToken : "string"}
  172. ],
  173. "string.other" : [
  174. {token : "string.other", regex : /}/, next : "start"},
  175. {defaultToken : "string.other"}
  176. ],
  177. "tag" : [
  178. {token : "string.tag", regex : />/, next : "start"},
  179. {defaultToken : "string.tag"}
  180. ],
  181. "comment" : [
  182. {token : "comment", regex : /}/, next : "start"},
  183. {defaultToken : "comment"}
  184. ]
  185. };
  186. };
  187. oop.inherits(RedHighlightRules, TextHighlightRules);
  188. exports.RedHighlightRules = RedHighlightRules;
  189. });
  190. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  191. "use strict";
  192. var oop = require("../../lib/oop");
  193. var Range = require("../../range").Range;
  194. var BaseFoldMode = require("./fold_mode").FoldMode;
  195. var FoldMode = exports.FoldMode = function(commentRegex) {
  196. if (commentRegex) {
  197. this.foldingStartMarker = new RegExp(
  198. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  199. );
  200. this.foldingStopMarker = new RegExp(
  201. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  202. );
  203. }
  204. };
  205. oop.inherits(FoldMode, BaseFoldMode);
  206. (function() {
  207. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  208. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  209. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  210. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  211. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  212. this._getFoldWidgetBase = this.getFoldWidget;
  213. this.getFoldWidget = function(session, foldStyle, row) {
  214. var line = session.getLine(row);
  215. if (this.singleLineBlockCommentRe.test(line)) {
  216. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  217. return "";
  218. }
  219. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  220. if (!fw && this.startRegionRe.test(line))
  221. return "start"; // lineCommentRegionStart
  222. return fw;
  223. };
  224. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  225. var line = session.getLine(row);
  226. if (this.startRegionRe.test(line))
  227. return this.getCommentRegionBlock(session, line, row);
  228. var match = line.match(this.foldingStartMarker);
  229. if (match) {
  230. var i = match.index;
  231. if (match[1])
  232. return this.openingBracketBlock(session, match[1], row, i);
  233. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  234. if (range && !range.isMultiLine()) {
  235. if (forceMultiline) {
  236. range = this.getSectionRange(session, row);
  237. } else if (foldStyle != "all")
  238. range = null;
  239. }
  240. return range;
  241. }
  242. if (foldStyle === "markbegin")
  243. return;
  244. var match = line.match(this.foldingStopMarker);
  245. if (match) {
  246. var i = match.index + match[0].length;
  247. if (match[1])
  248. return this.closingBracketBlock(session, match[1], row, i);
  249. return session.getCommentFoldRange(row, i, -1);
  250. }
  251. };
  252. this.getSectionRange = function(session, row) {
  253. var line = session.getLine(row);
  254. var startIndent = line.search(/\S/);
  255. var startRow = row;
  256. var startColumn = line.length;
  257. row = row + 1;
  258. var endRow = row;
  259. var maxRow = session.getLength();
  260. while (++row < maxRow) {
  261. line = session.getLine(row);
  262. var indent = line.search(/\S/);
  263. if (indent === -1)
  264. continue;
  265. if (startIndent > indent)
  266. break;
  267. var subRange = this.getFoldWidgetRange(session, "all", row);
  268. if (subRange) {
  269. if (subRange.start.row <= startRow) {
  270. break;
  271. } else if (subRange.isMultiLine()) {
  272. row = subRange.end.row;
  273. } else if (startIndent == indent) {
  274. break;
  275. }
  276. }
  277. endRow = row;
  278. }
  279. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  280. };
  281. this.getCommentRegionBlock = function(session, line, row) {
  282. var startColumn = line.search(/\s*$/);
  283. var maxRow = session.getLength();
  284. var startRow = row;
  285. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  286. var depth = 1;
  287. while (++row < maxRow) {
  288. line = session.getLine(row);
  289. var m = re.exec(line);
  290. if (!m) continue;
  291. if (m[1]) depth--;
  292. else depth++;
  293. if (!depth) break;
  294. }
  295. var endRow = row;
  296. if (endRow > startRow) {
  297. return new Range(startRow, startColumn, endRow, line.length);
  298. }
  299. };
  300. }).call(FoldMode.prototype);
  301. });
  302. ace.define("ace/mode/matching_brace_outdent",[], function(require, exports, module) {
  303. "use strict";
  304. var Range = require("../range").Range;
  305. var MatchingBraceOutdent = function() {};
  306. (function() {
  307. this.checkOutdent = function(line, input) {
  308. if (! /^\s+$/.test(line))
  309. return false;
  310. return /^\s*\}/.test(input);
  311. };
  312. this.autoOutdent = function(doc, row) {
  313. var line = doc.getLine(row);
  314. var match = line.match(/^(\s*\})/);
  315. if (!match) return 0;
  316. var column = match[1].length;
  317. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  318. if (!openBracePos || openBracePos.row == row) return 0;
  319. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  320. doc.replace(new Range(row, 0, row, column-1), indent);
  321. };
  322. this.$getIndent = function(line) {
  323. return line.match(/^\s*/)[0];
  324. };
  325. }).call(MatchingBraceOutdent.prototype);
  326. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  327. });
  328. ace.define("ace/mode/red",[], function(require, exports, module) {
  329. "use strict";
  330. var oop = require("../lib/oop");
  331. var TextMode = require("./text").Mode;
  332. var RedHighlightRules = require("./red_highlight_rules").RedHighlightRules;
  333. var RedFoldMode = require("./folding/cstyle").FoldMode;
  334. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  335. var Range = require("../range").Range;
  336. var Mode = function() {
  337. this.HighlightRules = RedHighlightRules;
  338. this.foldingRules = new RedFoldMode();
  339. this.$outdent = new MatchingBraceOutdent();
  340. this.$behaviour = this.$defaultBehaviour;
  341. };
  342. oop.inherits(Mode, TextMode);
  343. (function() {
  344. this.lineCommentStart = ";";
  345. this.blockComment = { start: "comment {", end: "}" };
  346. this.getNextLineIndent = function(state, line, tab) {
  347. var indent = this.$getIndent(line);
  348. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  349. var tokens = tokenizedLine.tokens;
  350. var endState = tokenizedLine.state;
  351. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  352. return indent;
  353. }
  354. if (state == "start") {
  355. var match = line.match(/^.*[\{\[\(]\s*$/);
  356. if (match) {
  357. indent += tab;
  358. }
  359. } else if (state == "doc-start") {
  360. if (endState == "start") {
  361. return "";
  362. }
  363. var match = line.match(/^\s*(\/?)\*/);
  364. if (match) {
  365. if (match[1]) {
  366. indent += " ";
  367. }
  368. indent += "* ";
  369. }
  370. }
  371. return indent;
  372. };
  373. this.checkOutdent = function(state, line, input) {
  374. return this.$outdent.checkOutdent(line, input);
  375. };
  376. this.autoOutdent = function(state, doc, row) {
  377. this.$outdent.autoOutdent(doc, row);
  378. };
  379. this.$id = "ace/mode/red";
  380. }).call(Mode.prototype);
  381. exports.Mode = Mode;
  382. });
  383. (function() {
  384. ace.require(["ace/mode/red"], function(m) {
  385. if (typeof module == "object" && typeof exports == "object" && module) {
  386. module.exports = m;
  387. }
  388. });
  389. })();