-
-
Save Marak/592580 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is how I would love to use it from Javascript... | |
var gherkin = require('gherkin'); | |
var simpleListener = { | |
feature: function(keyword, name, description, line) {}; | |
scenario: function(keyword, name, description, line) {}; | |
step: function(keyword, name, line) {}; | |
}; | |
var lexer = gherkin.lexer.en(simpleListener); | |
lexer.scan(source); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'gherkin/rb_lexer/en' | |
# Implements a subset of the listener interface needed for the | |
# simple feature below. With more complex features we'll need to | |
# implement more methods. The full interface is best described in | |
# Java: http://github.com/aslakhellesoy/gherkin/blob/master/java/src/main/java/gherkin/lexer/Listener.java | |
class SimpleListener | |
def feature(keyword, name, description, line) | |
puts "#{keyword}: #{name}" | |
puts " #{description}" | |
puts | |
end | |
def scenario(keyword, name, description, line) | |
puts " #{keyword}: #{name}" | |
end | |
def step(keyword, name, line) | |
puts " #{keyword}#{name}" | |
end | |
def eof | |
end | |
end | |
lexer = Gherkin::RbLexer::En.new(SimpleListener.new) | |
feature = <<-EOF | |
Feature: Do some simple scanning | |
Because we want to use Javascript | |
Scenario: Hello World | |
Given I have some Doppio | |
And I convert the English Ruby Gherkin Lexer to Javascript | |
Then I should be able to lex a .feature file with Node.js | |
EOF | |
lexer.scan(feature) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment