60d06d7e01bd491fa7376e70f9859545.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. ace.define("ace/mode/gherkin_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){var oop = require("../lib/oop");
  2. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  3. var stringEscape = "\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})";
  4. var GherkinHighlightRules = function () {
  5. var languages = [{
  6. name: "en",
  7. labels: "Feature|Background|Scenario(?: Outline)?|Examples",
  8. keywords: "Given|When|Then|And|But"
  9. }
  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",
  32. regex: '"{3}',
  33. next: "qqstring3"
  34. }, {
  35. token: "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",
  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. ace.define("ace/mode/gherkin",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/gherkin_highlight_rules"], function(require, exports, module){var oop = require("../lib/oop");
  108. var TextMode = require("./text").Mode;
  109. var GherkinHighlightRules = require("./gherkin_highlight_rules").GherkinHighlightRules;
  110. var Mode = function () {
  111. this.HighlightRules = GherkinHighlightRules;
  112. this.$behaviour = this.$defaultBehaviour;
  113. };
  114. oop.inherits(Mode, TextMode);
  115. (function () {
  116. this.lineCommentStart = "#";
  117. this.$id = "ace/mode/gherkin";
  118. this.getNextLineIndent = function (state, line, tab) {
  119. var indent = this.$getIndent(line);
  120. var space2 = " ";
  121. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  122. var tokens = tokenizedLine.tokens;
  123. if (line.match("[ ]*\\|")) {
  124. indent += "| ";
  125. }
  126. if (tokens.length && tokens[tokens.length - 1].type == "comment") {
  127. return indent;
  128. }
  129. if (state == "start") {
  130. if (line.match("Scenario:|Feature:|Scenario Outline:|Background:")) {
  131. indent += space2;
  132. }
  133. else if (line.match("(Given|Then).+(:)$|Examples:")) {
  134. indent += space2;
  135. }
  136. else if (line.match("\\*.+")) {
  137. indent += "* ";
  138. }
  139. }
  140. return indent;
  141. };
  142. }).call(Mode.prototype);
  143. exports.Mode = Mode;
  144. }); (function() {
  145. ace.require(["ace/mode/gherkin"], function(m) {
  146. if (typeof module == "object" && typeof exports == "object" && module) {
  147. module.exports = m;
  148. }
  149. });
  150. })();