Skip to content
This repository
Browse code

Polished Clifford Heath's patches.

  • Loading branch information...
commit 3f649becc6876086653aea2faeca0814f34084ed 1 parent b81f53e
Nathan Sobo authored
2  trunk/spec/compiler/grammar_spec.rb
@@ -7,7 +7,7 @@ module Bar
7 7 describe "a grammar" do
8 8 testing_grammar %{
9 9 grammar Foo
10   - # This is a grammar for Foo
  10 + # This comment should not cause a syntax error.
11 11 include GrammarSpec::Bar
12 12
13 13 rule foo
5 trunk/spec/compiler/sequence_spec.rb
@@ -69,18 +69,23 @@ def baz
69 69 it "should succeed on a valid sequence" do
70 70 compiling_expression('foo:"foo" "bar" <SequenceSpec::Foo> { def a_method; end }').should_not raise_error
71 71 end
  72 +
72 73 it "rejects space after a label" do
73 74 compiling_expression('foo :"foo" "bar"').should raise_error(RuntimeError)
74 75 end
  76 +
75 77 it "rejects space after label's colon" do
76 78 compiling_expression('foo: "foo" "bar"').should raise_error(RuntimeError)
77 79 end
  80 +
78 81 it "rejects missing space after a primary" do
79 82 compiling_expression('foo:"foo""bar"').should raise_error(RuntimeError)
80 83 end
  84 +
81 85 it "rejects missing space before node class declaration" do
82 86 compiling_expression('foo:"foo" "bar"<SequenceSpec::Foo>').should raise_error(RuntimeError)
83 87 end
  88 +
84 89 it "rejects missing space before inline module" do
85 90 compiling_expression('foo:"foo" "bar" <SequenceSpec::Foo>{def a_method; end}').should raise_error(RuntimeError)
86 91 end
38 trunk/spec/parser/compiled_parser_spec.rb
@@ -22,7 +22,6 @@ module CompiledParserSpec
22 22
23 23 it "allows its root to be specified" do
24 24 parser.parse('a').should_not be_nil
25   - parser.failure_reason.should == nil
26 25 parser.parse('b').should be_nil
27 26
28 27 parser.root = :b
@@ -42,9 +41,35 @@ module CompiledParserSpec
42 41 parser.parse('ba').should be_nil
43 42 parser.parse('ba', :index => 1).should_not be_nil
44 43 end
  44 +
45 45 end
46   -
  46 +
  47 + describe Runtime::CompiledParser, "for a grammar with a choice between terminals" do
  48 + attr_reader :parser
  49 +
  50 + testing_grammar %{
  51 + grammar Choice
  52 + rule choice
  53 + 'a' / 'b' / 'c'
  54 + end
  55 + end
  56 + }
  57 +
  58 + before do
  59 + @parser = parser_class_under_test.new
  60 + end
  61 +
  62 + it "provides #failure_reason, #failure_column, and #failure_line when there is a parse failure" do
  63 + parser.parse('z').should be_nil
  64 + parser.failure_reason.should == "Expected one of a, b, c at line 1, column 1 (byte 1) after "
  65 + parser.failure_line.should == 1
  66 + parser.failure_column.should == 1
  67 + end
  68 + end
  69 +
47 70 describe Runtime::CompiledParser, "#terminal_failures" do
  71 + attr_reader:parser
  72 +
48 73 testing_grammar %{
49 74 grammar SequenceOfTerminals
50 75 rule foo
@@ -52,9 +77,7 @@ module CompiledParserSpec
52 77 end
53 78 end
54 79 }
55   -
56   - attr_reader:parser
57   -
  80 +
58 81 before do
59 82 @parser = parser_class_under_test.new
60 83 end
@@ -67,11 +90,6 @@ module CompiledParserSpec
67 90 failure.index.should == 1
68 91 failure.expected_string.should == 'b'
69 92
70   - parser.failure_index.should == 1
71   - parser.failure_line.should == 1
72   - parser.failure_column.should == 2
73   - parser.failure_reason.should == "Expected b at line 1, column 2 (byte 2) after a"
74   -
75 93 parser.parse('b')
76 94 terminal_failures = parser.terminal_failures
77 95 terminal_failures.size.should == 1
18 trunk/spec/spec_helper.rb
@@ -63,20 +63,20 @@ def parse(input, options = {})
63 63 end
64 64
65 65 def compiling_grammar(grammar_under_test)
66   - lambda{
67   - grammar_node = parse_with_metagrammar(grammar_under_test.strip, :grammar)
68   - parser_code = grammar_node.compile
69   - [grammar_node, parser_code]
  66 + lambda {
  67 + grammar_node = parse_with_metagrammar(grammar_under_test.strip, :grammar)
  68 + parser_code = grammar_node.compile
  69 + [grammar_node, parser_code]
70 70 }
71 71 end
72 72
73 73 def compiling_expression(expression_under_test)
74 74 compiling_grammar(%{
75   - grammar Test
76   - rule expression_under_test
77   - #{expression_under_test}
78   - end
79   - end
  75 + grammar Test
  76 + rule expression_under_test
  77 + #{expression_under_test}
  78 + end
  79 + end
80 80 }.tabto(0))
81 81 end
82 82

0 comments on commit 3f649be

Please sign in to comment.
Something went wrong with that request. Please try again.