treetop 1.6.5 → 1.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/lib/treetop/compiler/metagrammar.rb +32 -3
  3. data/lib/treetop/compiler/metagrammar.treetop +32 -3
  4. data/lib/treetop/compiler/node_classes/anything_symbol.rb +7 -3
  5. data/lib/treetop/compiler/node_classes/atomic_expression.rb +2 -2
  6. data/lib/treetop/compiler/node_classes/character_class.rb +5 -1
  7. data/lib/treetop/compiler/node_classes/choice.rb +3 -3
  8. data/lib/treetop/compiler/node_classes/nonterminal.rb +4 -0
  9. data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +1 -1
  10. data/lib/treetop/compiler/node_classes/parsing_expression.rb +7 -8
  11. data/lib/treetop/compiler/node_classes/parsing_rule.rb +1 -1
  12. data/lib/treetop/compiler/node_classes/predicate.rb +6 -6
  13. data/lib/treetop/compiler/node_classes/predicate_block.rb +1 -1
  14. data/lib/treetop/compiler/node_classes/repetition.rb +14 -14
  15. data/lib/treetop/compiler/node_classes/sequence.rb +1 -1
  16. data/lib/treetop/compiler/node_classes/terminal.rb +32 -28
  17. data/lib/treetop/runtime/compiled_parser.rb +12 -12
  18. data/lib/treetop/runtime/syntax_node.rb +15 -15
  19. data/lib/treetop/runtime/terminal_parse_failure.rb +2 -2
  20. data/lib/treetop/runtime/terminal_syntax_node.rb +4 -4
  21. data/lib/treetop/version.rb +1 -1
  22. data/spec/compiler/anything_symbol_spec.rb +2 -2
  23. data/spec/compiler/character_class_spec.rb +3 -3
  24. data/spec/compiler/grammar_spec.rb +2 -2
  25. data/spec/compiler/not_predicate_spec.rb +6 -6
  26. data/spec/compiler/occurrence_range_spec.rb +4 -4
  27. data/spec/compiler/parenthesized_expression_spec.rb +5 -5
  28. data/spec/compiler/semantic_predicate_spec.rb +7 -7
  29. data/spec/compiler/terminal_spec.rb +6 -6
  30. data/spec/compiler/terminal_symbol_spec.rb +2 -2
  31. data/spec/runtime/compiled_parser_spec.rb +7 -7
  32. data/spec/spec_helper.rb +6 -1
  33. data/treetop.gemspec +12 -21
  34. metadata +8 -17
  35. data/spec/runtime/interval_skip_list/delete_spec.rb +0 -147
  36. data/spec/runtime/interval_skip_list/expire_range_spec.rb +0 -349
  37. data/spec/runtime/interval_skip_list/insert_and_delete_node_spec.rb +0 -385
  38. data/spec/runtime/interval_skip_list/insert_spec.rb +0 -660
  39. data/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +0 -6175
  40. data/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +0 -58
  41. data/spec/runtime/interval_skip_list/palindromic_fixture.rb +0 -35
  42. data/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +0 -163
  43. data/spec/runtime/interval_skip_list/spec_helper.rb +0 -91
@@ -17,12 +17,12 @@ module Treetop
17
17
  @index = options[:index] if options[:index]
18
18
  result = send("_nt_#{options[:root] || root}")
19
19
  should_consume_all = options.include?(:consume_all_input) ? options[:consume_all_input] : consume_all_input?
20
- if (should_consume_all && index != input.size)
21
- if index > max_terminal_failure_index # Otherwise the failure is already explained
22
- terminal_parse_failure('<END OF INPUT>', true)
23
- end
24
- return nil
25
- end
20
+ if (should_consume_all && index != input.size)
21
+ if index > max_terminal_failure_index # Otherwise the failure is already explained
22
+ terminal_parse_failure('<END OF INPUT>', true)
23
+ end
24
+ return nil
25
+ end
26
26
  return SyntaxNode.new(input, index...(index + 1)) if result == true
