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.
Files changed (139) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +348 -54
  3. data/LICENSE.txt +1 -1
  4. data/README.md +3 -2
  5. data/examples/NLP/engtagger.rb +193 -190
  6. data/examples/NLP/nano_eng/nano_grammar.rb +5 -5
  7. data/examples/data_formats/JSON/cli_options.rb +1 -1
  8. data/examples/data_formats/JSON/json_ast_builder.rb +12 -9
  9. data/examples/data_formats/JSON/json_ast_nodes.rb +12 -21
  10. data/examples/data_formats/JSON/json_grammar.rb +2 -2
  11. data/examples/data_formats/JSON/json_lexer.rb +8 -8
  12. data/examples/data_formats/JSON/json_minifier.rb +1 -1
  13. data/examples/general/calc_iter1/calc_ast_builder.rb +13 -10
  14. data/examples/general/calc_iter1/calc_ast_nodes.rb +23 -37
  15. data/examples/general/calc_iter1/calc_grammar.rb +2 -2
  16. data/examples/general/calc_iter1/calc_lexer.rb +6 -4
  17. data/examples/general/calc_iter1/spec/calculator_spec.rb +5 -5
  18. data/examples/general/calc_iter2/calc_ast_builder.rb +5 -3
  19. data/examples/general/calc_iter2/calc_ast_nodes.rb +27 -43
  20. data/examples/general/calc_iter2/calc_grammar.rb +3 -3
  21. data/examples/general/calc_iter2/calc_lexer.rb +11 -10
  22. data/examples/general/calc_iter2/spec/calculator_spec.rb +26 -26
  23. data/examples/general/left.rb +2 -2
  24. data/examples/general/right.rb +2 -2
  25. data/lib/rley/base/dotted_item.rb +23 -31
  26. data/lib/rley/constants.rb +2 -2
  27. data/lib/rley/engine.rb +20 -23
  28. data/lib/rley/formatter/asciitree.rb +3 -3
  29. data/lib/rley/formatter/bracket_notation.rb +1 -8
  30. data/lib/rley/formatter/debug.rb +6 -6
  31. data/lib/rley/formatter/json.rb +2 -2
  32. data/lib/rley/gfg/call_edge.rb +1 -1
  33. data/lib/rley/gfg/edge.rb +5 -5
  34. data/lib/rley/gfg/end_vertex.rb +2 -6
  35. data/lib/rley/gfg/epsilon_edge.rb +1 -5
  36. data/lib/rley/gfg/grm_flow_graph.rb +27 -23
  37. data/lib/rley/gfg/item_vertex.rb +10 -10
  38. data/lib/rley/gfg/non_terminal_vertex.rb +4 -4
  39. data/lib/rley/gfg/scan_edge.rb +1 -1
  40. data/lib/rley/gfg/shortcut_edge.rb +2 -2
  41. data/lib/rley/gfg/start_vertex.rb +4 -8
  42. data/lib/rley/gfg/vertex.rb +43 -39
  43. data/lib/rley/lexical/token_range.rb +6 -6
  44. data/lib/rley/parse_forest_visitor.rb +5 -5
  45. data/lib/rley/parse_rep/ast_base_builder.rb +9 -11
  46. data/lib/rley/parse_rep/cst_builder.rb +5 -6
  47. data/lib/rley/parse_rep/parse_forest_builder.rb +20 -18
  48. data/lib/rley/parse_rep/parse_forest_factory.rb +3 -3
  49. data/lib/rley/parse_rep/parse_rep_creator.rb +11 -13
  50. data/lib/rley/parse_rep/parse_tree_builder.rb +4 -4
  51. data/lib/rley/parse_rep/parse_tree_factory.rb +27 -27
  52. data/lib/rley/parse_tree_visitor.rb +1 -1
  53. data/lib/rley/parser/error_reason.rb +4 -5
  54. data/lib/rley/parser/gfg_chart.rb +20 -22
  55. data/lib/rley/parser/gfg_parsing.rb +16 -30
  56. data/lib/rley/parser/parse_entry.rb +25 -31
  57. data/lib/rley/parser/parse_entry_set.rb +18 -15
  58. data/lib/rley/parser/parse_entry_tracker.rb +4 -4
  59. data/lib/rley/parser/parse_state.rb +16 -21
  60. data/lib/rley/parser/parse_state_tracker.rb +4 -4
  61. data/lib/rley/parser/parse_tracer.rb +13 -13
  62. data/lib/rley/parser/parse_walker_factory.rb +23 -28
  63. data/lib/rley/parser/state_set.rb +9 -10
  64. data/lib/rley/ptree/non_terminal_node.rb +7 -5
  65. data/lib/rley/ptree/parse_tree.rb +3 -3
  66. data/lib/rley/ptree/parse_tree_node.rb +5 -5
  67. data/lib/rley/ptree/terminal_node.rb +7 -7
  68. data/lib/rley/rley_error.rb +12 -12
  69. data/lib/rley/sppf/alternative_node.rb +6 -6
  70. data/lib/rley/sppf/composite_node.rb +7 -7
  71. data/lib/rley/sppf/epsilon_node.rb +3 -3
  72. data/lib/rley/sppf/leaf_node.rb +3 -3
  73. data/lib/rley/sppf/parse_forest.rb +16 -16
  74. data/lib/rley/sppf/sppf_node.rb +7 -8
  75. data/lib/rley/sppf/token_node.rb +3 -3
  76. data/lib/rley/syntax/grammar.rb +5 -5
  77. data/lib/rley/syntax/grammar_builder.rb +9 -9
  78. data/lib/rley/syntax/grm_symbol.rb +6 -6
  79. data/lib/rley/syntax/non_terminal.rb +9 -15
  80. data/lib/rley/syntax/production.rb +10 -10
  81. data/lib/rley/syntax/symbol_seq.rb +7 -9
  82. data/lib/rley/syntax/terminal.rb +4 -5
  83. data/lib/rley/syntax/verbatim_symbol.rb +3 -3
  84. data/lib/support/base_tokenizer.rb +19 -18
  85. data/spec/rley/base/dotted_item_spec.rb +2 -2
  86. data/spec/rley/engine_spec.rb +17 -15
  87. data/spec/rley/formatter/asciitree_spec.rb +7 -7
  88. data/spec/rley/formatter/bracket_notation_spec.rb +13 -13
  89. data/spec/rley/formatter/json_spec.rb +1 -1
  90. data/spec/rley/gfg/end_vertex_spec.rb +5 -5
  91. data/spec/rley/gfg/item_vertex_spec.rb +10 -10
  92. data/spec/rley/gfg/non_terminal_vertex_spec.rb +3 -3
  93. data/spec/rley/gfg/shortcut_edge_spec.rb +1 -1
  94. data/spec/rley/gfg/start_vertex_spec.rb +5 -5
  95. data/spec/rley/gfg/vertex_spec.rb +3 -3
  96. data/spec/rley/lexical/token_range_spec.rb +16 -16
  97. data/spec/rley/lexical/token_spec.rb +2 -2
  98. data/spec/rley/parse_forest_visitor_spec.rb +165 -163
  99. data/spec/rley/parse_rep/ambiguous_parse_spec.rb +44 -44
  100. data/spec/rley/parse_rep/ast_builder_spec.rb +6 -6
  101. data/spec/rley/parse_rep/cst_builder_spec.rb +5 -5
  102. data/spec/rley/parse_rep/groucho_spec.rb +21 -21
  103. data/spec/rley/parse_rep/parse_forest_builder_spec.rb +26 -26
  104. data/spec/rley/parse_rep/parse_forest_factory_spec.rb +6 -6
  105. data/spec/rley/parse_rep/parse_tree_factory_spec.rb +2 -2
  106. data/spec/rley/parse_tree_visitor_spec.rb +10 -8
  107. data/spec/rley/parser/error_reason_spec.rb +6 -6
  108. data/spec/rley/parser/gfg_earley_parser_spec.rb +4 -2
  109. data/spec/rley/parser/gfg_parsing_spec.rb +4 -8
  110. data/spec/rley/parser/parse_entry_spec.rb +19 -19
  111. data/spec/rley/parser/parse_state_spec.rb +5 -5
  112. data/spec/rley/parser/parse_walker_factory_spec.rb +1 -1
  113. data/spec/rley/parser/state_set_spec.rb +22 -22
  114. data/spec/rley/ptree/non_terminal_node_spec.rb +5 -3
  115. data/spec/rley/ptree/parse_tree_node_spec.rb +4 -4
  116. data/spec/rley/ptree/terminal_node_spec.rb +6 -6
  117. data/spec/rley/sppf/alternative_node_spec.rb +6 -6
  118. data/spec/rley/sppf/non_terminal_node_spec.rb +3 -3
  119. data/spec/rley/sppf/token_node_spec.rb +4 -4
  120. data/spec/rley/support/ambiguous_grammar_helper.rb +3 -4
  121. data/spec/rley/support/grammar_abc_helper.rb +2 -4
  122. data/spec/rley/support/grammar_ambig01_helper.rb +4 -5
  123. data/spec/rley/support/grammar_arr_int_helper.rb +4 -5
  124. data/spec/rley/support/grammar_b_expr_helper.rb +4 -5
  125. data/spec/rley/support/grammar_l0_helper.rb +10 -11
  126. data/spec/rley/support/grammar_pb_helper.rb +6 -5
  127. data/spec/rley/support/grammar_sppf_helper.rb +1 -1
  128. data/spec/rley/syntax/grammar_builder_spec.rb +5 -5
  129. data/spec/rley/syntax/grammar_spec.rb +6 -6
  130. data/spec/rley/syntax/grm_symbol_spec.rb +1 -1
  131. data/spec/rley/syntax/non_terminal_spec.rb +8 -8
  132. data/spec/rley/syntax/production_spec.rb +13 -13
  133. data/spec/rley/syntax/symbol_seq_spec.rb +2 -2
  134. data/spec/rley/syntax/terminal_spec.rb +5 -5
  135. data/spec/rley/syntax/verbatim_symbol_spec.rb +1 -1
  136. data/spec/spec_helper.rb +0 -12
  137. data/spec/support/base_tokenizer_spec.rb +7 -2
  138. metadata +21 -62
  139. 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
