rley 0.7.07 → 0.7.08
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +348 -54
- data/LICENSE.txt +1 -1
- data/README.md +3 -2
- data/examples/NLP/engtagger.rb +193 -190
- data/examples/NLP/nano_eng/nano_grammar.rb +5 -5
- data/examples/data_formats/JSON/cli_options.rb +1 -1
- data/examples/data_formats/JSON/json_ast_builder.rb +12 -9
- data/examples/data_formats/JSON/json_ast_nodes.rb +12 -21
- data/examples/data_formats/JSON/json_grammar.rb +2 -2
- data/examples/data_formats/JSON/json_lexer.rb +8 -8
- data/examples/data_formats/JSON/json_minifier.rb +1 -1
- data/examples/general/calc_iter1/calc_ast_builder.rb +13 -10
- data/examples/general/calc_iter1/calc_ast_nodes.rb +23 -37
- data/examples/general/calc_iter1/calc_grammar.rb +2 -2
- data/examples/general/calc_iter1/calc_lexer.rb +6 -4
- data/examples/general/calc_iter1/spec/calculator_spec.rb +5 -5
- data/examples/general/calc_iter2/calc_ast_builder.rb +5 -3
- data/examples/general/calc_iter2/calc_ast_nodes.rb +27 -43
- data/examples/general/calc_iter2/calc_grammar.rb +3 -3
- data/examples/general/calc_iter2/calc_lexer.rb +11 -10
- data/examples/general/calc_iter2/spec/calculator_spec.rb +26 -26
- data/examples/general/left.rb +2 -2
- data/examples/general/right.rb +2 -2
- data/lib/rley/base/dotted_item.rb +23 -31
- data/lib/rley/constants.rb +2 -2
- data/lib/rley/engine.rb +20 -23
- data/lib/rley/formatter/asciitree.rb +3 -3
- data/lib/rley/formatter/bracket_notation.rb +1 -8
- data/lib/rley/formatter/debug.rb +6 -6
- data/lib/rley/formatter/json.rb +2 -2
- data/lib/rley/gfg/call_edge.rb +1 -1
- data/lib/rley/gfg/edge.rb +5 -5
- data/lib/rley/gfg/end_vertex.rb +2 -6
- data/lib/rley/gfg/epsilon_edge.rb +1 -5
- data/lib/rley/gfg/grm_flow_graph.rb +27 -23
- data/lib/rley/gfg/item_vertex.rb +10 -10
- data/lib/rley/gfg/non_terminal_vertex.rb +4 -4
- data/lib/rley/gfg/scan_edge.rb +1 -1
- data/lib/rley/gfg/shortcut_edge.rb +2 -2
- data/lib/rley/gfg/start_vertex.rb +4 -8
- data/lib/rley/gfg/vertex.rb +43 -39
- data/lib/rley/lexical/token_range.rb +6 -6
- data/lib/rley/parse_forest_visitor.rb +5 -5
- data/lib/rley/parse_rep/ast_base_builder.rb +9 -11
- data/lib/rley/parse_rep/cst_builder.rb +5 -6
- data/lib/rley/parse_rep/parse_forest_builder.rb +20 -18
- data/lib/rley/parse_rep/parse_forest_factory.rb +3 -3
- data/lib/rley/parse_rep/parse_rep_creator.rb +11 -13
- data/lib/rley/parse_rep/parse_tree_builder.rb +4 -4
- data/lib/rley/parse_rep/parse_tree_factory.rb +27 -27
- data/lib/rley/parse_tree_visitor.rb +1 -1
- data/lib/rley/parser/error_reason.rb +4 -5
- data/lib/rley/parser/gfg_chart.rb +20 -22
- data/lib/rley/parser/gfg_parsing.rb +16 -30
- data/lib/rley/parser/parse_entry.rb +25 -31
- data/lib/rley/parser/parse_entry_set.rb +18 -15
- data/lib/rley/parser/parse_entry_tracker.rb +4 -4
- data/lib/rley/parser/parse_state.rb +16 -21
- data/lib/rley/parser/parse_state_tracker.rb +4 -4
- data/lib/rley/parser/parse_tracer.rb +13 -13
- data/lib/rley/parser/parse_walker_factory.rb +23 -28
- data/lib/rley/parser/state_set.rb +9 -10
- data/lib/rley/ptree/non_terminal_node.rb +7 -5
- data/lib/rley/ptree/parse_tree.rb +3 -3
- data/lib/rley/ptree/parse_tree_node.rb +5 -5
- data/lib/rley/ptree/terminal_node.rb +7 -7
- data/lib/rley/rley_error.rb +12 -12
- data/lib/rley/sppf/alternative_node.rb +6 -6
- data/lib/rley/sppf/composite_node.rb +7 -7
- data/lib/rley/sppf/epsilon_node.rb +3 -3
- data/lib/rley/sppf/leaf_node.rb +3 -3
- data/lib/rley/sppf/parse_forest.rb +16 -16
- data/lib/rley/sppf/sppf_node.rb +7 -8
- data/lib/rley/sppf/token_node.rb +3 -3
- data/lib/rley/syntax/grammar.rb +5 -5
- data/lib/rley/syntax/grammar_builder.rb +9 -9
- data/lib/rley/syntax/grm_symbol.rb +6 -6
- data/lib/rley/syntax/non_terminal.rb +9 -15
- data/lib/rley/syntax/production.rb +10 -10
- data/lib/rley/syntax/symbol_seq.rb +7 -9
- data/lib/rley/syntax/terminal.rb +4 -5
- data/lib/rley/syntax/verbatim_symbol.rb +3 -3
- data/lib/support/base_tokenizer.rb +19 -18
- data/spec/rley/base/dotted_item_spec.rb +2 -2
- data/spec/rley/engine_spec.rb +17 -15
- data/spec/rley/formatter/asciitree_spec.rb +7 -7
- data/spec/rley/formatter/bracket_notation_spec.rb +13 -13
- data/spec/rley/formatter/json_spec.rb +1 -1
- data/spec/rley/gfg/end_vertex_spec.rb +5 -5
- data/spec/rley/gfg/item_vertex_spec.rb +10 -10
- data/spec/rley/gfg/non_terminal_vertex_spec.rb +3 -3
- data/spec/rley/gfg/shortcut_edge_spec.rb +1 -1
- data/spec/rley/gfg/start_vertex_spec.rb +5 -5
- data/spec/rley/gfg/vertex_spec.rb +3 -3
- data/spec/rley/lexical/token_range_spec.rb +16 -16
- data/spec/rley/lexical/token_spec.rb +2 -2
- data/spec/rley/parse_forest_visitor_spec.rb +165 -163
- data/spec/rley/parse_rep/ambiguous_parse_spec.rb +44 -44
- data/spec/rley/parse_rep/ast_builder_spec.rb +6 -6
- data/spec/rley/parse_rep/cst_builder_spec.rb +5 -5
- data/spec/rley/parse_rep/groucho_spec.rb +21 -21
- data/spec/rley/parse_rep/parse_forest_builder_spec.rb +26 -26
- data/spec/rley/parse_rep/parse_forest_factory_spec.rb +6 -6
- data/spec/rley/parse_rep/parse_tree_factory_spec.rb +2 -2
- data/spec/rley/parse_tree_visitor_spec.rb +10 -8
- data/spec/rley/parser/error_reason_spec.rb +6 -6
- data/spec/rley/parser/gfg_earley_parser_spec.rb +4 -2
- data/spec/rley/parser/gfg_parsing_spec.rb +4 -8
- data/spec/rley/parser/parse_entry_spec.rb +19 -19
- data/spec/rley/parser/parse_state_spec.rb +5 -5
- data/spec/rley/parser/parse_walker_factory_spec.rb +1 -1
- data/spec/rley/parser/state_set_spec.rb +22 -22
- data/spec/rley/ptree/non_terminal_node_spec.rb +5 -3
- data/spec/rley/ptree/parse_tree_node_spec.rb +4 -4
- data/spec/rley/ptree/terminal_node_spec.rb +6 -6
- data/spec/rley/sppf/alternative_node_spec.rb +6 -6
- data/spec/rley/sppf/non_terminal_node_spec.rb +3 -3
- data/spec/rley/sppf/token_node_spec.rb +4 -4
- data/spec/rley/support/ambiguous_grammar_helper.rb +3 -4
- data/spec/rley/support/grammar_abc_helper.rb +2 -4
- data/spec/rley/support/grammar_ambig01_helper.rb +4 -5
- data/spec/rley/support/grammar_arr_int_helper.rb +4 -5
- data/spec/rley/support/grammar_b_expr_helper.rb +4 -5
- data/spec/rley/support/grammar_l0_helper.rb +10 -11
- data/spec/rley/support/grammar_pb_helper.rb +6 -5
- data/spec/rley/support/grammar_sppf_helper.rb +1 -1
- data/spec/rley/syntax/grammar_builder_spec.rb +5 -5
- data/spec/rley/syntax/grammar_spec.rb +6 -6
- data/spec/rley/syntax/grm_symbol_spec.rb +1 -1
- data/spec/rley/syntax/non_terminal_spec.rb +8 -8
- data/spec/rley/syntax/production_spec.rb +13 -13
- data/spec/rley/syntax/symbol_seq_spec.rb +2 -2
- data/spec/rley/syntax/terminal_spec.rb +5 -5
- data/spec/rley/syntax/verbatim_symbol_spec.rb +1 -1
- data/spec/spec_helper.rb +0 -12
- data/spec/support/base_tokenizer_spec.rb +7 -2
- metadata +21 -62
- data/.simplecov +0 -8
@@ -25,12 +25,12 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
25
25
|
builder = Syntax::GrammarBuilder.new do
|
26
26
|
add_terminals('a', 'b')
|
27
27
|
rule 'Phi' => 'S'
|
28
|
-
rule 'S' =>
|
29
|
-
rule 'S' =>
|
28
|
+
rule 'S' => 'A T'
|
29
|
+
rule 'S' => 'a T'
|
30
30
|
rule 'A' => 'a'
|
31
|
-
rule 'A' =>
|
31
|
+
rule 'A' => 'B A'
|
32
32
|
rule 'B' => []
|
33
|
-
rule 'T' =>
|
33
|
+
rule 'T' => 'b b b'
|
34
34
|
end
|
35
35
|
builder.grammar
|
36
36
|
end
|
@@ -49,11 +49,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
49
49
|
end
|
50
50
|
|
51
51
|
# Emit a text representation of the current path.
|
52
|
-
def path_to_s
|
52
|
+
def path_to_s
|
53
53
|
text_parts = subject.curr_path.map do |path_element|
|
54
54
|
path_element.to_string(0)
|
55
55
|
end
|
56
|
-
|
56
|
+
text_parts.join('/')
|
57
57
|
end
|
58
58
|
|
59
59
|
context 'Initialization:' do
|
@@ -38,11 +38,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
38
38
|
end
|
39
39
|
|
40
40
|
# Emit a text representation of the current path.
|
41
|
-
def path_to_s
|
41
|
+
def path_to_s
|
42
42
|
text_parts = subject.curr_path.map do |path_element|
|
43
43
|
path_element.to_string(0)
|
44
44
|
end
|
45
|
-
|
45
|
+
text_parts.join('/')
|
46
46
|
end
|
47
47
|
|
48
48
|
|
@@ -11,7 +11,7 @@ require_relative './support/grammar_sppf_helper'
|
|
11
11
|
require_relative '../../lib/rley/parse_tree_visitor'
|
12
12
|
|
13
13
|
module Rley # Open this namespace to avoid module qualifier prefixes
|
14
|
-
describe ParseTreeVisitor do
|
14
|
+
describe ParseTreeVisitor do
|
15
15
|
let(:grammar_abc) do
|
16
16
|
sandbox = Object.new
|
17
17
|
sandbox.extend(GrammarABCHelper)
|
@@ -45,7 +45,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
45
45
|
# Capital letters represent non-terminal nodes
|
46
46
|
let(:grm_abc_ptree1) do
|
47
47
|
engine = Rley::Engine.new
|
48
|
-
engine.use_grammar(grammar_abc)
|
48
|
+
engine.use_grammar(grammar_abc)
|
49
49
|
parse_result = engine.parse(grm_abc_tokens1)
|
50
50
|
ptree = engine.convert(parse_result)
|
51
51
|
ptree
|
@@ -161,6 +161,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
161
161
|
subject.end_visit_ptree(grm_abc_ptree1)
|
162
162
|
end
|
163
163
|
|
164
|
+
# rubocop: disable Naming/VariableNumber
|
164
165
|
it 'should begin the visit when requested' do
|
165
166
|
# Reminder: parse tree structure is
|
166
167
|
# S[0,5]
|
@@ -209,11 +210,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
209
210
|
expectations.each do |(msg, args)|
|
210
211
|
expect(listener1).to receive(msg).with(*args).ordered
|
211
212
|
end
|
212
|
-
|
213
|
+
|
213
214
|
# Here we go...
|
214
215
|
subject.start
|
215
216
|
end
|
216
|
-
|
217
|
+
|
217
218
|
it 'should also visit in pre-order' do
|
218
219
|
# Reminder: parse tree structure is
|
219
220
|
# S[0,5]
|
@@ -228,7 +229,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
228
229
|
root = grm_abc_ptree1.root
|
229
230
|
# Here we defeat encapsulation for the good cause
|
230
231
|
subject.instance_variable_set(:@traversal, :pre_order)
|
231
|
-
|
232
|
+
|
232
233
|
children = root.subnodes
|
233
234
|
big_a_1 = children[0]
|
234
235
|
big_a_1_children = big_a_1.subnodes
|
@@ -239,7 +240,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
239
240
|
expectations = [
|
240
241
|
[:before_ptree, [grm_abc_ptree1]]
|
241
242
|
# TODO: fix this test
|
242
|
-
# [:before_subnodes, [root, children]],
|
243
|
+
# [:before_subnodes, [root, children]],
|
243
244
|
# [:before_non_terminal, [root]],
|
244
245
|
|
245
246
|
# [:before_non_terminal, [big_a_1]],
|
@@ -267,10 +268,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
267
268
|
expectations.each do |(msg, args)|
|
268
269
|
expect(listener1).to receive(msg).with(*args).ordered
|
269
270
|
end
|
270
|
-
|
271
|
+
|
271
272
|
# Here we go...
|
272
273
|
subject.start
|
273
|
-
end
|
274
|
+
end
|
275
|
+
# rubocop: enable Naming/VariableNumber
|
274
276
|
end # context
|
275
277
|
end # describe
|
276
278
|
end # module
|
@@ -46,8 +46,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
46
46
|
|
47
47
|
context 'Initialization:' do
|
48
48
|
it 'should be created with arguments' do
|
49
|
-
expect do
|
50
|
-
ExpectationNotMet.new(3, err_token, terminals)
|
49
|
+
expect do
|
50
|
+
ExpectationNotMet.new(3, err_token, terminals)
|
51
51
|
end.not_to raise_error
|
52
52
|
end
|
53
53
|
|
@@ -75,8 +75,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
75
75
|
|
76
76
|
context 'Initialization:' do
|
77
77
|
it 'should be created with arguments' do
|
78
|
-
expect do
|
79
|
-
UnexpectedToken.new(3, err_token, terminals)
|
78
|
+
expect do
|
79
|
+
UnexpectedToken.new(3, err_token, terminals)
|
80
80
|
end.not_to raise_error
|
81
81
|
end
|
82
82
|
end # context
|
@@ -107,8 +107,8 @@ MESSAGE_END
|
|
107
107
|
|
108
108
|
context 'Initialization:' do
|
109
109
|
it 'should be created with arguments' do
|
110
|
-
expect do
|
111
|
-
PrematureInputEnd.new(3, err_token, terminals)
|
110
|
+
expect do
|
111
|
+
PrematureInputEnd.new(3, err_token, terminals)
|
112
112
|
end.not_to raise_error
|
113
113
|
end
|
114
114
|
end # context
|
@@ -71,7 +71,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
71
71
|
|
72
72
|
# Helper method that mimicks the output of a tokenizer
|
73
73
|
# for the language specified by grammar_expr
|
74
|
-
def grm2_tokens
|
74
|
+
def grm2_tokens
|
75
75
|
input_sequence = [
|
76
76
|
{ '2' => 'integer' },
|
77
77
|
'+',
|
@@ -79,7 +79,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
79
79
|
'*',
|
80
80
|
{ '4' => 'integer' }
|
81
81
|
]
|
82
|
-
|
82
|
+
build_token_sequence(input_sequence, grammar_expr)
|
83
83
|
end
|
84
84
|
|
85
85
|
# Default instantiation rule
|
@@ -104,6 +104,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
104
104
|
end # context
|
105
105
|
|
106
106
|
context 'Parsing: ' do
|
107
|
+
# rubocop: disable Naming/VariableNumber
|
107
108
|
it 'should parse a valid simple input' do
|
108
109
|
parse_result = subject.parse(grm1_tokens)
|
109
110
|
expect(parse_result.success?).to eq(true)
|
@@ -183,6 +184,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
183
184
|
expect(entry_set_5.entries.size).to eq(4)
|
184
185
|
compare_entry_texts(entry_set_5, expected)
|
185
186
|
end
|
187
|
+
# rubocop: enable Naming/VariableNumber
|
186
188
|
|
187
189
|
it 'should parse a valid simple expression' do
|
188
190
|
instance = GFGEarleyParser.new(grammar_expr)
|
@@ -95,14 +95,14 @@ SNIPPET
|
|
95
95
|
|
96
96
|
context 'Parsing:' do
|
97
97
|
# Utility method to fill the first entry set...
|
98
|
-
def fill_first_set
|
98
|
+
def fill_first_set
|
99
99
|
subject.start_rule(subject.initial_entry, 0)
|
100
100
|
subject.call_rule(subject.chart[0].last, 0)
|
101
101
|
subject.start_rule(subject.chart[0].last, 0)
|
102
102
|
end
|
103
103
|
|
104
104
|
# Utility method to initialize the second entry set...
|
105
|
-
def seed_second_set
|
105
|
+
def seed_second_set
|
106
106
|
# Cheating: we change the tokens to scan...
|
107
107
|
# Seeding second entry set...
|
108
108
|
subject.scan_rule(0, grm1_token_b[0])
|
@@ -301,8 +301,8 @@ SNIPPET
|
|
301
301
|
it 'should give a text representation of itself' do
|
302
302
|
repr = subject.to_s
|
303
303
|
expect(repr).to match(/^success\? true/)
|
304
|
-
|
305
|
-
# Let's test the last chart state only
|
304
|
+
|
305
|
+
# Let's test the last chart state only
|
306
306
|
expectation = <<REPR
|
307
307
|
State[5]
|
308
308
|
T => integer . | 4
|
@@ -338,10 +338,6 @@ REPR
|
|
338
338
|
it 'should indicate whether a parse succeeded' do
|
339
339
|
expect(subject.success?).to be_truthy
|
340
340
|
end
|
341
|
-
|
342
|
-
it 'should build a parse forest' do
|
343
|
-
expect { subject.parse_forest }.not_to raise_error if subject.success?
|
344
|
-
end
|
345
341
|
end # context
|
346
342
|
end # describe
|
347
343
|
end # module
|
@@ -52,7 +52,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
52
52
|
it 'should know the origin value' do
|
53
53
|
expect(subject.origin).to eq(origin_val)
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
it 'should have not antecedent at creation' do
|
57
57
|
expect(subject.antecedents).to be_empty
|
58
58
|
expect(subject).to be_orphan
|
@@ -91,13 +91,13 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
91
91
|
instance = ParseEntry.new(GFG::EndVertex.new('NT.'), 3)
|
92
92
|
expect(instance).to be_end_entry
|
93
93
|
end
|
94
|
-
|
94
|
+
|
95
95
|
it 'should know if the entry is a dotted item vertex' do
|
96
96
|
expect(subject).not_to be_dotted_entry
|
97
97
|
|
98
98
|
instance = ParseEntry.new(GFG::ItemVertex.new('P => S.'), 3)
|
99
99
|
expect(instance).to be_dotted_entry
|
100
|
-
end
|
100
|
+
end
|
101
101
|
|
102
102
|
it 'should know if the vertex is at end of production (if any)' do
|
103
103
|
# Case: start vertex
|
@@ -120,7 +120,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
120
120
|
instance4 = ParseEntry.new(v2, 3)
|
121
121
|
expect(instance4).to be_exit_entry
|
122
122
|
end
|
123
|
-
|
123
|
+
|
124
124
|
it 'should know if the vertex is at begin of production (if any)' do
|
125
125
|
# Case: start vertex
|
126
126
|
instance1 = ParseEntry.new(GFG::StartVertex.new('.NT'), 3)
|
@@ -131,17 +131,17 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
131
131
|
expect(instance2).not_to be_entry_entry
|
132
132
|
|
133
133
|
# Case: item vertex not at begin of rhs
|
134
|
-
d1 = Base::DottedItem.new(sample_prod, 1)
|
134
|
+
d1 = Base::DottedItem.new(sample_prod, 1)
|
135
135
|
v1 = GFG::ItemVertex.new(d1)
|
136
136
|
instance3 = ParseEntry.new(v1, 3)
|
137
137
|
expect(instance3).not_to be_entry_entry
|
138
138
|
|
139
139
|
# Case: item vertex at end of rhs
|
140
|
-
d2 = Base::DottedItem.new(sample_prod, 0)
|
141
|
-
v2 = GFG::ItemVertex.new(d2)
|
140
|
+
d2 = Base::DottedItem.new(sample_prod, 0)
|
141
|
+
v2 = GFG::ItemVertex.new(d2)
|
142
142
|
instance4 = ParseEntry.new(v2, 3)
|
143
143
|
expect(instance4).to be_entry_entry
|
144
|
-
end
|
144
|
+
end
|
145
145
|
|
146
146
|
it 'should know the symbol before the dot (if any)' do
|
147
147
|
# Case: start vertex
|
@@ -151,20 +151,20 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
151
151
|
# Case: end vertex
|
152
152
|
instance2 = ParseEntry.new(GFG::EndVertex.new('NT.'), 3)
|
153
153
|
expect(instance2.prev_symbol).to be_nil # Really correct?
|
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
|
-
expect(instance3.prev_symbol).to eq('symbol')
|
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
|
-
expect(instance4.prev_symbol).to be_nil
|
165
|
+
expect(instance4.prev_symbol).to be_nil
|
166
166
|
end
|
167
|
-
|
167
|
+
|
168
168
|
it 'should know the next expected symbol (if any)' do
|
169
169
|
# Case: start vertex
|
170
170
|
instance1 = ParseEntry.new(GFG::StartVertex.new('.NT'), 3)
|
@@ -173,19 +173,19 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
173
173
|
# Case: end vertex
|
174
174
|
instance2 = ParseEntry.new(GFG::EndVertex.new('NT.'), 3)
|
175
175
|
expect(instance2.next_symbol).to be_nil
|
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
|
-
expect(instance3.next_symbol).to eq('symbol')
|
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
|
-
expect(instance4.next_symbol).to be_nil
|
188
|
-
end
|
187
|
+
expect(instance4.next_symbol).to be_nil
|
188
|
+
end
|
189
189
|
|
190
190
|
it 'should accept antecedents' do
|
191
191
|
antecedent = ParseEntry.new(vertex2, origin_val)
|
@@ -198,7 +198,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
198
198
|
expected = '.sentence | 3'
|
199
199
|
expect(subject.to_s).to eq(expected)
|
200
200
|
end
|
201
|
-
|
201
|
+
|
202
202
|
it 'should be inspectable' do
|
203
203
|
subject.add_antecedent(subject) # Cheat for the good cause...
|
204
204
|
# expected = '.sentence | 3'
|
@@ -209,8 +209,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
209
209
|
pattern2 = /@origin=3 @antecedents=\[/
|
210
210
|
expect(subject.inspect).to match(pattern2)
|
211
211
|
suffix = /<Rley::GFG::StartVertex:\d+ label=\.sentence> @origin=3\]>$/
|
212
|
-
expect(subject.inspect).to match(suffix)
|
213
|
-
end
|
212
|
+
expect(subject.inspect).to match(suffix)
|
213
|
+
end
|
214
214
|
end # context
|
215
215
|
end # describe
|
216
216
|
end # module
|
@@ -63,7 +63,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
63
63
|
item = Base::DottedItem.new(aProd, aRank)
|
64
64
|
ParseState.new(item, aVal)
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
it 'should compare with itself' do
|
68
68
|
synonym = subject # Fool Rubocop
|
69
69
|
expect(subject == synonym).to eq(true)
|
@@ -81,14 +81,14 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
81
81
|
diff_rule = ParseState.new(other_dotted_rule, 3)
|
82
82
|
expect(subject == diff_rule).to eq(false)
|
83
83
|
end
|
84
|
-
|
84
|
+
|
85
85
|
it 'should know if the parsing is at the start of the production' do
|
86
86
|
expect(subject).not_to be_predicted
|
87
87
|
at_start = Base::DottedItem.new(sample_prod, 0)
|
88
88
|
|
89
89
|
instance = ParseState.new(at_start, 0)
|
90
90
|
expect(instance).to be_predicted
|
91
|
-
end
|
91
|
+
end
|
92
92
|
|
93
93
|
it 'should know if the parsing reached the end of the production' do
|
94
94
|
expect(subject).not_to be_complete
|
@@ -101,7 +101,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
101
101
|
it 'should know the next expected symbol' do
|
102
102
|
expect(subject.next_symbol).to eq(t_c)
|
103
103
|
end
|
104
|
-
|
104
|
+
|
105
105
|
it 'should know whether another instance follows this one' do
|
106
106
|
expect(subject.precedes?(subject)).to eq(false)
|
107
107
|
state1 = new_parse_state(sample_prod, 1, origin_val)
|
@@ -112,7 +112,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
112
112
|
state3 = new_parse_state(sample_prod, 3, origin_val)
|
113
113
|
expect(state3.precedes?(state0)).to eq(false)
|
114
114
|
end
|
115
|
-
|
115
|
+
|
116
116
|
it 'should know its text representation' do
|
117
117
|
expected = 'sentence => A B . C | 3'
|
118
118
|
expect(subject.to_s).to eq(expected)
|
@@ -303,7 +303,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
303
303
|
event18 = walker.next
|
304
304
|
expectations = [:revisit, 'T. | 1', 4]
|
305
305
|
event_expectations(event18, expectations)
|
306
|
-
|
306
|
+
|
307
307
|
# Lazy walk: make start entry .T the current one
|
308
308
|
# Multiple visit occurred: jump to antecedent of start entry
|
309
309
|
event19 = walker.next
|
@@ -19,7 +19,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
19
19
|
it 'should be created without argument' do
|
20
20
|
expect { StateSet.new }.not_to raise_error
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
it 'should be empty at creation' do
|
24
24
|
expect(subject.states).to be_empty
|
25
25
|
end
|
@@ -33,19 +33,19 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
33
33
|
subject.push_state(state2)
|
34
34
|
expect(subject.states).to eq([state1, state2])
|
35
35
|
end
|
36
|
-
|
36
|
+
|
37
37
|
it 'should ignore a second push of a state' do
|
38
38
|
expect(subject.states).to be_empty
|
39
39
|
subject.push_state(state1)
|
40
40
|
subject.push_state(state2)
|
41
41
|
expect(subject.states).to eq([state1, state2])
|
42
|
-
|
42
|
+
|
43
43
|
# One tries to push an already pushed state
|
44
44
|
expect(subject.push_state(state1)).to be_falsy
|
45
|
-
|
45
|
+
|
46
46
|
# ...It is not added
|
47
|
-
expect(subject.states).to eq([state1, state2])
|
48
|
-
end
|
47
|
+
expect(subject.states).to eq([state1, state2])
|
48
|
+
end
|
49
49
|
|
50
50
|
it 'should list the states expecting a given terminal' do
|
51
51
|
# Case of no state
|
@@ -73,52 +73,52 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
73
73
|
expect(dotted_rule2).to receive(:production).and_return(a_prod)
|
74
74
|
expect(subject.states_for(a_prod)).to eq([state2])
|
75
75
|
end
|
76
|
-
|
76
|
+
|
77
77
|
it 'should list the states that rewrite a given non-terminal' do
|
78
78
|
non_term = double('fake-non-terminal')
|
79
79
|
prod1 = double('fake-production1')
|
80
80
|
prod2 = double('fake-production2')
|
81
|
-
|
81
|
+
|
82
82
|
# Adding states
|
83
83
|
subject.push_state(state1)
|
84
84
|
subject.push_state(state2)
|
85
85
|
expect(dotted_rule1).to receive(:production).and_return(prod1)
|
86
|
-
expect(prod1).to receive(:lhs).and_return(:dummy)
|
86
|
+
expect(prod1).to receive(:lhs).and_return(:dummy)
|
87
87
|
expect(dotted_rule2).to receive(:production).and_return(prod2)
|
88
88
|
expect(dotted_rule2).to receive(:reduce_item?).and_return(true)
|
89
|
-
expect(prod2).to receive(:lhs).and_return(non_term)
|
89
|
+
expect(prod2).to receive(:lhs).and_return(non_term)
|
90
90
|
expect(subject.states_rewriting(non_term)).to eq([state2])
|
91
91
|
end
|
92
|
-
|
92
|
+
|
93
93
|
it 'should list of ambiguous states' do
|
94
94
|
prod1 = double('fake-production1')
|
95
95
|
prod2 = double('fake-production2')
|
96
96
|
expect(subject.ambiguities.size).to eq(0)
|
97
|
-
|
97
|
+
|
98
98
|
# Adding states
|
99
99
|
subject.push_state(state1)
|
100
100
|
allow(dotted_rule1).to receive(:production).and_return(prod1)
|
101
|
-
allow(dotted_rule1).to receive(:
|
102
|
-
allow(dotted_rule1).to receive(:lhs).and_return(:something)
|
101
|
+
allow(dotted_rule1).to receive(:reduce_item?).and_return(true)
|
102
|
+
allow(dotted_rule1).to receive(:lhs).and_return(:something)
|
103
103
|
expect(subject.ambiguities.size).to eq(0)
|
104
104
|
allow(dotted_rule2).to receive(:production).and_return(prod2)
|
105
|
-
allow(dotted_rule2).to receive(:
|
106
|
-
allow(dotted_rule2).to receive(:lhs).and_return(:something_else)
|
105
|
+
allow(dotted_rule2).to receive(:reduce_item?).and_return(true)
|
106
|
+
allow(dotted_rule2).to receive(:lhs).and_return(:something_else)
|
107
107
|
subject.push_state(state2)
|
108
108
|
expect(subject.ambiguities.size).to eq(0)
|
109
109
|
dotted_rule3 = double('fake_dotted_rule3')
|
110
110
|
allow(dotted_rule3).to receive(:production).and_return(prod2)
|
111
|
-
allow(dotted_rule3).to receive(:
|
112
|
-
allow(dotted_rule3).to receive(:lhs).and_return(:something_else)
|
111
|
+
allow(dotted_rule3).to receive(:reduce_item?).and_return(true)
|
112
|
+
allow(dotted_rule3).to receive(:lhs).and_return(:something_else)
|
113
113
|
state3 = ParseState.new(dotted_rule3, 5)
|
114
|
-
subject.push_state(state3)
|
115
|
-
expect(subject.ambiguities[0]).to eq([state2, state3])
|
114
|
+
subject.push_state(state3)
|
115
|
+
expect(subject.ambiguities[0]).to eq([state2, state3])
|
116
116
|
end
|
117
|
-
|
117
|
+
|
118
118
|
it 'should complain when impossible predecessor of parse state' do
|
119
119
|
subject.push_state(state1)
|
120
120
|
subject.push_state(state2)
|
121
|
-
expect(dotted_rule1).to receive(:prev_position).and_return(nil)
|
121
|
+
expect(dotted_rule1).to receive(:prev_position).and_return(nil)
|
122
122
|
err = StandardError
|
123
123
|
expect { subject.predecessor_state(state1) }.to raise_error(err)
|
124
124
|
end
|