27
27
  return result
28
28
  end
@@ -99,14 +99,14 @@ module Treetop
99
99
  end
100
100
 
101
101
  def has_terminal?(terminal, mode, index)
102
- case mode
103
- when :regexp # A Regexp has been passed in, either a character class or a literel regex 'foo'r
104
- (terminal =~ input[index..-1]) == 0 && $&.length
105
- when false # The terminal is a string which must match exactly
102
+ case mode
103
+ when :regexp # A Regexp has been passed in, either a character class or a literel regex 'foo'r
104
+ (terminal =~ input[index..-1]) == 0 && $&.length
105
+ when false # The terminal is a string which must match exactly
106
106
  input[index, terminal.size] == terminal && terminal.size
107
- when :insens # The terminal is a downcased string which must match input downcased
107
+ when :insens # The terminal is a downcased string which must match input downcased
108
108
  input[index, terminal.size].downcase == terminal && terminal.size
109
- when true # Only occurs with old compiled grammars, for character classes
109
+ when true # Only occurs with old compiled grammars, for character classes
110
110
  rx = @regexps[terminal] ||= Regexp.new(terminal)
111
111
  input.index(rx, index) == index && $&.length
112
112
  end
@@ -8,8 +8,8 @@ module Treetop
8
8
  @input = input
9
9
  @interval = interval
10
10
  if (@elements = elements)
11
- @elements.each { |e| e.equal?(true) or e.parent = self }
12
- end
11
+ @elements.each { |e| e.equal?(true) or e.parent = self }
12
+ end
13
13
  end
14
14
 
15
15
  def elements
@@ -20,7 +20,7 @@ module Treetop
20
20
  if element == true
21
21
  index = last_element ? last_element.interval.last : interval.first
22
22
  element = SyntaxNode.new(input, index...(index + 1))
23
- element.parent = self
23
+ element.parent = self
24
24
  end
25
25
  last_element = element
26
26
  end
@@ -76,21 +76,21 @@ module Treetop
76
76
  end
77
77
 
78
78
  def inspect_children(indent="")
79
- return '' unless elements && elements.size > 0
80
- ":" +
81
- elements.map do |e|
82
- begin
83
- "\n"+e.inspect(indent+" ")
84
- rescue # Defend against inspect not taking a parameter
85
- "\n"+indent+" "+e.inspect
86
- end
87
- end.
88
- join("")
79
+ return '' unless elements && elements.size > 0
80
+ ":" +
81
+ elements.map do |e|
82
+ begin
83
+ "\n"+e.inspect(indent+" ")
84
+ rescue # Defend against inspect not taking a parameter
85
+ "\n"+indent+" "+e.inspect
86
+ end
87
+ end.
88
+ join("")
89
89
  end
90
90
 
91
91
  def inspect(indent="")
92
- inspect_self(indent) +
93
- inspect_children(indent)
92
+ inspect_self(indent) +
93
+ inspect_children(indent)
94
94
  end
95
95
 
96
96
  @@dot_id_counter = 0
@@ -6,11 +6,11 @@ module Treetop
6
6
  def initialize(index, expected_string, unexpected = false)
7
7
  @index = index
8
8
  @expected_string = expected_string
9
- @unexpected = unexpected
9
+ @unexpected = unexpected
10
10
  end
11
11
 
12
12
  def to_s
13
- "String matching #{expected_string} #{@unexpected ? 'not ' : ''}expected."
13
+ "String matching #{expected_string} #{@unexpected ? 'not ' : ''}expected."
14
14
  end
15
15
  end
16
16
  end
@@ -7,10 +7,10 @@ module Treetop
7
7
  end
8
8
 
9
9
  def inspect(indent="")
10
- indent+
11
- self.class.to_s.sub(/.*:/,'') +
12
- " offset=#{interval.first}" +
13
- " #{text_value.inspect}"
10
+ indent+
11
+ self.class.to_s.sub(/.*:/,'') +
12
+ " offset=#{interval.first}" +
13
+ " #{text_value.inspect}"
14
14
  end