- return text_parts.join('/')
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 + '/S[4, 5]')
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 + '/S[4, 5]'
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 + '/S[4, 5]/L[4, 5]')
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 + '/S[4, 5]/L[4, 5]')
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 + '/S[4, 5]/L[4, 5]')
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 + '/S[4, 5]')
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 + '/S[4, 5]')
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 + '/S[0, 3]')
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 + '/S[0, 3]')
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 + '/S[0, 3]/S[2, 3]')
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 + '/S[0, 3]/S[2, 3]')
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 + '/S[0, 3]/S[2, 3]/L[2, 3]')
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 + '/S[0, 3]/S[2, 3]/L[2, 3]')
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 + '/S[0, 3]/S[2, 3]/L[2, 3]')
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 + '/S[0, 3]/S[2, 3]')
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 + '/S[0, 3]/S[2, 3]')
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 + '/S[0, 3]')
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 + '/S[0, 3]')
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 + '/S[0, 3]')
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 + '/S[0, 3]/S[0, 1]')
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 + '/S[0, 3]/S[0, 1]')
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 + '/S[0, 3]/S[0, 1]/L[0, 1]')
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 + '/S[0, 3]/S[0, 1]/L[0, 1]')
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 + '/S[0, 3]/S[0, 1]/L[0, 1]')
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 + '/S[0, 3]/S[0, 1]')
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 + '/S[0, 3]/S[0, 1]')
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 + '/S[0, 3]')
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 + '/S[0, 3]')
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 + '/S[2, 5]')
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 + '/S[2, 5]')
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 + '/S[2, 5]')
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 + '/S[2, 5]')
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 + '/S[2, 5]')
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 + '/S[2, 5]')
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 + '/S[2, 5]')
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' => %w[NP VP]
29
- rule 'NP' => %w[Det N]
30
- rule 'NP' => %w[Det N PP]
28
+ rule 'S' => 'NP VP'
29
+ rule 'NP' => 'Det N'
30
+ rule 'NP' => 'Det N PP'
31
31
  rule 'NP' => 'Pro'
