mode-gherkin.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. define("ace/mode/gherkin_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(ace_require, exports, module) {
  2. var oop = ace_require("../lib/oop");
  3. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  4. var stringEscape = "\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})";
  5. var GherkinHighlightRules = function() {
  6. var languages = [{
  7. name: "en",
  8. labels: "Feature|Background|Scenario(?: Outline)?|Examples",
  9. keywords: "Given|When|Then|And|But"
  10. }];
  11. var labels = languages.map(function(l) {
  12. return l.labels;
  13. }).join("|");
  14. var keywords = languages.map(function(l) {
  15. return l.keywords;
  16. }).join("|");
  17. this.$rules = {
  18. start : [{
  19. token: "constant.numeric",
  20. regex: "(?:(?:[1-9]\\d*)|(?:0))"
  21. }, {
  22. token : "comment",
  23. regex : "#.*$"
  24. }, {
  25. token : "keyword",
  26. regex : "(?:" + labels + "):|(?:" + keywords + ")\\b"
  27. }, {
  28. token : "keyword",
  29. regex : "\\*"
  30. }, {
  31. token : "string", // multi line """ string start
  32. regex : '"{3}',
  33. next : "qqstring3"
  34. }, {
  35. token : "string", // " string
  36. regex : '"',
  37. next : "qqstring"
  38. }, {
  39. token : "text",
  40. regex : "^\\s*(?=@[\\w])",
  41. next : [{
  42. token : "text",
  43. regex : "\\s+"
  44. }, {
  45. token : "variable.parameter",
  46. regex : "@[\\w]+"
  47. }, {
  48. token : "empty",
  49. regex : "",
  50. next : "start"
  51. }]
  52. }, {
  53. token : "comment",
  54. regex : "<[^>]+>"
  55. }, {
  56. token : "comment",
  57. regex : "\\|(?=.)",
  58. next : "table-item"
  59. }, {
  60. token : "comment",
  61. regex : "\\|$",
  62. next : "start"
  63. }],
  64. "qqstring3" : [ {
  65. token : "constant.language.escape",
  66. regex : stringEscape
  67. }, {
  68. token : "string", // multi line """ string end
  69. regex : '"{3}',
  70. next : "start"
  71. }, {
  72. defaultToken : "string"
  73. }],
  74. "qqstring" : [{
  75. token : "constant.language.escape",
  76. regex : stringEscape
  77. }, {
  78. token : "string",
  79. regex : "\\\\$",
  80. next : "qqstring"
  81. }, {
  82. token : "string",
  83. regex : '"|$',
  84. next : "start"
  85. }, {
  86. defaultToken: "string"
  87. }],
  88. "table-item" : [{
  89. token : "comment",
  90. regex : /$/,
  91. next : "start"
  92. }, {
  93. token : "comment",
  94. regex : /\|/
  95. }, {
  96. token : "string",
  97. regex : /\\./
  98. }, {
  99. defaultToken : "string"
  100. }]
  101. };
  102. this.normalizeRules();
  103. };
  104. oop.inherits(GherkinHighlightRules, TextHighlightRules);
  105. exports.GherkinHighlightRules = GherkinHighlightRules;
  106. });
  107. define("ace/mode/gherkin",["ace_require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/gherkin_highlight_rules"], function(ace_require, exports, module) {
  108. var oop = ace_require("../lib/oop");
  109. var TextMode = ace_require("./text").Mode;
  110. var GherkinHighlightRules = ace_require("./gherkin_highlight_rules").GherkinHighlightRules;
  111. var Mode = function() {
  112. this.HighlightRules = GherkinHighlightRules;
  113. this.$behaviour = this.$defaultBehaviour;
  114. };
  115. oop.inherits(Mode, TextMode);
  116. (function() {
  117. this.lineCommentStart = "#";
  118. this.$id = "ace/mode/gherkin";
  119. this.getNextLineIndent = function(state, line, tab) {
  120. var indent = this.$getIndent(line);
  121. var space2 = " ";
  122. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  123. var tokens = tokenizedLine.tokens;
  124. if(line.match("[ ]*\\|")) {
  125. indent += "| ";
  126. }
  127. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  128. return indent;
  129. }
  130. if (state == "start") {
  131. if (line.match("Scenario:|Feature:|Scenario Outline:|Background:")) {
  132. indent += space2;
  133. } else if(line.match("(Given|Then).+(:)$|Examples:")) {
  134. indent += space2;
  135. } else if(line.match("\\*.+")) {
  136. indent += "* ";
  137. }
  138. }
  139. return indent;
  140. };
  141. }).call(Mode.prototype);
  142. exports.Mode = Mode;
  143. }); (function() {
  144. window.ace_require(["ace/mode/gherkin"], function(m) {
  145. if (typeof module == "object" && typeof exports == "object" && module) {
  146. module.exports = m;
  147. }
  148. });
  149. })();