15
15
  end
16
16
  end
@@ -2,7 +2,7 @@ module Treetop #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 6
5
- TINY = 5
5
+ TINY = 6
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -20,8 +20,8 @@ module AnythingSymbolSpec
20
20
 
21
21
  it "fails to parse epsilon" do
22
22
  parse('') do |result|
23
- result.should be_nil
24
- parser.terminal_failures.size.should == 1
23
+ result.should be_nil
24
+ parser.terminal_failures.size.should == 1
25
25
  end
26
26
  end
27
27
  end
@@ -22,8 +22,8 @@ module CharacterClassSpec
22
22
 
23
23
  it "does not match single characters outside of that range" do
24
24
  parse('8') do |result|
25
- result.should be_nil
26
- parser.terminal_failures.size.should == 1
25
+ result.should be_nil
26
+ parser.terminal_failures.size.should == 1
27
27
  end
28
28
  parse('a').should be_nil
29
29
  end
@@ -212,7 +212,7 @@ module CharacterClassSpec
212
212
  it "doesn't evaluate the insertion" do
213
213
  x = true
214
214
  lambda{
215
- x = parse("y")
215
+ x = parse("y")
216
216
  }.should_not raise_error
217
217
  x.should be_nil
218
218
  parse('#').should_not be_nil
@@ -32,8 +32,8 @@ module GrammarSpec
32
32
 
33
33
  it "fails if it does not parse all input" do
34
34
  parse('barbarbazbaz') do |result|
35
- result.should be_nil
36
- parser.terminal_failures.size.should == 1
35
+ result.should be_nil
36
+ parser.terminal_failures.size.should == 1
37
37
  end
38
38
  end
39
39
 
@@ -6,8 +6,8 @@ module NotPredicateSpec
6
6
 
7
7
  it "fails to parse input matching the terminal symbol" do
8
8
  parse('foo') do |result|
9
- result.should be_nil
10
- parser.terminal_failures.size.should == 1
9
+ result.should be_nil
10
+ parser.terminal_failures.size.should == 1
11
11
  end
12
12
  end
13
13
  end
@@ -17,8 +17,8 @@ module NotPredicateSpec
17
17
 
18
18
  it "fails to parse input matching the terminal symbol" do
19
19
  parse('e') do |result|
20
- result.should be_nil
21
- parser.terminal_failures.size.should == 1
20
+ result.should be_nil
21
+ parser.terminal_failures.size.should == 1
22
22
  end
23
23
  end
24
24
  end
@@ -44,8 +44,8 @@ module NotPredicateSpec
44
44
 
45
45
  it "fails to parse matching input" do
46
46
  parse('abcc') do |result|
47
- result.should be_nil
48
- parser.terminal_failures.size.should == 1
47
+ result.should be_nil
48
+ parser.terminal_failures.size.should == 1
49
49
  end
50
50
  end
51
51
  end
@@ -55,7 +55,7 @@ module OccurrenceRangeSpec
55
55
  parse("foofoofoo") do |result|
56
56
  result.should be_nil
57
57
 
58
- parser.terminal_failures.size.should == 1
58
+ parser.terminal_failures.size.should == 1
59
59
  end
60
60
  end
61
61
 
@@ -64,7 +64,7 @@ module OccurrenceRangeSpec
64
64
  result.should_not be_nil
65
65
  result.elements.size.should == 2
66
66
 
67
- parser.terminal_failures.size.should == 0
67
+ parser.terminal_failures.size.should == 0
68
68
  end
69
69
  end
70
70
 
@@ -114,7 +114,7 @@ module OccurrenceRangeSpec
114
114
  result.should respond_to(:a_method)
115
115
 
116
116
  terminal_failures = parser.terminal_failures
117
- terminal_failures.size.should == 0
117
+ terminal_failures.size.should == 0
118
118
  end
