treetop 1.6.5 → 1.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/treetop/compiler/metagrammar.rb +32 -3
- data/lib/treetop/compiler/metagrammar.treetop +32 -3
- data/lib/treetop/compiler/node_classes/anything_symbol.rb +7 -3
- data/lib/treetop/compiler/node_classes/atomic_expression.rb +2 -2
- data/lib/treetop/compiler/node_classes/character_class.rb +5 -1
- data/lib/treetop/compiler/node_classes/choice.rb +3 -3
- data/lib/treetop/compiler/node_classes/nonterminal.rb +4 -0
- data/lib/treetop/compiler/node_classes/parenthesized_expression.rb +1 -1
- data/lib/treetop/compiler/node_classes/parsing_expression.rb +7 -8
- data/lib/treetop/compiler/node_classes/parsing_rule.rb +1 -1
- data/lib/treetop/compiler/node_classes/predicate.rb +6 -6
- data/lib/treetop/compiler/node_classes/predicate_block.rb +1 -1
- data/lib/treetop/compiler/node_classes/repetition.rb +14 -14
- data/lib/treetop/compiler/node_classes/sequence.rb +1 -1
- data/lib/treetop/compiler/node_classes/terminal.rb +32 -28
- data/lib/treetop/runtime/compiled_parser.rb +12 -12
- data/lib/treetop/runtime/syntax_node.rb +15 -15
- data/lib/treetop/runtime/terminal_parse_failure.rb +2 -2
- data/lib/treetop/runtime/terminal_syntax_node.rb +4 -4
- data/lib/treetop/version.rb +1 -1
- data/spec/compiler/anything_symbol_spec.rb +2 -2
- data/spec/compiler/character_class_spec.rb +3 -3
- data/spec/compiler/grammar_spec.rb +2 -2
- data/spec/compiler/not_predicate_spec.rb +6 -6
- data/spec/compiler/occurrence_range_spec.rb +4 -4
- data/spec/compiler/parenthesized_expression_spec.rb +5 -5
- data/spec/compiler/semantic_predicate_spec.rb +7 -7
- data/spec/compiler/terminal_spec.rb +6 -6
- data/spec/compiler/terminal_symbol_spec.rb +2 -2
- data/spec/runtime/compiled_parser_spec.rb +7 -7
- data/spec/spec_helper.rb +6 -1
- data/treetop.gemspec +12 -21
- metadata +8 -17
- data/spec/runtime/interval_skip_list/delete_spec.rb +0 -147
- data/spec/runtime/interval_skip_list/expire_range_spec.rb +0 -349
- data/spec/runtime/interval_skip_list/insert_and_delete_node_spec.rb +0 -385
- data/spec/runtime/interval_skip_list/insert_spec.rb +0 -660
- data/spec/runtime/interval_skip_list/interval_skip_list_spec.graffle +0 -6175
- data/spec/runtime/interval_skip_list/interval_skip_list_spec.rb +0 -58
- data/spec/runtime/interval_skip_list/palindromic_fixture.rb +0 -35
- data/spec/runtime/interval_skip_list/palindromic_fixture_spec.rb +0 -163
- data/spec/runtime/interval_skip_list/spec_helper.rb +0 -91
@@ -1,58 +0,0 @@
|
|
1
|
-
#require 'runtime/interval_skip_list/spec_helper'
|
2
|
-
#
|
3
|
-
#MAX_INTERVAL = 100000
|
4
|
-
#
|
5
|
-
#describe IntervalSkipList do
|
6
|
-
# describe "#next_node_height" do
|
7
|
-
# attr_reader :list
|
8
|
-
#
|
9
|
-
# before do
|
10
|
-
# @list = IntervalSkipList.new
|
11
|
-
# end
|
12
|
-
#
|
13
|
-
# it "returns a number between 1 and the max_height of the list" do
|
14
|
-
# height = list.next_node_height
|
15
|
-
# height.should be <= list.max_height
|
16
|
-
# height.should be > 0
|
17
|
-
# end
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# describe "a list with 1000 random intervals" do
|
21
|
-
# attr_reader :list, :inserted_ranges
|
22
|
-
#
|
23
|
-
# before do
|
24
|
-
# @list = IntervalSkipList.new
|
25
|
-
# @inserted_ranges = []
|
26
|
-
#
|
27
|
-
# 0.upto(10) do |i|
|
28
|
-
# first, last = [rand(MAX_INTERVAL), rand(MAX_INTERVAL)].sort
|
29
|
-
# range = first..last
|
30
|
-
# list.insert(range, i)
|
31
|
-
# inserted_ranges.push(range)
|
32
|
-
# end
|
33
|
-
# end
|
34
|
-
#
|
35
|
-
# it "functions correctly for stabbing queries" do
|
36
|
-
# 10000.times do
|
37
|
-
# n = rand(MAX_INTERVAL)
|
38
|
-
# ranges = list.containing(n).sort
|
39
|
-
#
|
40
|
-
# expected_ranges = []
|
41
|
-
# inserted_ranges.each_with_index do |range,i|
|
42
|
-
# expected_ranges.push(i) if n > range.first && n < range.last
|
43
|
-
# end
|
44
|
-
# expected_ranges.sort!
|
45
|
-
# unless ranges == expected_ranges
|
46
|
-
# puts "N = #{n}"
|
47
|
-
# puts "Expected: " + expected_ranges.inspect
|
48
|
-
# puts "Actual: " + ranges.inspect
|
49
|
-
# expected_ranges.size.should be <= ranges.size
|
50
|
-
# puts "Missing containers: #{(expected_ranges.map {|o| o.object_id} - ranges.map {|o| o.object_id}).inspect}"
|
51
|
-
# puts "Unexpected containers: #{(ranges.map {|o| o.object_id} - expected_ranges.map {|o| o.object_id}).inspect}"
|
52
|
-
# puts "Inserted Ranges: #{inserted_ranges.inspect}"
|
53
|
-
# puts "Expected Ranges: #{expected_ranges.map {|i| inserted_ranges[i]}.inspect}"
|
54
|
-
# end
|
55
|
-
# end
|
56
|
-
# end
|
57
|
-
# end
|
58
|
-
#end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module PalindromicFixtureSharedContext
|
2
|
-
extend RSpec::Core::SharedContext
|
3
|
-
include IntervalSkipListSpecHelper
|
4
|
-
|
5
|
-
attr_reader :list, :node
|
6
|
-
|
7
|
-
def construct_interval_skip_list
|
8
|
-
@list = IntervalSkipList.new
|
9
|
-
end
|
10
|
-
|
11
|
-
def expected_node_heights
|
12
|
-
[3, 2, 1, 3, 1, 2, 3]
|
13
|
-
end
|
14
|
-
|
15
|
-
def populate_interval_skip_list
|
16
|
-
@list.insert(1..3, :a)
|
17
|
-
@list.insert(1..5, :b)
|
18
|
-
@list.insert(1..7, :c)
|
19
|
-
@list.insert(1..9, :d)
|
20
|
-
@list.insert(1..11, :e)
|
21
|
-
@list.insert(1..13, :f)
|
22
|
-
@list.insert(5..13, :g)
|
23
|
-
end
|
24
|
-
|
25
|
-
def make_it_determinisitic
|
26
|
-
extend NextNodeHeightIsDeterministicSharedContext # use the method without getting the filter
|
27
|
-
next_node_height_is_deterministic
|
28
|
-
end
|
29
|
-
|
30
|
-
before :each do
|
31
|
-
construct_interval_skip_list
|
32
|
-
make_it_determinisitic
|
33
|
-
populate_interval_skip_list
|
34
|
-
end
|
35
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
require 'runtime/interval_skip_list/spec_helper'
|
2
|
-
|
3
|
-
describe "The palindromic fixture", :palindromic => true do
|
4
|
-
include PalindromicFixtureSharedContext
|
5
|
-
|
6
|
-
describe " #nodes" do
|
7
|
-
describe "[0]" do
|
8
|
-
before do
|
9
|
-
@node = list.nodes[0]
|
10
|
-
end
|
11
|
-
|
12
|
-
it "has a key of 1 and a height of 3" do
|
13
|
-
node.key.should == 1
|
14
|
-
node.height.should == 3
|
15
|
-
end
|
16
|
-
|
17
|
-
it "has :c, :d, :e, and :f as its only forward markers at level 2" do
|
18
|
-
node.forward_markers[2].should have_markers(:c, :d, :e, :f)
|
19
|
-
end
|
20
|
-
|
21
|
-
it "has :a, :b as its only forward markers at level 1" do
|
22
|
-
node.forward_markers[1].should have_markers(:a, :b)
|
23
|
-
end
|
24
|
-
|
25
|
-
it "has no forward markers at level 0" do
|
26
|
-
node.forward_markers[0].should be_empty
|
27
|
-
end
|
28
|
-
|
29
|
-
it "has no markers" do
|
30
|
-
node.markers.should be_empty
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "[1]" do
|
35
|
-
before do
|
36
|
-
@node = list.nodes[1]
|
37
|
-
end
|
38
|
-
|
39
|
-
it "has a key of 3 and a height of 2" do
|
40
|
-
node.key.should == 3
|
41
|
-
node.height.should == 2
|
42
|
-
end
|
43
|
-
|
44
|
-
it "has no forward markers at level 1" do
|
45
|
-
node.forward_markers[1].should be_empty
|
46
|
-
end
|
47
|
-
|
48
|
-
it "has :b as its only forward marker at level 0" do
|
49
|
-
node.forward_markers[0].should have_marker(:b)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "has :a and :b as its only markers" do
|
53
|
-
node.markers.should have_markers(:a, :b)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
describe "[2]" do
|
58
|
-
before do
|
59
|
-
@node = list.nodes[2]
|
60
|
-
end
|
61
|
-
|
62
|
-
it "has a key of 5 and a height of 1" do
|
63
|
-
node.key.should == 5
|
64
|
-
node.height.should == 1
|
65
|
-
end
|
66
|
-
|
67
|
-
it "has :g as its only forward marker at level 0" do
|
68
|
-
node.forward_markers[0].should have_marker(:g)
|
69
|
-
end
|
70
|
-
|
71
|
-
it "has :b as its only marker" do
|
72
|
-
node.markers.should have_marker(:b)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
describe "[3]" do
|
77
|
-
before do
|
78
|
-
@node = list.nodes[3]
|
79
|
-
end
|
80
|
-
|
81
|
-
it "has a key of 7 and a height of 3" do
|
82
|
-
node.key.should == 7
|
83
|
-
node.height.should == 3
|
84
|
-
end
|
85
|
-
|
86
|
-
it "has :f and :g as its only forward markers at level 2" do
|
87
|
-
node.forward_markers[2].should have_markers(:f, :g)
|
88
|
-
end
|
89
|
-
|
90
|
-
it "has :e as its only forward markers at level 1" do
|
91
|
-
node.forward_markers[1].should have_marker(:e)
|
92
|
-
end
|
93
|
-
|
94
|
-
it "has :d as its only forward marker at level 0" do
|
95
|
-
node.forward_markers[0].should have_markers(:d)
|
96
|
-
end
|
97
|
-
|
98
|
-
it "has :c, :d, :e, :f and :g as its only markers" do
|
99
|
-
node.markers.should have_markers(:c, :d, :e, :f, :g)
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
describe "[4]" do
|
104
|
-
before do
|
105
|
-
@node = list.nodes[4]
|
106
|
-
end
|
107
|
-
|
108
|
-
it "has a key of 9 and a height of 1" do
|
109
|
-
node.key.should == 9
|
110
|
-
node.height.should == 1
|
111
|
-
end
|
112
|
-
|
113
|
-
it "has no forward markers at any level" do
|
114
|
-
node.forward_markers[0].should be_empty
|
115
|
-
end
|
116
|
-
|
117
|
-
it "has :d as its only marker" do
|
118
|
-
node.markers.should have_markers(:d)
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
describe "[5]" do
|
123
|
-
before do
|
124
|
-
@node = list.nodes[5]
|
125
|
-
end
|
126
|
-
|
127
|
-
it "has a key of 11 and a height of 2" do
|
128
|
-
node.key.should == 11
|
129
|
-
node.height.should == 2
|
130
|
-
end
|
131
|
-
|
132
|
-
it "has no forward markers at any level" do
|
133
|
-
node.forward_markers[0].should be_empty
|
134
|
-
node.forward_markers[1].should be_empty
|
135
|
-
end
|
136
|
-
|
137
|
-
it "has :e as its only marker" do
|
138
|
-
node.markers.should have_markers(:e)
|
139
|
-
end
|
140
|
-
end
|
141
|
-
|
142
|
-
describe "[6]" do
|
143
|
-
before do
|
144
|
-
@node = list.nodes[6]
|
145
|
-
end
|
146
|
-
|
147
|
-
it "has a key of 13 and a height of 3" do
|
148
|
-
node.key.should == 13
|
149
|
-
node.height.should == 3
|
150
|
-
end
|
151
|
-
|
152
|
-
it "has no forward markers at any level" do
|
153
|
-
node.forward_markers[0].should be_empty
|
154
|
-
node.forward_markers[1].should be_empty
|
155
|
-
node.forward_markers[2].should be_empty
|
156
|
-
end
|
157
|
-
|
158
|
-
it "has :f and :g as its only markers" do
|
159
|
-
node.markers.should have_markers(:f, :g)
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
@@ -1,91 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
class IntervalSkipList
|
4
|
-
public :insert_node, :delete_node, :nodes, :head, :next_node_height
|
5
|
-
end
|
6
|
-
|
7
|
-
module NextNodeHeightIsDeterministicSharedContext
|
8
|
-
extend RSpec::Core::SharedContext
|
9
|
-
|
10
|
-
before :each do
|
11
|
-
next_node_height_is_deterministic
|
12
|
-
end
|
13
|
-
|
14
|
-
# @todo we call this in one place other than here. cleanup?
|
15
|
-
def next_node_height_is_deterministic
|
16
|
-
node_heights = expected_node_heights.dup
|
17
|
-
stub(list).next_node_height { node_heights.shift }
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
module IntervalSkipListSpecHelper
|
22
|
-
def contain_marker(marker)
|
23
|
-
ContainMarkers.new(list, [marker])
|
24
|
-
end
|
25
|
-
|
26
|
-
def contain_markers(*markers)
|
27
|
-
ContainMarkers.new(list, markers)
|
28
|
-
end
|
29
|
-
|
30
|
-
class ContainMarkers
|
31
|
-
attr_reader :failure_message
|
32
|
-
|
33
|
-
def initialize(list, expected_markers)
|
34
|
-
@list = list
|
35
|
-
@expected_markers = expected_markers
|
36
|
-
end
|
37
|
-
|
38
|
-
def matches?(target_range)
|
39
|
-
@target_range = target_range
|
40
|
-
|
41
|
-
@target_range.each do |i|
|
42
|
-
markers = @list.containing(i)
|
43
|
-
|
44
|
-
@expected_markers.each do |expected_marker|
|
45
|
-
unless markers.include?(expected_marker)
|
46
|
-
@failure_message = "Expected #{expected_marker.inspect} to contain #{i}, but it doesn't. #{i} is contained by: #{markers.inspect}."
|
47
|
-
return false
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
markers.each do |marker|
|
52
|
-
unless @expected_markers.include?(marker)
|
53
|
-
@failure_message = "Did not expect #{marker.inspect} to contain #{i}. Only expected #{@expected_markers.inspect}."
|
54
|
-
return false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
true
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def have_markers(*markers)
|
64
|
-
HaveMarkers.new(markers)
|
65
|
-
end
|
66
|
-
|
67
|
-
def have_marker(marker)
|
68
|
-
HaveMarkers.new([marker])
|
69
|
-
end
|
70
|
-
|
71
|
-
class HaveMarkers
|
72
|
-
def initialize(expected_markers)
|
73
|
-
@expected_markers = expected_markers
|
74
|
-
end
|
75
|
-
|
76
|
-
def matches?(target)
|
77
|
-
@target = target
|
78
|
-
return false unless @target.size == @expected_markers.size
|
79
|
-
@expected_markers.each do |expected_marker|
|
80
|
-
return false unless @target.include?(expected_marker)
|
81
|
-
end
|
82
|
-
true
|
83
|
-
end
|
84
|
-
|
85
|
-
def failure_message
|
86
|
-
"Expected #{@target.inspect} to include only #{@expected_markers.inspect}"
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
require 'runtime/interval_skip_list/palindromic_fixture'
|