mode-fsl.js 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. ace.define("ace/mode/fsl_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 FSLHighlightRules = 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.fsl"
  16. }]
  17. }, {
  18. token: "comment.line.fsl",
  19. regex: /\/\//,
  20. push: [{
  21. token: "comment.line.fsl",
  22. regex: /$/,
  23. next: "pop"
  24. }, {
  25. defaultToken: "comment.line.fsl"
  26. }]
  27. }, {
  28. token: "entity.name.function",
  29. regex: /\${/,
  30. push: [{
  31. token: "entity.name.function",
  32. regex: /}/,
  33. next: "pop"
  34. }, {
  35. defaultToken: "keyword.other"
  36. }],
  37. comment: "js outcalls"
  38. }, {
  39. token: "constant.numeric",
  40. regex: /[0-9]*\.[0-9]*\.[0-9]*/,
  41. comment: "semver"
  42. }, {
  43. token: "constant.language.fslLanguage",
  44. regex: "(?:"
  45. + "graph_layout|machine_name|machine_author|machine_license|machine_comment|machine_language"
  46. + "|machine_version|machine_reference|npm_name|graph_layout|on_init|on_halt|on_end|on_terminate|on_finalize|on_transition"
  47. + "|on_action|on_stochastic_action|on_legal|on_main|on_forced|on_validation|on_validation_failure|on_transition_refused|on_forced_transition_refused"
  48. + "|on_action_refused|on_enter|on_exit|start_states|end_states|terminal_states|final_states|fsl_version"
  49. + ")\\s*:"
  50. }, {
  51. token: "keyword.control.transition.fslArrow",
  52. regex: /<->|<-|->|<=>|=>|<=|<~>|~>|<~|<-=>|<=->|<-~>|<~->|<=~>|<~=>/
  53. }, {
  54. token: "constant.numeric.fslProbability",
  55. regex: /[0-9]+%/,
  56. comment: "edge probability annotation"
  57. }, {
  58. token: "constant.character.fslAction",
  59. regex: /\'[^']*\'/,
  60. comment: "action annotation"
  61. }, {
  62. token: "string.quoted.double.fslLabel.doublequoted",
  63. regex: /\"[^"]*\"/,
  64. comment: "fsl label annotation"
  65. }, {
  66. token: "entity.name.tag.fslLabel.atom",
  67. regex: /[a-zA-Z0-9_.+&()#@!?,]/,
  68. comment: "fsl label annotation"
  69. }]
  70. };
  71. this.normalizeRules();
  72. };
  73. FSLHighlightRules.metaData = {
  74. fileTypes: ["fsl", "fsl_state"],
  75. name: "FSL",
  76. scopeName: "source.fsl"
  77. };
  78. oop.inherits(FSLHighlightRules, TextHighlightRules);
  79. exports.FSLHighlightRules = FSLHighlightRules;
  80. });
  81. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  82. "use strict";
  83. var oop = require("../../lib/oop");
  84. var Range = require("../../range").Range;
  85. var BaseFoldMode = require("./fold_mode").FoldMode;
  86. var FoldMode = exports.FoldMode = function(commentRegex) {
  87. if (commentRegex) {
  88. this.foldingStartMarker = new RegExp(
  89. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  90. );
  91. this.foldingStopMarker = new RegExp(
  92. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  93. );
  94. }
  95. };
  96. oop.inherits(FoldMode, BaseFoldMode);
  97. (function() {
  98. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  99. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  100. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  101. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  102. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  103. this._getFoldWidgetBase = this.getFoldWidget;
  104. this.getFoldWidget = function(session, foldStyle, row) {
  105. var line = session.getLine(row);
  106. if (this.singleLineBlockCommentRe.test(line)) {
  107. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  108. return "";
  109. }
  110. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  111. if (!fw && this.startRegionRe.test(line))
  112. return "start"; // lineCommentRegionStart
  113. return fw;
  114. };
  115. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  116. var line = session.getLine(row);
  117. if (this.startRegionRe.test(line))
  118. return this.getCommentRegionBlock(session, line, row);
  119. var match = line.match(this.foldingStartMarker);
  120. if (match) {
  121. var i = match.index;
  122. if (match[1])
  123. return this.openingBracketBlock(session, match[1], row, i);
  124. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  125. if (range && !range.isMultiLine()) {
  126. if (forceMultiline) {
  127. range = this.getSectionRange(session, row);
  128. } else if (foldStyle != "all")
  129. range = null;
  130. }
  131. return range;
  132. }
  133. if (foldStyle === "markbegin")
  134. return;
  135. var match = line.match(this.foldingStopMarker);
  136. if (match) {
  137. var i = match.index + match[0].length;
  138. if (match[1])
  139. return this.closingBracketBlock(session, match[1], row, i);
  140. return session.getCommentFoldRange(row, i, -1);
  141. }
  142. };
  143. this.getSectionRange = function(session, row) {
  144. var line = session.getLine(row);
  145. var startIndent = line.search(/\S/);
  146. var startRow = row;
  147. var startColumn = line.length;
  148. row = row + 1;
  149. var endRow = row;
  150. var maxRow = session.getLength();
  151. while (++row < maxRow) {
  152. line = session.getLine(row);
  153. var indent = line.search(/\S/);
  154. if (indent === -1)
  155. continue;
  156. if (startIndent > indent)
  157. break;
  158. var subRange = this.getFoldWidgetRange(session, "all", row);
  159. if (subRange) {
  160. if (subRange.start.row <= startRow) {
  161. break;
  162. } else if (subRange.isMultiLine()) {
  163. row = subRange.end.row;
  164. } else if (startIndent == indent) {
  165. break;
  166. }
  167. }
  168. endRow = row;
  169. }
  170. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  171. };
  172. this.getCommentRegionBlock = function(session, line, row) {
  173. var startColumn = line.search(/\s*$/);
  174. var maxRow = session.getLength();
  175. var startRow = row;
  176. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  177. var depth = 1;
  178. while (++row < maxRow) {
  179. line = session.getLine(row);
  180. var m = re.exec(line);
  181. if (!m) continue;
  182. if (m[1]) depth--;
  183. else depth++;
  184. if (!depth) break;
  185. }
  186. var endRow = row;
  187. if (endRow > startRow) {
  188. return new Range(startRow, startColumn, endRow, line.length);
  189. }
  190. };
  191. }).call(FoldMode.prototype);
  192. });
  193. ace.define("ace/mode/fsl",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/fsl_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  194. "use strict";
  195. var oop = require("../lib/oop");
  196. var TextMode = require("./text").Mode;
  197. var FSLHighlightRules = require("./fsl_highlight_rules").FSLHighlightRules;
  198. var FoldMode = require("./folding/cstyle").FoldMode;
  199. var Mode = function() {
  200. this.HighlightRules = FSLHighlightRules;
  201. this.foldingRules = new FoldMode();
  202. };
  203. oop.inherits(Mode, TextMode);
  204. (function() {
  205. this.lineCommentStart = "//";
  206. this.blockComment = {start: "/*", end: "*/"};
  207. this.$id = "ace/mode/fsl";
  208. this.snippetFileId = "ace/snippets/fsl";
  209. }).call(Mode.prototype);
  210. exports.Mode = Mode;
  211. }); (function() {
  212. ace.require(["ace/mode/fsl"], function(m) {
  213. if (typeof module == "object" && typeof exports == "object" && module) {
  214. module.exports = m;
  215. }
  216. });
  217. })();