119
119
  end
120
120
 
@@ -123,7 +123,7 @@ module OccurrenceRangeSpec
123
123
  result.should be_nil
124
124
 
125
125
  terminal_failures = parser.terminal_failures
126
- terminal_failures.size.should == 1
126
+ terminal_failures.size.should == 1
127
127
  end
128
128
  end
129
129
  end
@@ -14,8 +14,8 @@ module ParenthesizedExpressionSpec
14
14
 
15
15
  it "should behave as normal" do
16
16
  parse('foo') do |result|
17
- result.should be_nil
18
- parser.terminal_failures.size.should == 1
17
+ result.should be_nil
18
+ parser.terminal_failures.size.should == 1
19
19
  end
20
20
  end
21
21
  end
@@ -24,9 +24,9 @@ module ParenthesizedExpressionSpec
24
24
  testing_expression '("foo" { def inner; end } ) { def outer; end} '
25
25
  it "should extend both code modules " do
26
26
  parse('foo') do |result|
27
- skip "Arbitrarily nested modules are not yet compiled"
28
- result.should respond_to(:inner)
29
- result.should respond_to(:outer)
27
+ skip "Arbitrarily nested modules are not yet compiled"
28
+ result.should respond_to(:inner)
29
+ result.should respond_to(:outer)
30
30
  end
31
31
  end
32
32
  end
@@ -17,7 +17,7 @@ module SemanticPredicateSpec
17
17
  parse('foo', :consume_all_input => false) do |result|
18
18
  result.should be_nil
19
19
  terminal_failures = parser.terminal_failures
20
- terminal_failures.size.should == 1
20
+ terminal_failures.size.should == 1
21
21
  end
22
22
  end
23
23
 
@@ -44,7 +44,7 @@ module SemanticPredicateSpec
44
44
  result.should be_nil
45
45
  $value.should == 'prior '
46
46
  terminal_failures = parser.terminal_failures
47
- terminal_failures.size.should == 1
47
+ terminal_failures.size.should == 1
48
48
  end
49
49
  end
50
50
 
@@ -69,7 +69,7 @@ module SemanticPredicateSpec
69
69
  result.should be_nil
70
70
  $value.should == 'prior '
71
71
  terminal_failures = parser.terminal_failures
72
- terminal_failures.size.should == 1
72
+ terminal_failures.size.should == 1
73
73
  end
74
74
  end
75
75
 
@@ -78,7 +78,7 @@ module SemanticPredicateSpec
78
78
  parse('foo', :consume_all_input => false) do |result|
79
79
  result.should be_nil
80
80
  terminal_failures = parser.terminal_failures
81
- # We should get "prior " failed, and also the predicate block
81
+ # We should get "prior " failed, and also the predicate block
82
82
  terminal_failures.size.should == 2
83
83
  terminal_failures[0].index.should == 0
84
84
  terminal_failures[0].expected_string.should == '"prior "'
@@ -105,7 +105,7 @@ module SemanticPredicateSpec
105
105
  parse('foo', :consume_all_input => false) do |result|
106
106
  result.should be_nil
107
107
  terminal_failures = parser.terminal_failures
108
- terminal_failures.size.should == 1
108
+ terminal_failures.size.should == 1
109
109
  end
110
110
  end
111
111
 
@@ -132,7 +132,7 @@ module SemanticPredicateSpec
132
132
  result.should be_nil
133
133
  $value.should == 'prior '
134
134
  terminal_failures = parser.terminal_failures
135
- terminal_failures.size.should == 1
135
+ terminal_failures.size.should == 1
136
136
  end
137
137
  end
138
138
 
@@ -157,7 +157,7 @@ module SemanticPredicateSpec
157
157
  result.should be_nil
158
158
  $value.should == 'prior '
159
159
  terminal_failures = parser.terminal_failures
160
- terminal_failures.size.should == 1
160
+ terminal_failures.size.should == 1
161
161
  end
162
162
  end
