mode-jssm.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. ace.define("ace/mode/jssm_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 JSSMHighlightRules = function() {
  6. this.$rules = {
  7. start: [{
  8. token: "punctuation.definition.comment.mn",
  9. regex: /\/\*/,
  10. push: [{
  11. token: "punctuation.definition.comment.mn",
  12. regex: /\*\//,
  13. next: "pop"
  14. }, {
  15. defaultToken: "comment.block.jssm"
  16. }],
  17. comment: "block comment"
  18. }, {
  19. token: "comment.line.jssm",
  20. regex: /\/\//,
  21. push: [{
  22. token: "comment.line.jssm",
  23. regex: /$/,
  24. next: "pop"
  25. }, {
  26. defaultToken: "comment.line.jssm"
  27. }],
  28. comment: "block comment"
  29. }, {
  30. token: "entity.name.function",
  31. regex: /\${/,
  32. push: [{
  33. token: "entity.name.function",
  34. regex: /}/,
  35. next: "pop"
  36. }, {
  37. defaultToken: "keyword.other"
  38. }],
  39. comment: "js outcalls"
  40. }, {
  41. token: "constant.numeric",
  42. regex: /[0-9]*\.[0-9]*\.[0-9]*/,
  43. comment: "semver"
  44. }, {
  45. token: "constant.language.jssmLanguage",
  46. regex: /graph_layout\s*:/,
  47. comment: "jssm language tokens"
  48. }, {
  49. token: "constant.language.jssmLanguage",
  50. regex: /machine_name\s*:/,
  51. comment: "jssm language tokens"
  52. }, {
  53. token: "constant.language.jssmLanguage",
  54. regex: /machine_version\s*:/,
  55. comment: "jssm language tokens"
  56. }, {
  57. token: "constant.language.jssmLanguage",
  58. regex: /jssm_version\s*:/,
  59. comment: "jssm language tokens"
  60. }, {
  61. token: "keyword.control.transition.jssmArrow.legal_legal",
  62. regex: /<->/,
  63. comment: "transitions"
  64. }, {
  65. token: "keyword.control.transition.jssmArrow.legal_none",
  66. regex: /<-/,
  67. comment: "transitions"
  68. }, {
  69. token: "keyword.control.transition.jssmArrow.none_legal",
  70. regex: /->/,
  71. comment: "transitions"
  72. }, {
  73. token: "keyword.control.transition.jssmArrow.main_main",
  74. regex: /<=>/,
  75. comment: "transitions"
  76. }, {
  77. token: "keyword.control.transition.jssmArrow.none_main",
  78. regex: /=>/,
  79. comment: "transitions"
  80. }, {
  81. token: "keyword.control.transition.jssmArrow.main_none",
  82. regex: /<=/,
  83. comment: "transitions"
  84. }, {
  85. token: "keyword.control.transition.jssmArrow.forced_forced",
  86. regex: /<~>/,
  87. comment: "transitions"
  88. }, {
  89. token: "keyword.control.transition.jssmArrow.none_forced",
  90. regex: /~>/,
  91. comment: "transitions"
  92. }, {
  93. token: "keyword.control.transition.jssmArrow.forced_none",
  94. regex: /<~/,
  95. comment: "transitions"
  96. }, {
  97. token: "keyword.control.transition.jssmArrow.legal_main",
  98. regex: /<-=>/,
  99. comment: "transitions"
  100. }, {
  101. token: "keyword.control.transition.jssmArrow.main_legal",
  102. regex: /<=->/,
  103. comment: "transitions"
  104. }, {
  105. token: "keyword.control.transition.jssmArrow.legal_forced",
  106. regex: /<-~>/,
  107. comment: "transitions"
  108. }, {
  109. token: "keyword.control.transition.jssmArrow.forced_legal",
  110. regex: /<~->/,
  111. comment: "transitions"
  112. }, {
  113. token: "keyword.control.transition.jssmArrow.main_forced",
  114. regex: /<=~>/,
  115. comment: "transitions"
  116. }, {
  117. token: "keyword.control.transition.jssmArrow.forced_main",
  118. regex: /<~=>/,
  119. comment: "transitions"
  120. }, {
  121. token: "constant.numeric.jssmProbability",
  122. regex: /[0-9]+%/,
  123. comment: "edge probability annotation"
  124. }, {
  125. token: "constant.character.jssmAction",
  126. regex: /\'[^']*\'/,
  127. comment: "action annotation"
  128. }, {
  129. token: "entity.name.tag.jssmLabel.doublequoted",
  130. regex: /\"[^"]*\"/,
  131. comment: "jssm label annotation"
  132. }, {
  133. token: "entity.name.tag.jssmLabel.atom",
  134. regex: /[a-zA-Z0-9_.+&()#@!?,]/,
  135. comment: "jssm label annotation"
  136. }]
  137. };
  138. this.normalizeRules();
  139. };
  140. JSSMHighlightRules.metaData = {
  141. fileTypes: ["jssm", "jssm_state"],
  142. name: "JSSM",
  143. scopeName: "source.jssm"
  144. };
  145. oop.inherits(JSSMHighlightRules, TextHighlightRules);
  146. exports.JSSMHighlightRules = JSSMHighlightRules;
  147. });
  148. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  149. "use strict";
  150. var oop = require("../../lib/oop");
  151. var Range = require("../../range").Range;
  152. var BaseFoldMode = require("./fold_mode").FoldMode;
  153. var FoldMode = exports.FoldMode = function(commentRegex) {
  154. if (commentRegex) {
  155. this.foldingStartMarker = new RegExp(
  156. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  157. );
  158. this.foldingStopMarker = new RegExp(
  159. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  160. );
  161. }
  162. };
  163. oop.inherits(FoldMode, BaseFoldMode);
  164. (function() {
  165. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  166. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  167. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  168. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  169. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  170. this._getFoldWidgetBase = this.getFoldWidget;
  171. this.getFoldWidget = function(session, foldStyle, row) {
  172. var line = session.getLine(row);
  173. if (this.singleLineBlockCommentRe.test(line)) {
  174. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  175. return "";
  176. }
  177. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  178. if (!fw && this.startRegionRe.test(line))
  179. return "start"; // lineCommentRegionStart
  180. return fw;
  181. };
  182. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  183. var line = session.getLine(row);
  184. if (this.startRegionRe.test(line))
  185. return this.getCommentRegionBlock(session, line, row);
  186. var match = line.match(this.foldingStartMarker);
  187. if (match) {
  188. var i = match.index;
  189. if (match[1])
  190. return this.openingBracketBlock(session, match[1], row, i);
  191. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  192. if (range && !range.isMultiLine()) {
  193. if (forceMultiline) {
  194. range = this.getSectionRange(session, row);
  195. } else if (foldStyle != "all")
  196. range = null;
  197. }
  198. return range;
  199. }
  200. if (foldStyle === "markbegin")
  201. return;
  202. var match = line.match(this.foldingStopMarker);
  203. if (match) {
  204. var i = match.index + match[0].length;
  205. if (match[1])
  206. return this.closingBracketBlock(session, match[1], row, i);
  207. return session.getCommentFoldRange(row, i, -1);
  208. }
  209. };
  210. this.getSectionRange = function(session, row) {
  211. var line = session.getLine(row);
  212. var startIndent = line.search(/\S/);
  213. var startRow = row;
  214. var startColumn = line.length;
  215. row = row + 1;
  216. var endRow = row;
  217. var maxRow = session.getLength();
  218. while (++row < maxRow) {
  219. line = session.getLine(row);
  220. var indent = line.search(/\S/);
  221. if (indent === -1)
  222. continue;
  223. if (startIndent > indent)
  224. break;
  225. var subRange = this.getFoldWidgetRange(session, "all", row);
  226. if (subRange) {
  227. if (subRange.start.row <= startRow) {
  228. break;
  229. } else if (subRange.isMultiLine()) {
  230. row = subRange.end.row;
  231. } else if (startIndent == indent) {
  232. break;
  233. }
  234. }
  235. endRow = row;
  236. }
  237. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  238. };
  239. this.getCommentRegionBlock = function(session, line, row) {
  240. var startColumn = line.search(/\s*$/);
  241. var maxRow = session.getLength();
  242. var startRow = row;
  243. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  244. var depth = 1;
  245. while (++row < maxRow) {
  246. line = session.getLine(row);
  247. var m = re.exec(line);
  248. if (!m) continue;
  249. if (m[1]) depth--;
  250. else depth++;
  251. if (!depth) break;
  252. }
  253. var endRow = row;
  254. if (endRow > startRow) {
  255. return new Range(startRow, startColumn, endRow, line.length);
  256. }
  257. };
  258. }).call(FoldMode.prototype);
  259. });
  260. ace.define("ace/mode/jssm",[], function(require, exports, module) {
  261. "use strict";
  262. var oop = require("../lib/oop");
  263. var TextMode = require("./text").Mode;
  264. var JSSMHighlightRules = require("./jssm_highlight_rules").JSSMHighlightRules;
  265. var FoldMode = require("./folding/cstyle").FoldMode;
  266. var Mode = function() {
  267. this.HighlightRules = JSSMHighlightRules;
  268. this.foldingRules = new FoldMode();
  269. };
  270. oop.inherits(Mode, TextMode);
  271. (function() {
  272. this.lineCommentStart = "//";
  273. this.blockComment = {start: "/*", end: "*/"};
  274. this.$id = "ace/mode/jssm";
  275. }).call(Mode.prototype);
  276. exports.Mode = Mode;
  277. });
  278. (function() {
  279. ace.require(["ace/mode/jssm"], function(m) {
  280. if (typeof module == "object" && typeof exports == "object" && module) {
  281. module.exports = m;
  282. }
  283. });
  284. })();