rley 0.3.01 → 0.3.04
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -3
- data/Gemfile +1 -1
- data/examples/parsers/parsing_groucho.rb +1 -3
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/parser/gfg_parsing.rb +5 -179
- data/lib/rley/parser/parse_forest_builder.rb +62 -77
- data/lib/rley/parser/parse_walker_factory.rb +26 -17
- data/lib/rley.rb +1 -0
- data/spec/rley/gfg/end_vertex_spec.rb +1 -1
- data/spec/rley/gfg/shortcut_edge_spec.rb +6 -6
- data/spec/rley/gfg/start_vertex_spec.rb +1 -1
- data/spec/rley/parse_forest_visitor_spec.rb +1 -1
- data/spec/rley/parse_tree_visitor_spec.rb +1 -1
- data/spec/rley/parser/gfg_parsing_spec.rb +3 -6
- data/spec/rley/parser/parse_entry_set_spec.rb +19 -19
- data/spec/rley/parser/parse_entry_spec.rb +6 -6
- data/spec/rley/parser/parse_forest_builder_spec.rb +374 -79
- data/spec/rley/parser/parse_forest_factory_spec.rb +1 -1
- data/spec/rley/parser/parse_walker_factory_spec.rb +60 -40
- data/spec/rley/parser/state_set_spec.rb +8 -8
- data/spec/rley/support/grammar_L0_helper.rb +81 -0
- metadata +11 -13
- data/spec/rley/sppf/antecedence_graph.rb +0 -87
- data/spec/rley/sppf/forest_representation.rb +0 -136
- data/spec/rley/sppf/gfg_representation.rb +0 -111
@@ -15,7 +15,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'should know its label' do
|
18
|
-
|
18
|
+
expect(sample_nt).to receive(:to_s).and_return('NT')
|
19
19
|
expect(subject.label).to eq('.NT')
|
20
20
|
end
|
21
21
|
end # context
|
@@ -224,7 +224,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
224
224
|
[:after_pforest, [grm_abc_pforest1]]
|
225
225
|
]
|
226
226
|
expectations.each do |(msg, args)|
|
227
|
-
|
227
|
+
expect(listener1).to receive(msg).with(*args).ordered
|
228
228
|
end
|
229
229
|
|
230
230
|
# Here we go...
|
@@ -206,7 +206,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
206
206
|
[:after_ptree, [grm_abc_ptree1]]
|
207
207
|
]
|
208
208
|
expectations.each do |(msg, args)|
|
209
|
-
|
209
|
+
expect(listener1).to receive(msg).with(*args).ordered
|
210
210
|
end
|
211
211
|
|
212
212
|
# Here we go...
|
@@ -317,12 +317,9 @@ SNIPPET
|
|
317
317
|
parser.parse(tokens)
|
318
318
|
end
|
319
319
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
entry_tracker = aParsing.send(:new_entry_tracker)
|
324
|
-
builder = aParsing.send(:forest_builder, entry_tracker.entry_set_index)
|
325
|
-
return [entry_tracker, builder]
|
320
|
+
it 'should build a parse forest' do
|
321
|
+
expect{subject.parse_forest }.not_to raise_error
|
322
|
+
|
326
323
|
end
|
327
324
|
=begin
|
328
325
|
it 'should create the root of a parse forest' do
|
@@ -99,19 +99,19 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
99
99
|
|
100
100
|
# Adding states
|
101
101
|
subject.push_entry(entry1)
|
102
|
-
|
103
|
-
|
104
|
-
|
102
|
+
expect(vertex1).to receive(:production).and_return(prod1)
|
103
|
+
expect(vertex1).to receive(:"reduce_item?").and_return(true)
|
104
|
+
expect(vertex1).to receive(:lhs).and_return(:something)
|
105
105
|
expect(subject.ambiguities.size).to eq(0)
|
106
|
-
|
107
|
-
|
108
|
-
|
106
|
+
expect(vertex2).to receive(:production).and_return(prod2)
|
107
|
+
expect(vertex2).to receive(:"reduce_item?").and_return(true)
|
108
|
+
expect(vertex2).to receive(:lhs).and_return(:something_else)
|
109
109
|
subject.push_entry(entry2)
|
110
110
|
expect(subject.ambiguities.size).to eq(0)
|
111
111
|
# dotted_rule3 = double('fake_dotted_rule3')
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
112
|
+
# expect(dotted_rule3).to receive(:production).and_return(prod2)
|
113
|
+
# expect(dotted_rule3).to receive(:"reduce_item?").and_return(true)
|
114
|
+
# expect(dotted_rule3).to receive(:lhs).and_return(:something_else)
|
115
115
|
# entry3 = ParseEntry.new(dotted_rule3, 5)
|
116
116
|
subject.push_entry(entry3)
|
117
117
|
expect(subject.ambiguities[0]).to eq([entry2, entry3])
|
@@ -125,8 +125,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
125
125
|
# Adding states
|
126
126
|
subject.push_entry(entry1)
|
127
127
|
subject.push_entry(entry2)
|
128
|
-
|
129
|
-
|
128
|
+
expect(vertex1).to receive(:next_symbol).and_return(:b)
|
129
|
+
expect(vertex2).to receive(:next_symbol).and_return(:a)
|
130
130
|
expect(subject.states_expecting(:a)).to eq([entry2])
|
131
131
|
expect(subject.states_expecting(:b)).to eq([entry1])
|
132
132
|
end
|
@@ -140,8 +140,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
140
140
|
# Adding states
|
141
141
|
subject.push_entry(entry1)
|
142
142
|
subject.push_entry(entry2)
|
143
|
-
|
144
|
-
|
143
|
+
expect(vertex1).to receive(:production).and_return(:dummy)
|
144
|
+
expect(vertex2).to receive(:production).and_return(a_prod)
|
145
145
|
expect(subject.states_for(a_prod)).to eq([entry2])
|
146
146
|
end
|
147
147
|
|
@@ -153,11 +153,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
153
153
|
# Adding states
|
154
154
|
subject.push_entry(entry1)
|
155
155
|
subject.push_entry(entry2)
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
156
|
+
expect(vertex1).to receive(:production).and_return(prod1)
|
157
|
+
expect(prod1).to receive(:lhs).and_return(:dummy)
|
158
|
+
expect(vertex2).to receive(:production).and_return(prod2)
|
159
|
+
expect(vertex2).to receive(:reduce_item?).and_return(true)
|
160
|
+
expect(prod2).to receive(:lhs).and_return(non_term)
|
161
161
|
expect(subject.states_rewriting(non_term)).to eq([entry2])
|
162
162
|
end
|
163
163
|
|
@@ -166,7 +166,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
166
166
|
it 'should complain when impossible predecessor of parse state' do
|
167
167
|
subject.push_entry(entry1)
|
168
168
|
subject.push_entry(entry2)
|
169
|
-
|
169
|
+
expect(vertex1).to receive(:prev_position).and_return(nil)
|
170
170
|
err = StandardError
|
171
171
|
expect { subject.predecessor_state(entry1) }.to raise_error(err)
|
172
172
|
end
|
@@ -110,13 +110,13 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
110
110
|
|
111
111
|
# Case: item vertex not at end of rhs
|
112
112
|
v1 = double('vertex-not-at-end')
|
113
|
-
|
113
|
+
expect(v1).to receive(:complete?).and_return(false)
|
114
114
|
instance3 = ParseEntry.new(v1, 3)
|
115
115
|
expect(instance3).not_to be_exit_entry
|
116
116
|
|
117
117
|
# Case: item vertex at end of rhs
|
118
118
|
v2 = double('vertex-at-end')
|
119
|
-
|
119
|
+
expect(v2).to receive(:complete?).and_return(true)
|
120
120
|
instance4 = ParseEntry.new(v2, 3)
|
121
121
|
expect(instance4).to be_exit_entry
|
122
122
|
end
|
@@ -154,13 +154,13 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
154
154
|
|
155
155
|
# Case: item vertex not at start of rhs
|
156
156
|
v1 = double('vertex-not-at-start')
|
157
|
-
|
157
|
+
expect(v1).to receive(:prev_symbol).and_return('symbol')
|
158
158
|
instance3 = ParseEntry.new(v1, 3)
|
159
159
|
expect(instance3.prev_symbol).to eq('symbol')
|
160
160
|
|
161
161
|
# Case: item vertex at start of rhs
|
162
162
|
v2 = double('vertex-at-start')
|
163
|
-
|
163
|
+
expect(v2).to receive(:prev_symbol).and_return(nil)
|
164
164
|
instance4 = ParseEntry.new(v2, 0)
|
165
165
|
expect(instance4.prev_symbol).to be_nil
|
166
166
|
end
|
@@ -176,13 +176,13 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
176
176
|
|
177
177
|
# Case: item vertex not at end of rhs
|
178
178
|
v1 = double('vertex-not-at-end')
|
179
|
-
|
179
|
+
expect(v1).to receive(:next_symbol).and_return('symbol')
|
180
180
|
instance3 = ParseEntry.new(v1, 3)
|
181
181
|
expect(instance3.next_symbol).to eq('symbol')
|
182
182
|
|
183
183
|
# Case: item vertex at end of rhs
|
184
184
|
v2 = double('vertex-at-end')
|
185
|
-
|
185
|
+
expect(v2).to receive(:next_symbol).and_return(nil)
|
186
186
|
instance4 = ParseEntry.new(v2, 3)
|
187
187
|
expect(instance4.next_symbol).to be_nil
|
188
188
|
end
|