163
163
 
@@ -18,14 +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
+ parser.terminal_failures.size.should == 1
22
22
  end
23
23
  end
24
24
 
25
25
  it "fails to match the input string in the wrong case" do
26
26
  parse "foo", :index => 0 do |result|
27
27
  result.should be_nil
28
- parser.terminal_failures.size.should == 1
28
+ parser.terminal_failures.size.should == 1
29
29
  end
30
30
  end
31
31
  end
@@ -78,8 +78,8 @@ module TerminalSymbolSpec
78
78
 
79
79
  it "fails to parse nonmatching input at the index even if a match occurs later" do
80
80
  parse(" foo", :index => 0) do |result|
81
- result.should be_nil
82
- parser.terminal_failures.size.should == 1
81
+ result.should be_nil
82
+ parser.terminal_failures.size.should == 1
83
83
  end
84
84
  end
85
85
  end
@@ -131,14 +131,14 @@ module TerminalSymbolSpec
131
131
  it "fails to match the input string other than at the start" do
132
132
  parse " Foo", :index => 0 do |result|
133
133
  result.should be_nil
134
- parser.terminal_failures.size.should == 1
134
+ parser.terminal_failures.size.should == 1
135
135
  end
136
136
  end
137
137
 
138
138
  it "fails to match the input string in the wrong case" do
139
139
  parse "foo", :index => 0 do |result|
140
140
  result.should be_nil
141
- parser.terminal_failures.size.should == 1
141
+ parser.terminal_failures.size.should == 1
142
142
  end
143
143
  end
144
144
  end
@@ -32,8 +32,8 @@ module TerminalSymbolSpec
32
32
 
33
33
  it "fails to parse nonmatching input at the index even if a match occurs later" do
34
34
  parse(" foo", :index => 0) do |result|
35
- result.should be_nil
36
- parser.terminal_failures.size.should == 1
35
+ result.should be_nil
36
+ parser.terminal_failures.size.should == 1
37
37
  end
38
38
  end
39
39
  end
@@ -128,16 +128,16 @@ module CompiledParserSpec
128
128
  grammar Alternates
129
129
  rule main
130
130
  aa &{|s| s[0].elements[0].parent.should == s[0] }
131
- / ab &{|s| s[0].elements[0].parent.should == s[0] }
131
+ / ab &{|s| s[0].elements[0].parent.should == s[0] }
132
132
  end
133
133
 
134
- rule aa
135
- 'a' 'a'
136
- end
134
+ rule aa
135
+ 'a' 'a'
136
+ end
137
137
 
138
- rule ab
139
- 'a' 'b'
140
- end
138
+ rule ab
139
+ 'a' 'b'
140
+ end
141
141
  end
142
142
  }
143
143
 
@@ -8,6 +8,11 @@ $LOAD_PATH.unshift File.expand_path('../../lib')
8
8
  require 'treetop'
9
9
  include Treetop
10
10
 
11
+ # We're still using the old expect syntax:
12
+ RSpec.configure do |c|
13
+ c.expect_with(:rspec) { |c| c.syntax = :should }
14
+ end
15
+
11
16
  module Treetop
12
17
  module ExampleGroupInstanceMethods
13
18
  module ClassMethods
@@ -26,7 +31,7 @@ module Treetop
26
31
  end
27
32
 
28
33
  def testing_grammar(grammar_under_test)
29
- self.parser_text = grammar_under_test
34
+ self.parser_text = grammar_under_test
30
35
  grammar_node = parse_with_metagrammar(grammar_under_test.strip, :module_or_grammar)
31
36
  self.parser_code = grammar_node.compile
32
37
  class_eval(self.parser_code)
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: treetop 1.6.5 ruby lib
5
+ # stub: treetop 1.6.6 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "treetop"
9
- s.version = "1.6.5"
9
+ s.version = "1.6.6"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["Nathan Sobo", "Clifford Heath"]
14
- s.date = "2016-02-25"
14
+ s.date = "2016-07-20"
15
15
  s.description = "A Parsing Expression Grammar (PEG) Parser generator DSL for Ruby"
