Skip to content

Extend parser to support additional structs #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/gherkin_ruby/parser/gherkin.rex
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ rule
Scenario: { [:SCENARIO, text[0..-2]] }

# Tags
@(\w|-)+ { [:TAG, text[1..-1]] }
@(\w|-|:)+ { [:TAG, text[1..-1]] }

# Step keywords
Given { [:GIVEN, text] }
When { [:WHEN, text] }
Then { [:THEN, text] }
And { [:AND, text] }
But { [:BUT, text] }
\* { [:STAR, text] }

# Text
[^#\n]* { [:TEXT, text.strip] }
Expand Down
4 changes: 2 additions & 2 deletions lib/gherkin_ruby/parser/gherkin.y
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class GherkinRuby::Parser
token NEWLINE
token FEATURE BACKGROUND SCENARIO
token TAG
token GIVEN WHEN THEN AND BUT
token GIVEN WHEN THEN AND BUT STAR
token TEXT

rule
Expand Down Expand Up @@ -73,7 +73,7 @@ rule
;

Keyword:
GIVEN | WHEN | THEN | AND | BUT
GIVEN | WHEN | THEN | AND | BUT | STAR
;

Scenarios:
Expand Down
160 changes: 82 additions & 78 deletions lib/gherkin_ruby/parser/lexer.rb
Original file line number Diff line number Diff line change
@@ -1,113 +1,117 @@
#--
# DO NOT MODIFY!!!!
# This file is automatically generated by rex 1.0.5
# from lexical definition file "lib/gherkin_ruby/parser/gherkin.rex".
# This file is automatically generated by rex 1.0.7
# from lexical definition file "gherkin.rex".
#++

require 'racc/parser'
# Compile with: rex gherkin.rex -o lexer.rb

class GherkinRuby::Parser < Racc::Parser
require 'strscan'
require 'strscan'

class ScanError < StandardError ; end
class ScanError < StandardError ; end

attr_reader :lineno
attr_reader :filename
attr_accessor :state
attr_reader :lineno
attr_reader :filename
attr_accessor :state

def scan_setup(str)
@ss = StringScanner.new(str)
@lineno = 1
@state = nil
end
def scan_setup(str)
@ss = StringScanner.new(str)
@lineno = 1
@state = nil
end

def action
yield
end
def action
yield
end

def scan_str(str)
scan_setup(str)
do_parse
end
alias :scan :scan_str
def scan_str(str)
scan_setup(str)
do_parse
end
alias :scan :scan_str

def load_file( filename )
@filename = filename
open(filename, "r") do |f|
scan_setup(f.read)
end
end
def load_file( filename )
@filename = filename
File.open(filename, "r") do |f|
scan_setup(f.read)
end
end

def scan_file( filename )
load_file(filename)
do_parse
end
def scan_file( filename )
load_file(filename)
do_parse
end


def next_token
return if @ss.eos?

# skips empty actions
until token = _next_token or @ss.eos?; end
token
end
def next_token
return if @ss.eos?

# skips empty actions
until token = _next_token or @ss.eos?; end
token
end

def _next_token
text = @ss.peek(1)
@lineno += 1 if text == "\n"
token = case @state
when nil
case
when (text = @ss.scan(/[ \t]+/))
;

def _next_token
text = @ss.peek(1)
@lineno += 1 if text == "\n"
token = case @state
when nil
case
when (text = @ss.scan(/[ \t]+/))
;
when (text = @ss.scan(/\#.*$/))
;

when (text = @ss.scan(/\#.*$/))
;
when (text = @ss.scan(/\n/))
action { [:NEWLINE, text] }

when (text = @ss.scan(/\n/))
action { [:NEWLINE, text] }
when (text = @ss.scan(/Feature:/))
action { [:FEATURE, text[0..-2]] }

when (text = @ss.scan(/Feature:/))
action { [:FEATURE, text[0..-2]] }
when (text = @ss.scan(/Background:/))
action { [:BACKGROUND, text[0..-2]] }

when (text = @ss.scan(/Background:/))
action { [:BACKGROUND, text[0..-2]] }
when (text = @ss.scan(/Scenario:/))
action { [:SCENARIO, text[0..-2]] }

when (text = @ss.scan(/Scenario:/))
action { [:SCENARIO, text[0..-2]] }
when (text = @ss.scan(/@(\w|-|:)+/))
action { [:TAG, text[1..-1]] }

when (text = @ss.scan(/@(\w|-)+/))
action { [:TAG, text[1..-1]] }
when (text = @ss.scan(/Given/))
action { [:GIVEN, text] }

when (text = @ss.scan(/Given/))
action { [:GIVEN, text] }
when (text = @ss.scan(/When/))
action { [:WHEN, text] }

when (text = @ss.scan(/When/))
action { [:WHEN, text] }
when (text = @ss.scan(/Then/))
action { [:THEN, text] }

when (text = @ss.scan(/Then/))
action { [:THEN, text] }
when (text = @ss.scan(/And/))
action { [:AND, text] }

when (text = @ss.scan(/And/))
action { [:AND, text] }
when (text = @ss.scan(/But/))
action { [:BUT, text] }

when (text = @ss.scan(/But/))
action { [:BUT, text] }
when (text = @ss.scan(/\*/))
action { [:STAR, text] }

when (text = @ss.scan(/[^#\n]*/))
action { [:TEXT, text.strip] }
when (text = @ss.scan(/[^#\n]*/))
action { [:TEXT, text.strip] }

else
text = @ss.string[@ss.pos .. -1]
raise ScanError, "can not match: '" + text + "'"
end # if

else
text = @ss.string[@ss.pos .. -1]
raise ScanError, "can not match: '" + text + "'"
end # if

else
raise ScanError, "undefined state: '" + state.to_s + "'"
end # case state
token
end # def _next_token
else
raise ScanError, "undefined state: '" + state.to_s + "'"
end # case state
token
end # def _next_token

def tokenize(code)
scan_setup(code)
Expand Down
Loading