No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mode-gherkin.js 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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 : "comment",
  26. regex : "@[A-Za-z0-9]+",
  27. next : "start"
  28. }, {
  29. token : "comment",
  30. regex : "<.+>"
  31. }, {
  32. token : "comment",
  33. regex : "\\| ",
  34. next : "table-item"
  35. }, {
  36. token : "comment",
  37. regex : "\\|$",
  38. next : "start"
  39. }],
  40. "qqstring3" : [ {
  41. token : "constant.language.escape",
  42. regex : stringEscape
  43. }, {
  44. token : "string", // multi line """ string end
  45. regex : '"{3}',
  46. next : "start"
  47. }, {
  48. defaultToken : "string"
  49. }],
  50. "qqstring" : [{
  51. token : "constant.language.escape",
  52. regex : stringEscape
  53. }, {
  54. token : "string",
  55. regex : "\\\\$",
  56. next : "qqstring"
  57. }, {
  58. token : "string",
  59. regex : '"|$',
  60. next : "start"
  61. }, {
  62. defaultToken: "string"
  63. }],
  64. "table-item" : [{
  65. token : "string",
  66. regex : "[A-Za-z0-9 ]*",
  67. next : "start"
  68. }],
  69. };
  70. }
  71. oop.inherits(GherkinHighlightRules, TextHighlightRules);
  72. exports.GherkinHighlightRules = GherkinHighlightRules;
  73. });
  74. ace.define("ace/mode/gherkin",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/gherkin_highlight_rules"], function(require, exports, module) {
  75. var oop = require("../lib/oop");
  76. var TextMode = require("./text").Mode;
  77. var GherkinHighlightRules = require("./gherkin_highlight_rules").GherkinHighlightRules;
  78. var Mode = function() {
  79. this.HighlightRules = GherkinHighlightRules;
  80. };
  81. oop.inherits(Mode, TextMode);
  82. (function() {
  83. this.lineCommentStart = "#";
  84. this.$id = "ace/mode/gherkin";
  85. this.getNextLineIndent = function(state, line, tab) {
  86. var indent = this.$getIndent(line);
  87. var space2 = " ";
  88. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  89. var tokens = tokenizedLine.tokens;
  90. console.log(state)
  91. if(line.match("[ ]*\\|")) {
  92. indent += "| ";
  93. }
  94. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  95. return indent;
  96. }
  97. if (state == "start") {
  98. if (line.match("Scenario:|Feature:|Scenario\ Outline:|Background:")) {
  99. indent += space2;
  100. } else if(line.match("(Given|Then).+(:)$|Examples:")) {
  101. indent += space2;
  102. } else if(line.match("\\*.+")) {
  103. indent += "* ";
  104. }
  105. }
  106. return indent;
  107. };
  108. }).call(Mode.prototype);
  109. exports.Mode = Mode;
  110. });