16
16
  s.email = "cliffordheath@gmail.com"
17
17
  s.executables = ["tt"]
@@ -124,15 +124,6 @@ Gem::Specification.new do |s|
124
124
  "spec/composition/subfolder/e_includes_c.treetop",
125
125
  "spec/ruby_extensions/string_spec.rb",
126
126
  "spec/runtime/compiled_parser_spec.rb",
127
- "spec/runtime/interval_skip_list/delete_spec.rb",
128
- "spec/runtime/interval_skip_list/expire_range_spec.rb",
129
- "spec/runtime/interval_skip_list/insert_and_delete_node_spec.rb",
130
- "spec/runtime/interval_skip_list/insert_spec.rb",
131
- "spec/runtime/interval_skip_list/interval_skip_list_spec.graffle",
132
- "spec/runtime/interval_skip_list/interval_skip_list_spec.rb",
133
- "spec/runtime/interval_skip_list/palindromic_fixture.rb",
134
- "spec/runtime/interval_skip_list/palindromic_fixture_spec.rb",
135
- "spec/runtime/interval_skip_list/spec_helper.rb",
136
127
  "spec/runtime/syntax_node_spec.rb",
137
128
  "spec/spec_helper.rb",
138
129
  "treetop.gemspec"
@@ -148,28 +139,28 @@ Gem::Specification.new do |s|
148
139
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
149
140
  s.add_runtime_dependency(%q<polyglot>, ["~> 0.3"])
150
141
  s.add_development_dependency(%q<jeweler>, ["~> 2.0"])
151
- s.add_development_dependency(%q<activesupport>, ["~> 4.0"])
142
+ s.add_development_dependency(%q<activesupport>, ["~> 5"])
152
143
  s.add_development_dependency(%q<i18n>, ["~> 0.6"])
153
144
  s.add_development_dependency(%q<rr>, ["~> 1.0"])
154
- s.add_development_dependency(%q<rspec>, ["~> 2"])
155
- s.add_development_dependency(%q<rake>, ["~> 10"])
145
+ s.add_development_dependency(%q<rspec>, ["~> 3"])
146
+ s.add_development_dependency(%q<rake>, ["~> 11"])
156
147
  else
157
148
  s.add_dependency(%q<polyglot>, ["~> 0.3"])
158
149
  s.add_dependency(%q<jeweler>, ["~> 2.0"])
159
- s.add_dependency(%q<activesupport>, ["~> 4.0"])
150
+ s.add_dependency(%q<activesupport>, ["~> 5"])
160
151
  s.add_dependency(%q<i18n>, ["~> 0.6"])
161
152
  s.add_dependency(%q<rr>, ["~> 1.0"])
162
- s.add_dependency(%q<rspec>, ["~> 2"])
163
- s.add_dependency(%q<rake>, ["~> 10"])
153
+ s.add_dependency(%q<rspec>, ["~> 3"])
154
+ s.add_dependency(%q<rake>, ["~> 11"])
164
155
  end
165
156
  else
166
157
  s.add_dependency(%q<polyglot>, ["~> 0.3"])
167
158
  s.add_dependency(%q<jeweler>, ["~> 2.0"])
168
- s.add_dependency(%q<activesupport>, ["~> 4.0"])
159
+ s.add_dependency(%q<activesupport>, ["~> 5"])
169
160
  s.add_dependency(%q<i18n>, ["~> 0.6"])
170
161
  s.add_dependency(%q<rr>, ["~> 1.0"])
171
- s.add_dependency(%q<rspec>, ["~> 2"])
172
- s.add_dependency(%q<rake>, ["~> 10"])
162
+ s.add_dependency(%q<rspec>, ["~> 3"])
163
+ s.add_dependency(%q<rake>, ["~> 11"])
173
164
  end
174
165
  end
175
166