Permalink
Browse files

Merge pull request #11 from ntalbott/better_eof_handling

Better EOF Handling
  • Loading branch information...
2 parents 15dc90d + 69e00f5 commit 7ba6d4b996f0f32055946f0614196fb1f27109bc @josepjaume josepjaume committed May 18, 2012
Showing with 76 additions and 63 deletions.
  1. +1 −1 Rakefile
  2. +4 −3 lib/gherkin/parser/gherkin.y
  3. +54 −59 lib/gherkin/parser/parser.rb
  4. +17 −0 test/gherkin/parser/parser_test.rb
View
2 Rakefile
@@ -15,7 +15,7 @@ task :regenerate do
if has_rex && has_racc
`rex lib/gherkin/parser/gherkin.rex -o lib/gherkin/parser/lexer.rb`
- `racc lib/gherkin/parser/gherkin.y -o lib/gherkin/parser/parser.rb`
+ `racc #{'--debug' if ENV['DEBUG_RACC']} lib/gherkin/parser/gherkin.y -o lib/gherkin/parser/parser.rb`
else
puts "You need both Rexical and Racc to do that. Install them by doing:"
puts
View
7 lib/gherkin/parser/gherkin.y
@@ -56,8 +56,9 @@ rule
;
Steps:
- Step Newline { result = [val[0]] }
- | Steps Step Newline { result = val[0] << val[1] }
+ Step { result = [val[0]] }
+ | Step Newline { result = [val[0]] }
+ | Step Newline Steps { val[2].unshift(val[0]); result = val[2] }
;
Step:
@@ -71,7 +72,6 @@ rule
Scenarios:
Scenario { result = [val[0]] }
| Scenarios Scenario { result = val[0] << val[1] }
- | Scenarios Newline Scenario { result = val[0] << val[2] }
;
Scenario:
@@ -96,5 +96,6 @@ end
---- inner
def parse(input)
+ @yydebug = true if ENV['DEBUG_RACC']
scan_str(input)
end
View
113 lib/gherkin/parser/parser.rb
@@ -15,68 +15,63 @@ class Parser < Racc::Parser
module_eval(<<'...end gherkin.y/module_eval...', 'gherkin.y', 97)
def parse(input)
+ @yydebug = true if ENV['DEBUG_RACC']
scan_str(input)
end
...end gherkin.y/module_eval...
##### State transition tables begin ###
racc_action_table = [
- 14, 3, 14, 15, 14, 26, 14, 11, 13, 3,
- 38, 31, 32, 33, 34, 35, 14, 14, 11, 13,
- 41, 31, 32, 33, 34, 35, 31, 32, 33, 34,
- 35, 31, 32, 33, 34, 35, 31, 32, 33, 34,
- 35, 3, 3, 7, 11, 13, 31, 32, 33, 34,
- 35, 3, 3, 3, 18, 3, 44, 14, 45, 20,
- 21, 48, 3, 14, 3, 14, 27, 3, 14, 14,
- 8, 24 ]
+ 14, 3, 11, 13, 14, 25, 14, 39, 11, 13,
+ 37, 30, 31, 32, 33, 34, 14, 14, 15, 3,
+ 7, 30, 31, 32, 33, 34, 14, 26, 23, 3,
+ 21, 30, 31, 32, 33, 34, 30, 31, 32, 33,
+ 34, 20, 3, 3, 41, 14, 42, 3, 18, 45,
+ 8, 3, 14, 3, 14, 3 ]
racc_action_check = [
- 19, 12, 4, 4, 22, 12, 51, 22, 22, 38,
- 19, 51, 51, 51, 51, 51, 40, 25, 2, 2,
- 25, 40, 40, 40, 40, 40, 47, 47, 47, 47,
- 47, 52, 52, 52, 52, 52, 17, 17, 17, 17,
- 17, 9, 0, 0, 9, 9, 28, 28, 28, 28,
- 28, 6, 24, 18, 5, 29, 30, 36, 37, 7,
- 8, 41, 42, 43, 45, 46, 15, 48, 49, 50,
- 1, 11 ]
+ 19, 12, 9, 9, 24, 12, 48, 24, 2, 2,
+ 19, 48, 48, 48, 48, 48, 40, 4, 4, 0,
+ 0, 40, 40, 40, 40, 40, 38, 15, 11, 18,
+ 8, 38, 38, 38, 38, 38, 17, 17, 17, 17,
+ 17, 7, 6, 28, 29, 35, 36, 37, 5, 39,
+ 1, 42, 43, 45, 47, 23 ]
racc_action_pointer = [
- 40, 70, 13, nil, 0, 50, 49, 47, 60, 39,
- nil, 59, -1, nil, nil, 54, nil, 29, 51, -2,
- nil, nil, 2, nil, 50, 15, nil, nil, 39, 53,
- 44, nil, nil, nil, nil, nil, 55, 46, 7, nil,
- 14, 49, 60, 61, nil, 62, 63, 19, 65, 66,
- 67, 4, 24 ]
+ 17, 50, 3, nil, 15, 44, 40, 29, 30, -3,
+ nil, 16, -1, nil, nil, 15, nil, 29, 27, -2,
+ nil, nil, nil, 53, 2, nil, nil, nil, 41, 32,
+ nil, nil, nil, nil, nil, 43, 34, 45, 24, 37,
+ 14, nil, 49, 50, nil, 51, nil, 52, 4, nil ]
racc_action_default = [
-31, -31, -1, -3, -31, -5, -7, -31, -31, -2,
- -24, -31, -31, -29, -4, -31, -6, -31, -31, -8,
- -10, 53, -31, -25, -31, -31, -30, -11, -14, -31,
- -31, -19, -20, -21, -22, -23, -15, -9, -31, -26,
- -31, -31, -31, -16, -18, -31, -12, -27, -31, -17,
- -13, -31, -28 ]
+ -25, -31, -31, -29, -4, -31, -6, -31, -31, -8,
+ -10, 50, -26, -31, -31, -30, -11, -14, -16, -31,
+ -20, -21, -22, -23, -24, -15, -9, -31, -31, -31,
+ -17, -19, -31, -12, -27, -31, -18, -13, -31, -28 ]
racc_goto_table = [
- 4, 10, 28, 42, 6, 16, 19, 5, 23, 22,
- 37, 17, 25, 9, 2, 1, nil, nil, 36, nil,
- nil, 39, 42, nil, 40, 47, nil, 42, nil, 43,
- nil, nil, nil, nil, nil, nil, 52, nil, 46, nil,
- nil, nil, 49, nil, nil, 50, nil, nil, 51 ]
+ 4, 27, 10, 16, 5, 9, 19, 6, 36, 22,
+ 17, 2, 24, 1, nil, nil, nil, nil, 35, nil,
+ nil, nil, 44, 38, 46, nil, nil, nil, 40, nil,
+ nil, nil, 49, nil, nil, nil, nil, 43, nil, nil,
+ nil, nil, 47, nil, nil, 48 ]
racc_goto_check = [
- 4, 13, 10, 11, 7, 6, 4, 5, 13, 4,
- 8, 9, 4, 3, 2, 1, nil, nil, 4, nil,
- nil, 13, 11, nil, 4, 10, nil, 11, nil, 4,
- nil, nil, nil, nil, nil, nil, 10, nil, 4, nil,
- nil, nil, 4, nil, nil, 4, nil, nil, 4 ]
+ 4, 10, 13, 6, 5, 3, 4, 7, 8, 13,
+ 9, 2, 4, 1, nil, nil, nil, nil, 4, nil,
+ nil, nil, 10, 4, 10, nil, nil, nil, 4, nil,
+ nil, nil, 10, nil, nil, nil, nil, 4, nil, nil,
+ nil, nil, 4, nil, nil, 4 ]
racc_goto_pointer = [
- nil, 15, 14, 11, 0, 7, 0, 4, -9, 6,
- -15, -25, nil, -1, nil ]
+ nil, 13, 11, 3, 0, 4, -2, 7, -11, 5,
+ -16, nil, nil, 0, nil ]
racc_goto_default = [
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
- nil, 29, 30, nil, 12 ]
+ nil, 28, 29, nil, 12 ]
racc_reduce_table = [
0, 0, :racc_error,
@@ -95,25 +90,25 @@ def parse(input)
3, 21, :_reduce_none,
2, 19, :_reduce_14,
2, 22, :_reduce_15,
- 2, 23, :_reduce_16,
- 3, 23, :_reduce_17,
- 2, 24, :_reduce_18,
+ 1, 23, :_reduce_16,
+ 2, 23, :_reduce_17,
+ 3, 23, :_reduce_18,
+ 2, 24, :_reduce_19,
1, 25, :_reduce_none,
1, 25, :_reduce_none,
1, 25, :_reduce_none,
1, 25, :_reduce_none,
1, 25, :_reduce_none,
- 1, 16, :_reduce_24,
- 2, 16, :_reduce_25,
- 3, 16, :_reduce_26,
+ 1, 16, :_reduce_25,
+ 2, 16, :_reduce_26,
4, 26, :_reduce_27,
6, 26, :_reduce_28,
1, 27, :_reduce_29,
2, 27, :_reduce_30 ]
racc_reduce_n = 31
-racc_shift_n = 53
+racc_shift_n = 50
racc_token_table = {
false => 0,
@@ -280,19 +275,24 @@ def _reduce_16(val, _values, result)
module_eval(<<'.,.,', 'gherkin.y', 59)
def _reduce_17(val, _values, result)
- result = val[0] << val[1]
+ result = [val[0]]
result
end
.,.,
-module_eval(<<'.,.,', 'gherkin.y', 63)
+module_eval(<<'.,.,', 'gherkin.y', 60)
def _reduce_18(val, _values, result)
- result = AST::Step.new(val[1], val[0]); result.pos(filename, lineno)
+ val[2].unshift(val[0]); result = val[2]
result
end
.,.,
-# reduce 19 omitted
+module_eval(<<'.,.,', 'gherkin.y', 64)
+ def _reduce_19(val, _values, result)
+ result = AST::Step.new(val[1], val[0]); result.pos(filename, lineno)
+ result
+ end
+.,.,
# reduce 20 omitted
@@ -302,23 +302,18 @@ def _reduce_18(val, _values, result)
# reduce 23 omitted
-module_eval(<<'.,.,', 'gherkin.y', 71)
- def _reduce_24(val, _values, result)
- result = [val[0]]
- result
- end
-.,.,
+# reduce 24 omitted
module_eval(<<'.,.,', 'gherkin.y', 72)
def _reduce_25(val, _values, result)
- result = val[0] << val[1]
+ result = [val[0]]
result
end
.,.,
module_eval(<<'.,.,', 'gherkin.y', 73)
def _reduce_26(val, _values, result)
- result = val[0] << val[2]
+ result = val[0] << val[1]
result
end
.,.,
View
17 test/gherkin/parser/parser_test.rb
@@ -71,6 +71,23 @@ def parse(input)
last_scenario.steps.last.name.must_equal "something else"
end
+ it 'parses feature with no ending newline' do
+ feature = parse(%(
+Feature: Do something
+
+ Scenario: Foo bar baz
+ Given blah foo bar
+ Then something else))
+ scenarios = feature.scenarios
+ scenarios.size.must_equal 1
+
+ first_scenario = scenarios.first
+
+ first_scenario.name.must_equal "Foo bar baz"
+ first_scenario.steps.first.name.must_equal "blah foo bar"
+ first_scenario.steps.last.name.must_equal "something else"
+ end
+
it 'parses feature with scenarios with tags' do
feature = parse("""
Feature: Do something

0 comments on commit 7ba6d4b

Please sign in to comment.