treetop 1.5.3 → 1.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +5 -13
  2. data/Rakefile +9 -3
  3. data/doc/pitfalls_and_advanced_techniques.markdown +1 -1
  4. data/doc/sitegen.rb +1 -1
  5. data/doc/syntactic_recognition.markdown +2 -0
  6. data/doc/tt.1 +1 -1
  7. data/lib/treetop/compiler/metagrammar.rb +81 -13
  8. data/lib/treetop/compiler/metagrammar.treetop +67 -13
  9. data/lib/treetop/compiler/node_classes/anything_symbol.rb +5 -1
  10. data/lib/treetop/compiler/node_classes/character_class.rb +6 -2
  11. data/lib/treetop/compiler/node_classes/choice.rb +9 -5
  12. data/lib/treetop/compiler/node_classes/nonterminal.rb +2 -2
  13. data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +5 -1
  14. data/lib/treetop/compiler/node_classes/parsing_expression.rb +12 -2
  15. data/lib/treetop/compiler/node_classes/predicate.rb +8 -1
  16. data/lib/treetop/compiler/node_classes/predicate_block.rb +7 -0
  17. data/lib/treetop/compiler/node_classes/repetition.rb +31 -11
  18. data/lib/treetop/compiler/node_classes/sequence.rb +5 -1
  19. data/lib/treetop/compiler/node_classes/terminal.rb +12 -2
  20. data/lib/treetop/runtime/compiled_parser.rb +12 -6
  21. data/lib/treetop/runtime/syntax_node.rb +24 -15
  22. data/lib/treetop/runtime/terminal_parse_failure.rb +4 -3
  23. data/lib/treetop/version.rb +2 -2
  24. data/spec/compiler/and_predicate_spec.rb +1 -1
  25. data/spec/compiler/anything_symbol_spec.rb +4 -1
  26. data/spec/compiler/character_class_spec.rb +4 -1
  27. data/spec/compiler/choice_spec.rb +20 -11
  28. data/spec/compiler/failure_propagation_functional_spec.rb +1 -1
  29. data/spec/compiler/grammar_spec.rb +4 -1
  30. data/spec/compiler/not_predicate_spec.rb +20 -6
  31. data/spec/compiler/occurrence_range_spec.rb +25 -28
  32. data/spec/compiler/one_or_more_spec.rb +2 -2
  33. data/spec/compiler/optional_spec.rb +2 -2
  34. data/spec/compiler/parenthesized_expression_spec.rb +15 -1
  35. data/spec/compiler/semantic_predicate_spec.rb +17 -16
  36. data/spec/compiler/sequence_spec.rb +1 -1
  37. data/spec/compiler/terminal_spec.rb +8 -1
  38. data/spec/compiler/terminal_symbol_spec.rb +4 -1
  39. data/spec/compiler/zero_or_more_spec.rb +4 -2
  40. data/spec/runtime/compiled_parser_spec.rb +33 -3
  41. metadata +20 -21
  42. data/examples/lambda_calculus/lambda_calculus +0 -0
@@ -34,7 +34,7 @@ module SequenceSpec
34
34
  terminal_failures.size.should == 1
35
35
  failure = terminal_failures.first
36
36
  failure.index.should == 6
37
- failure.expected_string.should == 'bar'
37
+ failure.expected_string.should == '"bar"'
38
38
  end
39
39
  end
40
40
  end
@@ -18,12 +18,14 @@ module TerminalSymbolSpec
18
18
  it "fails to match the input string other than at the start" do
19
19
  parse " Foo", :index => 0 do |result|
20
20
  result.should be_nil
21
+ parser.terminal_failures.size.should == 1
21
22
  end
22
23
  end
23
24
 
24
25
  it "fails to match the input string in the wrong case" do
25
26
  parse "foo", :index => 0 do |result|
26
27
  result.should be_nil
28
+ parser.terminal_failures.size.should == 1
27
29
  end
28
30
  end
29
31
  end
@@ -75,7 +77,10 @@ module TerminalSymbolSpec
75
77
  end
76
78
 
77
79
  it "fails to parse nonmatching input at the index even if a match occurs later" do
