mode-gherkin.js 4.2 KB

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