32
- rule 'VP' => %w[V NP]
33
- rule 'VP' => %w[VP PP]
34
- rule 'PP' => %w[P NP]
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
- Groucho_lexicon = {
42
- 'elephant' => 'N',
43
- 'pajamas' => 'N',
44
- 'shot' => 'V',
45
- 'I' => 'Pro',
46
- 'an' => 'Det',
47
- 'my' => 'Det',
48
- 'in' => 'P'
49
- }.freeze
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
- tokens = aText.scan(/\S+/).map do |word|
55
- term = Groucho_lexicon[word]
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
- return text_parts.join('/')
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' => %w[A T]
30
- rule 'S' => %w[a T]
29
+ rule 'S' => 'A T'
30
+ rule 'S' => 'a T'
31
31
  rule 'A' => 'a'
32
- rule 'A' => %w[B A]
32
+ rule 'A' => 'B A'
33
33
  rule 'B' => []
34
- rule 'T' => %w[b b b]
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
- return text_parts.join('/')
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 + 'Alt(A => a .)[0, 1]')
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 + 'Alt(A => B A .)[0, 1]')
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 + 'Alt(A => B A .)[0, 1]')
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 + 'Alt(A => B A .)[0, 1]')
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 + 'Alt(A => B A .)[0, 1]/B[0, 0]')
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 + 'Alt(A => B A .)[0, 1]/B[0, 0]')
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 + 'Alt(A => B A .)[0, 1]')
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