rley 0.7.07 → 0.7.08
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.
- 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
@@ -19,11 +19,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
19
19
|
include ExpectationHelper # Mix-in with expectation on parse entry sets
|
20
20
|
|
21
21
|
# Emit a text representation of the current path.
|
22
|
-
def path_to_s
|
22
|
+
def path_to_s
|
23
23
|
text_parts = subject.curr_path.map do |path_element|
|
24
24
|
path_element.to_string(0)
|
25
25
|
end
|
26
|
-
|
26
|
+
text_parts.join('/')
|
27
27
|
end
|
28
28
|
|
29
29
|
def next_event(eventType, anEntryText)
|
@@ -88,28 +88,28 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
88
88
|
|
89
89
|
next_event(:visit, 'S. | 4') # Event 5
|
90
90
|
path_prefix = 'P[0, 5]/S[0, 5]/Alt(S => S * S .)[0, 5]'
|
91
|
-
expected_curr_path(path_prefix
|
91
|
+
expected_curr_path("#{path_prefix}/S[4, 5]")
|
92
92
|
|
93
93
|
next_event(:visit, 'S => L . | 4') # Event 6
|
94
|
-
expected_path5 = path_prefix
|
94
|
+
expected_path5 = "#{path_prefix}/S[4, 5]"
|
95
95
|
expect(path_to_s).to eq(expected_path5)
|
96
96
|
|
97
97
|
next_event(:visit, 'L. | 4') # Event 7
|
98
|
-
expected_curr_path(path_prefix
|
98
|
+
expected_curr_path("#{path_prefix}/S[4, 5]/L[4, 5]")
|
99
99
|
|
100
100
|
next_event(:visit, 'L => integer . | 4') # Event 8
|
101
|
-
expected_curr_path(path_prefix
|
101
|
+
expected_curr_path("#{path_prefix}/S[4, 5]/L[4, 5]")
|
102
102
|
expected_first_child('integer[4, 5]')
|
103
103
|
|
104
104
|
next_event(:visit, 'L => . integer | 4') # Event 9
|
105
|
-
expected_curr_path(path_prefix
|
105
|
+
expected_curr_path("#{path_prefix}/S[4, 5]/L[4, 5]")
|
106
106
|
|
107
107
|
next_event(:visit, '.L | 4') # Event 10
|
108
|
-
expected_curr_path(path_prefix
|
108
|
+
expected_curr_path("#{path_prefix}/S[4, 5]")
|
109
109
|
|
110
110
|
next_event(:visit, 'S => . L | 4') # Event 11
|
111
111
|
expected_curr_parent('S[4, 5]')
|
112
|
-
expected_curr_path(path_prefix
|
112
|
+
expected_curr_path("#{path_prefix}/S[4, 5]")
|
113
113
|
|
114
114
|
next_event(:visit, '.S | 4') # Event 12
|
115
115
|
expected_curr_parent('Alt(S => S * S .)[0, 5]')
|
@@ -123,73 +123,73 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
123
123
|
expected_curr_path(path_prefix)
|
124
124
|
|
125
125
|
next_event(:visit, 'S. | 0') # Event 15
|
126
|
-
expected_curr_path(path_prefix
|
126
|
+
expected_curr_path("#{path_prefix}/S[0, 3]")
|
127
127
|
|
128
128
|
next_event(:visit, 'S => S + S . | 0') # Event 16
|
129
129
|
expected_curr_parent('S[0, 3]')
|
130
|
-
expected_curr_path(path_prefix
|
130
|
+
expected_curr_path("#{path_prefix}/S[0, 3]")
|
131
131
|
|
132
132
|
next_event(:visit, 'S. | 2') # Event 17
|
133
|
-
expected_curr_path(path_prefix
|
133
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]")
|
134
134
|
|
135
135
|
next_event(:visit, 'S => L . | 2') # Event 18
|
136
|
-
expected_curr_path(path_prefix
|
136
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]")
|
137
137
|
|
138
138
|
next_event(:visit, 'L. | 2') # Event 19
|
139
|
-
expected_curr_path(path_prefix
|
139
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]/L[2, 3]")
|
140
140
|
|
141
141
|
next_event(:visit, 'L => integer . | 2') # Event 20
|
142
|
-
expected_curr_path(path_prefix
|
142
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]/L[2, 3]")
|
143
143
|
expected_first_child('integer[2, 3]')
|
144
144
|
|
145
145
|
next_event(:visit, 'L => . integer | 2') # Event 21
|
146
|
-
expected_curr_path(path_prefix
|
146
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]/L[2, 3]")
|
147
147
|
|
148
148
|
next_event(:visit, '.L | 2') # Event 22
|
149
149
|
expected_curr_parent('S[2, 3]')
|
150
|
-
expected_curr_path(path_prefix
|
150
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]")
|
151
151
|
|
152
152
|
next_event(:visit, 'S => . L | 2') # Event 23
|
153
|
-
expected_curr_path(path_prefix
|
153
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]")
|
154
154
|
|
155
155
|
next_event(:visit, '.S | 2') # Event 24
|
156
|
-
expected_curr_path(path_prefix
|
156
|
+
expected_curr_path("#{path_prefix}/S[0, 3]")
|
157
157
|
|
158
158
|
next_event(:visit, 'S => S + . S | 0') # Event 24
|
159
|
-
expected_curr_path(path_prefix
|
159
|
+
expected_curr_path("#{path_prefix}/S[0, 3]")
|
160
160
|
expected_first_child('+[1, 2]')
|
161
161
|
|
162
162
|
next_event(:visit, 'S => S . + S | 0') # Event 25
|
163
|
-
expected_curr_path(path_prefix
|
163
|
+
expected_curr_path("#{path_prefix}/S[0, 3]")
|
164
164
|
|
165
165
|
next_event(:visit, 'S. | 0') # Event 27
|
166
166
|
expected_curr_parent('S[0, 1]')
|
167
|
-
expected_curr_path(path_prefix
|
167
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]")
|
168
168
|
|
169
169
|
next_event(:visit, 'S => L . | 0') # Event 28
|
170
|
-
expected_curr_path(path_prefix
|
170
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]")
|
171
171
|
|
172
172
|
next_event(:visit, 'L. | 0') # Event 29
|
173
|
-
expected_curr_path(path_prefix
|
173
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]/L[0, 1]")
|
174
174
|
|
175
175
|
next_event(:visit, 'L => integer . | 0') # Event 30
|
176
|
-
expected_curr_path(path_prefix
|
176
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]/L[0, 1]")
|
177
177
|
expected_first_child('integer[0, 1]')
|
178
178
|
|
179
179
|
next_event(:visit, 'L => . integer | 0') # Event 31
|
180
|
-
expected_curr_path(path_prefix
|
180
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]/L[0, 1]")
|
181
181
|
|
182
182
|
next_event(:visit, '.L | 0') # Event 32
|
183
|
-
expected_curr_path(path_prefix
|
183
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]")
|
184
184
|
|
185
185
|
next_event(:visit, 'S => . L | 0') # Event 33
|
186
|
-
expected_curr_path(path_prefix
|
186
|
+
expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]")
|
187
187
|
|
188
188
|
next_event(:visit, '.S | 0') # Event 34
|
189
|
-
expected_curr_path(path_prefix
|
189
|
+
expected_curr_path("#{path_prefix}/S[0, 3]")
|
190
190
|
|
191
191
|
next_event(:visit, 'S => . S + S | 0') # Event 35
|
192
|
-
expected_curr_path(path_prefix
|
192
|
+
expected_curr_path("#{path_prefix}/S[0, 3]")
|
193
193
|
|
194
194
|
next_event(:revisit, '.S | 0') # REVISIT Event 36
|
195
195
|
expected_curr_parent('Alt(S => S * S .)[0, 5]')
|
@@ -210,42 +210,42 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
210
210
|
next_event(:backtrack, 'S. | 0') # BACKTRACK Event 41
|
211
211
|
|
212
212
|
expected_curr_path('P[0, 5]/S[0, 5]')
|
213
|
-
|
213
|
+
|
214
214
|
next_event(:visit, 'S => S + S . | 0') # Event 42
|
215
215
|
expected_curr_parent('Alt(S => S + S .)[0, 5]')
|
216
216
|
path_prefix = 'P[0, 5]/S[0, 5]/Alt(S => S + S .)[0, 5]'
|
217
217
|
expected_curr_path(path_prefix)
|
218
218
|
|
219
219
|
next_event(:visit, 'S. | 2') # Event 43
|
220
|
-
expected_curr_path(path_prefix
|
220
|
+
expected_curr_path("#{path_prefix}/S[2, 5]")
|
221
221
|
|
222
222
|
next_event(:visit, 'S => S * S . | 2') # Event 44
|
223
|
-
expected_curr_path(path_prefix
|
224
|
-
|
223
|
+
expected_curr_path("#{path_prefix}/S[2, 5]")
|
224
|
+
|
225
225
|
# Up to now everything was running OK.
|
226
|
-
# Next steps are going wrong...
|
226
|
+
# Next steps are going wrong...
|
227
227
|
|
228
228
|
next_event(:revisit, 'S. | 4') # Event 45
|
229
|
-
expected_curr_path(path_prefix
|
229
|
+
expected_curr_path("#{path_prefix}/S[2, 5]")
|
230
230
|
expected_first_child('S[4, 5]')
|
231
|
-
|
231
|
+
|
232
232
|
next_event(:visit, 'S => S * . S | 2') # Event 46
|
233
|
-
expected_curr_path(path_prefix
|
233
|
+
expected_curr_path("#{path_prefix}/S[2, 5]")
|
234
234
|
expected_first_child('*[3, 4]')
|
235
235
|
|
236
236
|
next_event(:visit, 'S => S . * S | 2') # Event 47
|
237
|
-
expected_curr_path(path_prefix
|
238
|
-
|
237
|
+
expected_curr_path("#{path_prefix}/S[2, 5]")
|
238
|
+
|
239
239
|
next_event(:revisit, 'S. | 2') # Event 48
|
240
|
-
expected_curr_path(path_prefix
|
240
|
+
expected_curr_path("#{path_prefix}/S[2, 5]")
|
241
241
|
|
242
242
|
next_event(:visit, 'S => . S * S | 2') # Event 49
|
243
|
-
expected_curr_path(path_prefix
|
243
|
+
expected_curr_path("#{path_prefix}/S[2, 5]")
|
244
244
|
|
245
245
|
next_event(:revisit, '.S | 2') # Event 50
|
246
246
|
expected_curr_parent('Alt(S => S + S .)[0, 5]')
|
247
247
|
expected_curr_path(path_prefix)
|
248
|
-
|
248
|
+
|
249
249
|
# TODO: review previous and next steps...
|
250
250
|
|
251
251
|
next_event(:revisit, 'S => S + . S | 0') # Event 51
|
@@ -269,7 +269,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
269
269
|
expected_curr_path('P[0, 5]')
|
270
270
|
|
271
271
|
next_event(:revisit, '.P | 0') # Event 57
|
272
|
-
expected_curr_path('')
|
272
|
+
expected_curr_path('')
|
273
273
|
end
|
274
274
|
end # context
|
275
275
|
end # describe
|
@@ -12,16 +12,15 @@ require_relative '../support/expectation_helper'
|
|
12
12
|
require_relative '../support/grammar_b_expr_helper'
|
13
13
|
require_relative '../support/grammar_arr_int_helper'
|
14
14
|
|
15
|
-
|
16
15
|
module Rley # This module is used as a namespace
|
17
16
|
module ParseRep # This module is used as a namespace
|
18
17
|
ArrayNode = Struct.new(:children) do
|
19
|
-
def initialize
|
18
|
+
def initialize
|
20
19
|
super
|
21
20
|
self.children = []
|
22
21
|
end
|
23
22
|
|
24
|
-
def interpret
|
23
|
+
def interpret
|
25
24
|
return children.map(&:interpret)
|
26
25
|
end
|
27
26
|
end
|
@@ -33,17 +32,18 @@ module Rley # This module is used as a namespace
|
|
33
32
|
self.position = aPosition
|
34
33
|
end
|
35
34
|
|
36
|
-
def interpret
|
35
|
+
def interpret
|
37
36
|
value
|
38
37
|
end
|
39
38
|
end
|
40
39
|
|
40
|
+
# rubocop: disable Naming/VariableNumber
|
41
41
|
class ASTBuilder < ASTBaseBuilder
|
42
42
|
Terminal2NodeClass = {
|
43
43
|
'integer' => IntegerNode
|
44
44
|
}.freeze
|
45
45
|
|
46
|
-
def terminal2node
|
46
|
+
def terminal2node
|
47
47
|
Terminal2NodeClass
|
48
48
|
end
|
49
49
|
|
@@ -80,10 +80,10 @@ module Rley # This module is used as a namespace
|
|
80
80
|
return node
|
81
81
|
end
|
82
82
|
end # class
|
83
|
+
# rubocop: enable Naming/VariableNumber
|
83
84
|
end # module
|
84
85
|
end # module
|
85
86
|
|
86
|
-
|
87
87
|
module Rley # Open this namespace to avoid module qualifier prefixes
|
88
88
|
module ParseRep
|
89
89
|
describe ASTBuilder do
|
@@ -71,8 +71,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
71
71
|
end
|
72
72
|
end # context
|
73
73
|
|
74
|
-
|
75
|
-
|
74
|
+
|
75
|
+
|
76
76
|
context 'Parse tree construction (no null symbol):' do
|
77
77
|
before(:each) do
|
78
78
|
parser = Parser::GFGEarleyParser.new(sample_grammar)
|
@@ -119,7 +119,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
119
119
|
# Event: revisit .S | 0 0
|
120
120
|
# Event: visit P => . S | 0 0
|
121
121
|
# Event: visit .P | 0 0
|
122
|
-
|
122
|
+
|
123
123
|
it 'should react to a first end event' do
|
124
124
|
event = @walker.next
|
125
125
|
expect { subject.receive_event(*event) }.not_to raise_error
|
@@ -428,10 +428,10 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
428
428
|
next_event('visit P => . arr | 0 0')
|
429
429
|
expect(stack).to be_empty
|
430
430
|
expect(@instance.result).not_to be_nil
|
431
|
-
|
431
|
+
|
432
432
|
next_event('visit .P | 0 0')
|
433
433
|
expect(stack).to be_empty
|
434
|
-
expect(@instance.result).not_to be_nil
|
434
|
+
expect(@instance.result).not_to be_nil
|
435
435
|
end
|
436
436
|
end # context
|
437
437
|
end # describe
|
@@ -25,41 +25,41 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
25
25
|
builder = Rley::Syntax::GrammarBuilder.new do
|
26
26
|
add_terminals('N', 'V', 'Pro') # N(oun), V(erb), Pro(noun)
|
27
27
|
add_terminals('Det', 'P') # Det(erminer), P(reposition)
|
28
|
-
rule 'S' =>
|
29
|
-
rule 'NP' =>
|
30
|
-
rule 'NP' =>
|
28
|
+
rule 'S' => 'NP VP'
|
29
|
+
rule 'NP' => 'Det N'
|
30
|
+
rule 'NP' => 'Det N PP'
|
31
31
|
rule 'NP' => 'Pro'
|
32
|
-
rule 'VP' =>
|
33
|
-
rule 'VP' =>
|
34
|
-
rule 'PP' =>
|
32
|
+
rule 'VP' => 'V NP'
|
33
|
+
rule 'VP' => 'VP PP'
|
34
|
+
rule 'PP' => 'P NP'
|
35
35
|
end
|
36
36
|
builder.grammar
|
37
37
|
end
|
38
38
|
|
39
39
|
# The lexicon is just a Hash with pairs of the form:
|
40
40
|
# word => terminal symbol name
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
let(:groucho_lexicon) do
|
42
|
+
{
|
43
|
+
'elephant' => 'N',
|
44
|
+
'pajamas' => 'N',
|
45
|
+
'shot' => 'V',
|
46
|
+
'I' => 'Pro',
|
47
|
+
'an' => 'Det',
|
48
|
+
'my' => 'Det',
|
49
|
+
'in' => 'P'
|
50
|
+
}
|
51
|
+
end
|
50
52
|
|
51
53
|
# Highly simplified tokenizer implementation.
|
52
54
|
def tokenizer(aText, aGrammar)
|
53
55
|
pos = Rley::Lexical::Position.new(1, 2) # Dummy position
|
54
|
-
|
55
|
-
term =
|
56
|
+
aText.scan(/\S+/).map do |word|
|
57
|
+
term = groucho_lexicon[word]
|
56
58
|
raise StandardError, "Word '#{word}' not found in lexicon" if term.nil?
|
57
59
|
|
58
60
|
terminal = aGrammar.name2symbol[term]
|
59
61
|
Rley::Lexical::Token.new(word, terminal, pos)
|
60
62
|
end
|
61
|
-
|
62
|
-
return tokens
|
63
63
|
end
|
64
64
|
|
65
65
|
let(:sentence_tokens) do
|
@@ -73,11 +73,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
73
73
|
end
|
74
74
|
|
75
75
|
# Emit a text representation of the current path.
|
76
|
-
def path_to_s
|
76
|
+
def path_to_s
|
77
77
|
text_parts = subject.curr_path.map do |path_element|
|
78
78
|
path_element.to_string(0)
|
79
79
|
end
|
80
|
-
|
80
|
+
text_parts.join('/')
|
81
81
|
end
|
82
82
|
|
83
83
|
def next_event(eventType, anEntryText)
|
@@ -26,12 +26,12 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
26
26
|
builder = Syntax::GrammarBuilder.new do
|
27
27
|
add_terminals('a', 'b')
|
28
28
|
rule 'Phi' => 'S'
|
29
|
-
rule 'S' =>
|
30
|
-
rule 'S' =>
|
29
|
+
rule 'S' => 'A T'
|
30
|
+
rule 'S' => 'a T'
|
31
31
|
rule 'A' => 'a'
|
32
|
-
rule 'A' =>
|
32
|
+
rule 'A' => 'B A'
|
33
33
|
rule 'B' => []
|
34
|
-
rule 'T' =>
|
34
|
+
rule 'T' => 'b b b'
|
35
35
|
end
|
36
36
|
builder.grammar
|
37
37
|
end
|
@@ -48,11 +48,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
48
48
|
subject { ParseForestBuilder.new(sample_tokens) }
|
49
49
|
|
50
50
|
# Emit a text representation of the current path.
|
51
|
-
def path_to_s
|
51
|
+
def path_to_s
|
52
52
|
text_parts = subject.curr_path.map do |path_element|
|
53
53
|
path_element.to_string(0)
|
54
54
|
end
|
55
|
-
|
55
|
+
text_parts.join('/')
|
56
56
|
end
|
57
57
|
|
58
58
|
def next_event(eventType, anEntryText)
|
@@ -209,7 +209,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
209
209
|
path_prefix = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/'
|
210
210
|
|
211
211
|
next_event(:visit, 'A => a . | 0') # Event 21
|
212
|
-
expected_curr_path(path_prefix
|
212
|
+
expected_curr_path("#{path_prefix}Alt(A => a .)[0, 1]")
|
213
213
|
expect(subject.curr_path[-2].refinement).to eq(:or)
|
214
214
|
|
215
215
|
next_event(:visit, 'A => . a | 0') # Event 22
|
@@ -244,24 +244,24 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
244
244
|
path_prefix = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/'
|
245
245
|
|
246
246
|
next_event(:visit, 'A => B A . | 0') # Event 29
|
247
|
-
expected_curr_path(path_prefix
|
247
|
+
expected_curr_path("#{path_prefix}Alt(A => B A .)[0, 1]")
|
248
248
|
|
249
249
|
next_event(:revisit, 'A. | 0') # REVISIT Event 30
|
250
|
-
expected_curr_path(path_prefix
|
250
|
+
expected_curr_path("#{path_prefix}Alt(A => B A .)[0, 1]")
|
251
251
|
|
252
252
|
next_event(:visit, 'A => B . A | 0') # Event 31
|
253
|
-
expected_curr_path(path_prefix
|
253
|
+
expected_curr_path("#{path_prefix}Alt(A => B A .)[0, 1]")
|
254
254
|
|
255
255
|
next_event(:visit, 'B. | 0') # Event 32
|
256
|
-
expected_curr_path(path_prefix
|
256
|
+
expected_curr_path("#{path_prefix}Alt(A => B A .)[0, 1]/B[0, 0]")
|
257
257
|
|
258
258
|
# Entry with empty production!
|
259
259
|
next_event(:visit, 'B => . | 0') # Event 33
|
260
|
-
expected_curr_path(path_prefix
|
260
|
+
expected_curr_path("#{path_prefix}Alt(A => B A .)[0, 1]/B[0, 0]")
|
261
261
|
expected_first_child('_[0, 0]')
|
262
262
|
|
263
263
|
next_event(:visit, '.B | 0') # Event 34
|
264
|
-
expected_curr_path(path_prefix
|
264
|
+
expected_curr_path("#{path_prefix}Alt(A => B A .)[0, 1]")
|
265
265
|
|
266
266
|
next_event(:visit, 'A => . B A | 0') # Event 35
|
267
267
|
expected_curr_path('Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]')
|
@@ -360,46 +360,46 @@ module Rley # Open this namespace to avoid module qualifier prefixes
|
|
360
360
|
next_event(:revisit, '.Nominal | 3') # REVISIT Event 15
|
361
361
|
expected_curr_path('S[0, 5]/VP[1, 5]/NP[2, 5]')
|
362
362
|
|
363
|
-
next_event(:visit, 'NP => Determiner . Nominal | 2') # Event 16
|
363
|
+
next_event(:visit, 'NP => Determiner . Nominal | 2') # Event 16
|
364
364
|
expected_curr_path('S[0, 5]/VP[1, 5]/NP[2, 5]')
|
365
365
|
expected_first_child('Determiner[2, 3]')
|
366
366
|
|
367
|
-
next_event(:visit, 'NP => . Determiner Nominal | 2') # Event 17
|
367
|
+
next_event(:visit, 'NP => . Determiner Nominal | 2') # Event 17
|
368
368
|
expected_curr_path('S[0, 5]/VP[1, 5]/NP[2, 5]')
|
369
369
|
|
370
|
-
next_event(:visit, '.NP | 2') # Event 18
|
370
|
+
next_event(:visit, '.NP | 2') # Event 18
|
371
371
|
expected_curr_path('S[0, 5]/VP[1, 5]')
|
372
372
|
|
373
|
-
next_event(:visit, 'VP => Verb . NP | 1') # Event 19
|
373
|
+
next_event(:visit, 'VP => Verb . NP | 1') # Event 19
|
374
374
|
expected_curr_path('S[0, 5]/VP[1, 5]')
|
375
375
|
expected_first_child('Verb[1, 2]')
|
376
376
|
|
377
|
-
next_event(:visit, 'VP => . Verb NP | 1') # Event 20
|
377
|
+
next_event(:visit, 'VP => . Verb NP | 1') # Event 20
|
378
378
|
expected_curr_path('S[0, 5]/VP[1, 5]')
|
379
379
|
|
380
|
-
next_event(:visit, '.VP | 1') # Event 21
|
380
|
+
next_event(:visit, '.VP | 1') # Event 21
|
381
381
|
expected_curr_path('S[0, 5]')
|
382
382
|
|
383
|
-
next_event(:visit, 'S => NP . VP | 0') # Event22
|
383
|
+
next_event(:visit, 'S => NP . VP | 0') # Event22
|
384
384
|
expected_curr_path('S[0, 5]')
|
385
385
|
|
386
|
-
next_event(:visit, 'NP. | 0') # Event 23
|
386
|
+
next_event(:visit, 'NP. | 0') # Event 23
|
387
387
|
expected_curr_path('S[0, 5]/NP[0, 1]')
|
388
388
|
|
389
|
-
next_event(:visit, 'NP => Pronoun . | 0') # Event 24
|
389
|
+
next_event(:visit, 'NP => Pronoun . | 0') # Event 24
|
390
390
|
expected_curr_path('S[0, 5]/NP[0, 1]')
|
391
391
|
expected_first_child('Pronoun[0, 1]')
|
392
392
|
|
393
|
-
next_event(:visit, 'NP => . Pronoun | 0') # Event 25
|
393
|
+
next_event(:visit, 'NP => . Pronoun | 0') # Event 25
|
394
394
|
expected_curr_path('S[0, 5]/NP[0, 1]')
|
395
395
|
|
396
|
-
next_event(:visit, '.NP | 0') # Event 26
|
396
|
+
next_event(:visit, '.NP | 0') # Event 26
|
397
397
|
expected_curr_path('S[0, 5]')
|
398
398
|
|
399
|
-
next_event(:visit, 'S => . NP VP | 0') # Event 27
|
399
|
+
next_event(:visit, 'S => . NP VP | 0') # Event 27
|
400
400
|
expected_curr_path('S[0, 5]')
|
401
401
|
|
402
|
-
next_event(:visit, '.S | 0') # Event28
|
402
|
+
next_event(:visit, '.S | 0') # Event28
|
403
403
|
expected_curr_path('')
|
404
404
|
end
|
405
405
|
end # context
|