78
- parse(" foo", :index => 0).should be_nil
80
+ parse(" foo", :index => 0) do |result|
81
+ result.should be_nil
82
+ parser.terminal_failures.size.should == 1
83
+ end
79
84
  end
80
85
  end
81
86
 
@@ -126,12 +131,14 @@ module TerminalSymbolSpec
126
131
  it "fails to match the input string other than at the start" do
127
132
  parse " Foo", :index => 0 do |result|
128
133
  result.should be_nil
134
+ parser.terminal_failures.size.should == 1
129
135
  end
130
136
  end
131
137
 
132
138
  it "fails to match the input string in the wrong case" do
133
139
  parse "foo", :index => 0 do |result|
134
140
  result.should be_nil
141
+ parser.terminal_failures.size.should == 1
135
142
  end
136
143
  end
137
144
  end
@@ -31,7 +31,10 @@ module TerminalSymbolSpec
31
31
  end
32
32
 
33
33
  it "fails to parse nonmatching input at the index even if a match occurs later" do
34
- parse(" foo", :index => 0).should be_nil
34
+ parse(" foo", :index => 0) do |result|
35
+ result.should be_nil
36
+ parser.terminal_failures.size.should == 1
37
+ end
35
38
  end
36
39
  end
37
40
  end
@@ -5,6 +5,8 @@ module ZeroOrMoreSpec
5
5
  end
6
6
 
7
7
  describe "zero or more of a terminal symbol followed by a node class declaration and a block" do
8
+ # testing_expression '("foo" { def b_method; end } )* <ZeroOrMoreSpec::Foo> { def a_method; end }'
9
+ # testing_expression '("foo" { def a_method; end } )* <ZeroOrMoreSpec::Foo>'
8
10
  testing_expression '"foo"* <ZeroOrMoreSpec::Foo> { def a_method; end }'
9
11
 
10
12
  it "successfully parses epsilon, returning an instance declared node class and recording a terminal failure" do
@@ -17,7 +19,7 @@ module ZeroOrMoreSpec
17
19
  terminal_failures.size.should == 1
18
20
  failure = terminal_failures.first
19
21
  failure.index.should == 0
20
- failure.expected_string.should == 'foo'
22
+ failure.expected_string.should == '"foo"'
21
23
  end
22
24
  end
23
25
 
@@ -30,7 +32,7 @@ module ZeroOrMoreSpec
30
32
  terminal_failures.size.should == 1
31
33
  failure = terminal_failures.first
32
34
  failure.index.should == 6
33
- failure.expected_string.should == 'foo'
35
+ failure.expected_string.should == '"foo"'
34
36
  end
35
37
  end
36
38
  end
@@ -83,7 +83,7 @@ module CompiledParserSpec
83
83
 
84
84
  it "provides #failure_reason, #failure_column, and #failure_line when there is a parse failure" do
85
85
  parser.parse('z').should be_nil
86
- parser.failure_reason.should == "Expected one of a, b, c at line 1, column 1 (byte 1) after "
86
+ parser.failure_reason.should == "Expected one of 'a', 'b', 'c' at line 1, column 1 (byte 1)"
87
87
  parser.failure_line.should == 1
88
88
  parser.failure_column.should == 1
89
89
  end
@@ -110,14 +110,44 @@ module CompiledParserSpec
110
110
  terminal_failures.size.should == 1
111
111
  failure = terminal_failures.first
112
112
  failure.index.should == 1
113
- failure.expected_string.should == 'b'
113
+ failure.expected_string.should == "'b'"
114
114
 
115
115
  parser.parse('b')
116
116
  terminal_failures = parser.terminal_failures
117
117
  terminal_failures.size.should == 1
118
118
  failure = terminal_failures.first
119
119
  failure.index.should == 0
120
- failure.expected_string.should == 'a'
120
+ failure.expected_string.should == "'a'"
121
121
  end
122
122
  end
