diff --git a/demo/kitchen-sink/docs/gherkin.feature b/demo/kitchen-sink/docs/gherkin.feature new file mode 100644 index 00000000..ab31cdf1 --- /dev/null +++ b/demo/kitchen-sink/docs/gherkin.feature @@ -0,0 +1,10 @@ +Feature: Serve coffee + Coffee should not be served until paid for + Coffee should not be served until the button has been pressed + If there is no coffee left then money should be refunded + + Scenario: Buy last coffee + Given there are 1 coffees left in the machine + And I have deposited 1$ + When I press the coffee button + Then I should be served a coffee \ No newline at end of file diff --git a/lib/ace/ext/modelist.js b/lib/ace/ext/modelist.js index e3b8862a..67c80ef0 100644 --- a/lib/ace/ext/modelist.js +++ b/lib/ace/ext/modelist.js @@ -67,6 +67,7 @@ var supportedModes = { EJS: ["ejs"], Forth: ["frt|fs|ldr"], FTL: ["ftl"], + Gherkin: ["feature"], Glsl: ["glsl|frag|vert"], golang: ["go"], Groovy: ["groovy"], diff --git a/lib/ace/mode/gherkin.js b/lib/ace/mode/gherkin.js new file mode 100644 index 00000000..8b9b58a5 --- /dev/null +++ b/lib/ace/mode/gherkin.js @@ -0,0 +1,58 @@ +define(function(require, exports, module) { + +var oop = require("../lib/oop"); +var TextMode = require("./text").Mode; +var Tokenizer = require("../tokenizer").Tokenizer; +var GherkinHighlightRules = require("./gherkin_highlight_rules").GherkinHighlightRules; + +var Mode = function() { + this.$tokenizer = new Tokenizer(new GherkinHighlightRules().getRules()); +}; +oop.inherits(Mode, TextMode); + +(function() { + this.lineCommentStart = "#"; + this.$id = "ace/mode/gherkin"; + + this.getNextLineIndent = function(state, line, tab) { + var indent = this.$getIndent(line); + + var tokenizedLine = this.getTokenizer().getLineTokens(line, state); + var tokens = tokenizedLine.tokens; + + console.log(state) + + if(line.match("[ ]*\\|")) { + console.log(line.match("\|")); + indent += "| "; + } + + if (tokens.length && tokens[tokens.length-1].type == "comment") { + return indent; + } + + + if (state == "start") { + if (line.match("Scenario:|Feature:")) { + indent = tab; + } else if(line.match("Given.+(:)$|Examples:")) { + indent += tab; + } else if(line.match("\\*.+")) { + indent += "* "; + } + } + + + return indent; + }; + + this.checkOutdent = function(state, line, input) { + if(line.match("Feature:")) { + + } + } + // Extra logic goes here. (see below) +}).call(Mode.prototype); + +exports.Mode = Mode; +}); \ No newline at end of file diff --git a/lib/ace/mode/gherkin_highlight_rules.js b/lib/ace/mode/gherkin_highlight_rules.js new file mode 100644 index 00000000..a902703d --- /dev/null +++ b/lib/ace/mode/gherkin_highlight_rules.js @@ -0,0 +1,83 @@ +define(function(require, exports, module) { + +var oop = require("../lib/oop"); +var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; +var stringEscape = "\\\\(x[0-9A-Fa-f]{2}|[0-7]{3}|[\\\\abfnrtv'\"]|U[0-9A-Fa-f]{8}|u[0-9A-Fa-f]{4})"; + +var GherkinHighlightRules = function() { + + // need to include constant ints + this.$rules = { + start : [{ + token: 'constant.numeric', + regex: "(?:(?:[1-9]\\d*)|(?:0))" + }, { + token : "comment", + regex : "#.*$" + }, { + token : "keyword", + regex : "Feature:|Background:|Scenario:|Scenario Outline:|Examples:|Given|When|Then|And|But|\\*|Scenario\ Outline", + }, { + token : "string", // multi line """ string start + regex : '"{3}', + next : "qqstring3" + }, { + token : "string", // " string + regex : '"', + next : "qqstring" + }, { + token : "comment", + regex : "@[A-Za-z0-9]+", + next : "start" + }, { + token : "comment", + regex : "<.+>" + }, { + token : "comment", + regex : "\\| ", + next : "table-item" + }, { + token : "comment", + regex : "\\|$", + next : "start" + }], + "qqstring3" : [ { + token : "constant.language.escape", + regex : stringEscape + }, { + token : "string", // multi line """ string end + regex : '"{3}', + next : "start" + }, { + defaultToken : "string" + }], + "qqstring" : [{ + token : "constant.language.escape", + regex : stringEscape + }, { + token : "string", + regex : "\\\\$", + next : "qqstring" + }, { + token : "string", + regex : '"|$', + next : "start" + }, { + defaultToken: "string" + }], + "table-item" : [{ + token : "string", + regex : "[A-Za-z0-9 ]*", + next : "start" + }], + }; + + + //new TextHighlightRules().getRules(); + +} + +oop.inherits(GherkinHighlightRules, TextHighlightRules); + +exports.GherkinHighlightRules = GherkinHighlightRules; +}); \ No newline at end of file