123
+
124
+ describe "a SyntaxNode" do
125
+ attr_reader :parser
126
+
127
+ testing_grammar %{
128
+ grammar Alternates
129
+ rule main
130
+ aa &{|s| s[0].elements[0].parent.should == s[0] }
131
+ / ab &{|s| s[0].elements[0].parent.should == s[0] }
132
+ end
133
+
134
+ rule aa
135
+ 'a' 'a'
136
+ end
137
+
138
+ rule ab
139
+ 'a' 'b'
140
+ end
141
+ end
142
+ }
143
+
144
+ before do
145
+ @parser = parser_class_under_test.new
146
+ end
147
+
148
+ it "should have its parent set and reset" do
149
+ parser.parse('ab')
150
+ end
151
+ end
152
+
123
153
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: treetop
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.3
4
+ version: 1.6.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Sobo
@@ -9,106 +9,106 @@ authors:
9
9
  autorequire: treetop
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-03-21 00:00:00.000000000 Z
12
+ date: 2014-12-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: polyglot
16
16
  requirement: !ruby/object:Gem::Requirement
17
17
  requirements:
18
- - - ~>
18
+ - - "~>"
19
19
  - !ruby/object:Gem::Version
20
20
  version: '0.3'
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
- - - ~>
25
+ - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0.3'
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: jeweler
30
30
  requirement: !ruby/object:Gem::Requirement
31
31
  requirements:
32
- - - ~>
32
+ - - "~>"
33
33
  - !ruby/object:Gem::Version
34
34
  version: '2.0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
- - - ~>
39
+ - - "~>"
40
40
  - !ruby/object:Gem::Version
41
41
  version: '2.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: activesupport
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
- - - ~>
46
+ - - "~>"
47
47
  - !ruby/object:Gem::Version
48
48
  version: '4.0'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
- - - ~>
53
+ - - "~>"
54
54
  - !ruby/object:Gem::Version
55
55
  version: '4.0'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: i18n
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ~>
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
62
  version: '0.6'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ~>
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
69
  version: '0.6'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: rr
72
72
  requirement: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ~>
74
+ - - "~>"
75
75
  - !ruby/object:Gem::Version
76
76
  version: '1.0'
77
77
  type: :development
78
78
  prerelease: false
79
79
  version_requirements: !ruby/object:Gem::Requirement
80
80
  requirements:
81
- - - ~>
81
+ - - "~>"
82
82
  - !ruby/object:Gem::Version
83
83
  version: '1.0'
84
84
  - !ruby/object:Gem::Dependency
85
85
  name: rspec
86
86
  requirement: !ruby/object:Gem::Requirement
87
87
  requirements:
88
- - - ~>
88
+ - - "~>"
89
89
  - !ruby/object:Gem::Version
90
90
  version: '2'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
- - - ~>
95
+ - - "~>"
96
96
  - !ruby/object:Gem::Version
97
97
  version: '2'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: rake
100
100
  requirement: !ruby/object:Gem::Requirement
101
101
  requirements:
102
- - - ~>
102
+ - - ">="
103
103
  - !ruby/object:Gem::Version
104
- version: '10'
104
+ version: '0'
105
105
  type: :development
106
106
  prerelease: false
107
107
  version_requirements: !ruby/object:Gem::Requirement
108
108
  requirements:
109
- - - ~>
109
+ - - ">="
110
110
  - !ruby/object:Gem::Version
111
- version: '10'
111
+ version: '0'
112
112
  description:
113
113
  email: cliffordheath@gmail.com
114
114
  executables:
@@ -136,7 +136,6 @@ files:
136
136
  - examples/lambda_calculus/arithmetic.treetop
137
137
  - examples/lambda_calculus/arithmetic_node_classes.rb
138
138
  - examples/lambda_calculus/arithmetic_test.rb
139
- - examples/lambda_calculus/lambda_calculus
140
139
  - examples/lambda_calculus/lambda_calculus.rb
141
140
  - examples/lambda_calculus/lambda_calculus.treetop
142
141
  - examples/lambda_calculus/lambda_calculus_node_classes.rb
@@ -243,12 +242,12 @@ require_paths:
243
242
  - lib
244
243
  required_ruby_version: !ruby/object:Gem::Requirement
245
244
  requirements:
246
- - - ! '>='
245
+ - - ">="
247
246
  - !ruby/object:Gem::Version
248
247
  version: '0'
249
248
  required_rubygems_version: !ruby/object:Gem::Requirement
250
249
  requirements:
251
- - - ! '>='
250
+ - - ">="
252
251
  - !ruby/object:Gem::Version
253
252
  version: '0'
254
253
  requirements: []
File without changes