rley 0.7.03 → 0.7.08

Sign up to get free protection for your applications and to get access to all the features.
Files changed (174) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +362 -62
  3. data/.travis.yml +6 -7
  4. data/CHANGELOG.md +20 -1
  5. data/LICENSE.txt +1 -1
  6. data/README.md +6 -7
  7. data/Rakefile +2 -0
  8. data/appveyor.yml +2 -4
  9. data/examples/NLP/benchmark_pico_en.rb +2 -0
  10. data/examples/NLP/engtagger.rb +193 -188
  11. data/examples/NLP/nano_eng/nano_en_demo.rb +2 -0
  12. data/examples/NLP/nano_eng/nano_grammar.rb +7 -5
  13. data/examples/NLP/pico_en_demo.rb +2 -0
  14. data/examples/data_formats/JSON/cli_options.rb +3 -1
  15. data/examples/data_formats/JSON/json_ast_builder.rb +14 -9
  16. data/examples/data_formats/JSON/json_ast_nodes.rb +14 -21
  17. data/examples/data_formats/JSON/json_demo.rb +2 -0
  18. data/examples/data_formats/JSON/json_grammar.rb +4 -2
  19. data/examples/data_formats/JSON/json_lexer.rb +10 -8
  20. data/examples/data_formats/JSON/json_minifier.rb +3 -1
  21. data/examples/general/calc_iter1/calc_ast_builder.rb +15 -10
  22. data/examples/general/calc_iter1/calc_ast_nodes.rb +25 -37
  23. data/examples/general/calc_iter1/calc_demo.rb +2 -0
  24. data/examples/general/calc_iter1/calc_grammar.rb +4 -2
  25. data/examples/general/calc_iter1/calc_lexer.rb +8 -4
  26. data/examples/general/calc_iter1/spec/calculator_spec.rb +7 -5
  27. data/examples/general/calc_iter2/calc_ast_builder.rb +7 -3
  28. data/examples/general/calc_iter2/calc_ast_nodes.rb +29 -43
  29. data/examples/general/calc_iter2/calc_demo.rb +2 -0
  30. data/examples/general/calc_iter2/calc_grammar.rb +5 -3
  31. data/examples/general/calc_iter2/calc_lexer.rb +13 -10
  32. data/examples/general/calc_iter2/spec/calculator_spec.rb +28 -26
  33. data/examples/general/left.rb +4 -2
  34. data/examples/general/right.rb +4 -2
  35. data/lib/rley.rb +2 -0
  36. data/lib/rley/base/base_parser.rb +2 -0
  37. data/lib/rley/base/dotted_item.rb +38 -41
  38. data/lib/rley/base/grm_items_builder.rb +2 -0
  39. data/lib/rley/constants.rb +5 -3
  40. data/lib/rley/engine.rb +22 -24
  41. data/lib/rley/formatter/asciitree.rb +6 -4
  42. data/lib/rley/formatter/base_formatter.rb +2 -0
  43. data/lib/rley/formatter/bracket_notation.rb +3 -8
  44. data/lib/rley/formatter/debug.rb +8 -6
  45. data/lib/rley/formatter/json.rb +4 -2
  46. data/lib/rley/gfg/call_edge.rb +3 -1
  47. data/lib/rley/gfg/edge.rb +7 -5
  48. data/lib/rley/gfg/end_vertex.rb +4 -6
  49. data/lib/rley/gfg/epsilon_edge.rb +3 -5
  50. data/lib/rley/gfg/grm_flow_graph.rb +31 -25
  51. data/lib/rley/gfg/item_vertex.rb +12 -22
  52. data/lib/rley/gfg/non_terminal_vertex.rb +6 -4
  53. data/lib/rley/gfg/return_edge.rb +2 -0
  54. data/lib/rley/gfg/scan_edge.rb +3 -1
  55. data/lib/rley/gfg/shortcut_edge.rb +4 -2
  56. data/lib/rley/gfg/start_vertex.rb +6 -8
  57. data/lib/rley/gfg/vertex.rb +47 -41
  58. data/lib/rley/lexical/token.rb +3 -1
  59. data/lib/rley/lexical/token_range.rb +8 -6
  60. data/lib/rley/parse_forest_visitor.rb +7 -5
  61. data/lib/rley/parse_rep/ast_base_builder.rb +11 -11
  62. data/lib/rley/parse_rep/cst_builder.rb +7 -4
  63. data/lib/rley/parse_rep/parse_forest_builder.rb +36 -25
  64. data/lib/rley/parse_rep/parse_forest_factory.rb +5 -3
  65. data/lib/rley/parse_rep/parse_rep_creator.rb +18 -13
  66. data/lib/rley/parse_rep/parse_tree_builder.rb +15 -15
  67. data/lib/rley/parse_rep/parse_tree_factory.rb +27 -25
  68. data/lib/rley/parse_tree_visitor.rb +3 -1
  69. data/lib/rley/parser/error_reason.rb +9 -8
  70. data/lib/rley/parser/gfg_chart.rb +54 -22
  71. data/lib/rley/parser/gfg_earley_parser.rb +3 -1
  72. data/lib/rley/parser/gfg_parsing.rb +51 -31
  73. data/lib/rley/parser/parse_entry.rb +29 -33
  74. data/lib/rley/parser/parse_entry_set.rb +32 -27
  75. data/lib/rley/parser/parse_entry_tracker.rb +6 -4
  76. data/lib/rley/parser/parse_state.rb +18 -21
  77. data/lib/rley/parser/parse_state_tracker.rb +6 -4
  78. data/lib/rley/parser/parse_tracer.rb +15 -13
  79. data/lib/rley/parser/parse_walker_factory.rb +28 -29
  80. data/lib/rley/parser/state_set.rb +11 -10
  81. data/lib/rley/ptree/non_terminal_node.rb +10 -6
  82. data/lib/rley/ptree/parse_tree.rb +6 -4
  83. data/lib/rley/ptree/parse_tree_node.rb +7 -5
  84. data/lib/rley/ptree/terminal_node.rb +9 -7
  85. data/lib/rley/rley_error.rb +12 -10
  86. data/lib/rley/sppf/alternative_node.rb +8 -6
  87. data/lib/rley/sppf/composite_node.rb +9 -7
  88. data/lib/rley/sppf/epsilon_node.rb +5 -3
  89. data/lib/rley/sppf/leaf_node.rb +5 -3
  90. data/lib/rley/sppf/non_terminal_node.rb +2 -0
  91. data/lib/rley/sppf/parse_forest.rb +19 -17
  92. data/lib/rley/sppf/sppf_node.rb +9 -8
  93. data/lib/rley/sppf/token_node.rb +5 -3
  94. data/lib/rley/syntax/grammar.rb +7 -5
  95. data/lib/rley/syntax/grammar_builder.rb +11 -9
  96. data/lib/rley/syntax/grm_symbol.rb +8 -6
  97. data/lib/rley/syntax/literal.rb +2 -0
  98. data/lib/rley/syntax/non_terminal.rb +11 -15
  99. data/lib/rley/syntax/production.rb +13 -11
  100. data/lib/rley/syntax/symbol_seq.rb +10 -10
  101. data/lib/rley/syntax/terminal.rb +6 -5
  102. data/lib/rley/syntax/verbatim_symbol.rb +5 -3
  103. data/lib/support/base_tokenizer.rb +23 -20
  104. data/spec/rley/base/dotted_item_spec.rb +4 -2
  105. data/spec/rley/base/grm_items_builder_spec.rb +2 -0
  106. data/spec/rley/engine_spec.rb +47 -9
  107. data/spec/rley/formatter/asciitree_spec.rb +11 -9
  108. data/spec/rley/formatter/bracket_notation_spec.rb +16 -14
  109. data/spec/rley/formatter/debug_spec.rb +4 -2
  110. data/spec/rley/formatter/json_spec.rb +5 -3
  111. data/spec/rley/gfg/call_edge_spec.rb +2 -0
  112. data/spec/rley/gfg/edge_spec.rb +2 -0
  113. data/spec/rley/gfg/end_vertex_spec.rb +7 -5
  114. data/spec/rley/gfg/epsilon_edge_spec.rb +2 -0
  115. data/spec/rley/gfg/grm_flow_graph_spec.rb +2 -0
  116. data/spec/rley/gfg/item_vertex_spec.rb +12 -10
  117. data/spec/rley/gfg/non_terminal_vertex_spec.rb +5 -3
  118. data/spec/rley/gfg/return_edge_spec.rb +2 -0
  119. data/spec/rley/gfg/scan_edge_spec.rb +2 -0
  120. data/spec/rley/gfg/shortcut_edge_spec.rb +3 -1
  121. data/spec/rley/gfg/start_vertex_spec.rb +7 -5
  122. data/spec/rley/gfg/vertex_spec.rb +5 -3
  123. data/spec/rley/lexical/token_range_spec.rb +18 -16
  124. data/spec/rley/lexical/token_spec.rb +4 -2
  125. data/spec/rley/parse_forest_visitor_spec.rb +167 -163
  126. data/spec/rley/parse_rep/ambiguous_parse_spec.rb +46 -44
  127. data/spec/rley/parse_rep/ast_builder_spec.rb +8 -6
  128. data/spec/rley/parse_rep/cst_builder_spec.rb +7 -5
  129. data/spec/rley/parse_rep/groucho_spec.rb +25 -25
  130. data/spec/rley/parse_rep/parse_forest_builder_spec.rb +28 -26
  131. data/spec/rley/parse_rep/parse_forest_factory_spec.rb +8 -6
  132. data/spec/rley/parse_rep/parse_tree_factory_spec.rb +4 -2
  133. data/spec/rley/parse_tree_visitor_spec.rb +12 -8
  134. data/spec/rley/parser/error_reason_spec.rb +8 -6
  135. data/spec/rley/parser/gfg_chart_spec.rb +17 -4
  136. data/spec/rley/parser/gfg_earley_parser_spec.rb +16 -11
  137. data/spec/rley/parser/gfg_parsing_spec.rb +41 -252
  138. data/spec/rley/parser/parse_entry_set_spec.rb +2 -0
  139. data/spec/rley/parser/parse_entry_spec.rb +21 -19
  140. data/spec/rley/parser/parse_state_spec.rb +7 -5
  141. data/spec/rley/parser/parse_tracer_spec.rb +16 -14
  142. data/spec/rley/parser/parse_walker_factory_spec.rb +10 -8
  143. data/spec/rley/parser/state_set_spec.rb +24 -22
  144. data/spec/rley/ptree/non_terminal_node_spec.rb +7 -3
  145. data/spec/rley/ptree/parse_tree_node_spec.rb +6 -4
  146. data/spec/rley/ptree/parse_tree_spec.rb +2 -0
  147. data/spec/rley/ptree/terminal_node_spec.rb +8 -6
  148. data/spec/rley/sppf/alternative_node_spec.rb +8 -6
  149. data/spec/rley/sppf/non_terminal_node_spec.rb +5 -3
  150. data/spec/rley/sppf/token_node_spec.rb +6 -4
  151. data/spec/rley/support/ambiguous_grammar_helper.rb +5 -4
  152. data/spec/rley/support/expectation_helper.rb +2 -0
  153. data/spec/rley/support/grammar_abc_helper.rb +4 -4
  154. data/spec/rley/support/grammar_ambig01_helper.rb +6 -5
  155. data/spec/rley/support/grammar_arr_int_helper.rb +6 -5
  156. data/spec/rley/support/grammar_b_expr_helper.rb +6 -5
  157. data/spec/rley/support/grammar_helper.rb +2 -0
  158. data/spec/rley/support/grammar_l0_helper.rb +15 -16
  159. data/spec/rley/support/grammar_pb_helper.rb +8 -5
  160. data/spec/rley/support/grammar_sppf_helper.rb +3 -1
  161. data/spec/rley/syntax/grammar_builder_spec.rb +7 -5
  162. data/spec/rley/syntax/grammar_spec.rb +8 -6
  163. data/spec/rley/syntax/grm_symbol_spec.rb +3 -1
  164. data/spec/rley/syntax/literal_spec.rb +2 -0
  165. data/spec/rley/syntax/non_terminal_spec.rb +10 -8
  166. data/spec/rley/syntax/production_spec.rb +15 -13
  167. data/spec/rley/syntax/symbol_seq_spec.rb +4 -2
  168. data/spec/rley/syntax/terminal_spec.rb +7 -5
  169. data/spec/rley/syntax/verbatim_symbol_spec.rb +3 -1
  170. data/spec/spec_helper.rb +2 -12
  171. data/spec/support/base_tokenizer_spec.rb +9 -2
  172. metadata +21 -63
  173. data/.simplecov +0 -7
  174. data/Gemfile +0 -8
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  require_relative '../../../lib/rley/parser/gfg_earley_parser'
@@ -17,11 +19,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
17
19
  include ExpectationHelper # Mix-in with expectation on parse entry sets
18
20
 
19
21
  # Emit a text representation of the current path.
20
- def path_to_s()
22
+ def path_to_s
21
23
  text_parts = subject.curr_path.map do |path_element|
22
24
  path_element.to_string(0)
23
25
  end
24
- return text_parts.join('/')
26
+ text_parts.join('/')
25
27
  end
26
28
 
27
29
  def next_event(eventType, anEntryText)
@@ -86,28 +88,28 @@ module Rley # Open this namespace to avoid module qualifier prefixes
86
88
 
87
89
  next_event(:visit, 'S. | 4') # Event 5
88
90
  path_prefix = 'P[0, 5]/S[0, 5]/Alt(S => S * S .)[0, 5]'
89
- expected_curr_path(path_prefix + '/S[4, 5]')
91
+ expected_curr_path("#{path_prefix}/S[4, 5]")
90
92
 
91
93
  next_event(:visit, 'S => L . | 4') # Event 6
92
- expected_path5 = path_prefix + '/S[4, 5]'
94
+ expected_path5 = "#{path_prefix}/S[4, 5]"
93
95
  expect(path_to_s).to eq(expected_path5)
94
96
 
95
97
  next_event(:visit, 'L. | 4') # Event 7
96
- expected_curr_path(path_prefix + '/S[4, 5]/L[4, 5]')
98
+ expected_curr_path("#{path_prefix}/S[4, 5]/L[4, 5]")
97
99
 
98
100
  next_event(:visit, 'L => integer . | 4') # Event 8
99
- expected_curr_path(path_prefix + '/S[4, 5]/L[4, 5]')
101
+ expected_curr_path("#{path_prefix}/S[4, 5]/L[4, 5]")
100
102
  expected_first_child('integer[4, 5]')
101
103
 
102
104
  next_event(:visit, 'L => . integer | 4') # Event 9
103
- expected_curr_path(path_prefix + '/S[4, 5]/L[4, 5]')
105
+ expected_curr_path("#{path_prefix}/S[4, 5]/L[4, 5]")
104
106
 
105
107
  next_event(:visit, '.L | 4') # Event 10
106
- expected_curr_path(path_prefix + '/S[4, 5]')
108
+ expected_curr_path("#{path_prefix}/S[4, 5]")
107
109
 
108
110
  next_event(:visit, 'S => . L | 4') # Event 11
109
111
  expected_curr_parent('S[4, 5]')
110
- expected_curr_path(path_prefix + '/S[4, 5]')
112
+ expected_curr_path("#{path_prefix}/S[4, 5]")
111
113
 
112
114
  next_event(:visit, '.S | 4') # Event 12
113
115
  expected_curr_parent('Alt(S => S * S .)[0, 5]')
@@ -121,73 +123,73 @@ module Rley # Open this namespace to avoid module qualifier prefixes
121
123
  expected_curr_path(path_prefix)
122
124
 
123
125
  next_event(:visit, 'S. | 0') # Event 15
124
- expected_curr_path(path_prefix + '/S[0, 3]')
126
+ expected_curr_path("#{path_prefix}/S[0, 3]")
125
127
 
126
128
  next_event(:visit, 'S => S + S . | 0') # Event 16
127
129
  expected_curr_parent('S[0, 3]')
128
- expected_curr_path(path_prefix + '/S[0, 3]')
130
+ expected_curr_path("#{path_prefix}/S[0, 3]")
129
131
 
130
132
  next_event(:visit, 'S. | 2') # Event 17
131
- expected_curr_path(path_prefix + '/S[0, 3]/S[2, 3]')
133
+ expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]")
132
134
 
133
135
  next_event(:visit, 'S => L . | 2') # Event 18
134
- expected_curr_path(path_prefix + '/S[0, 3]/S[2, 3]')
136
+ expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]")
135
137
 
136
138
  next_event(:visit, 'L. | 2') # Event 19
137
- 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]")
138
140
 
139
141
  next_event(:visit, 'L => integer . | 2') # Event 20
140
- 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]")
141
143
  expected_first_child('integer[2, 3]')
142
144
 
143
145
  next_event(:visit, 'L => . integer | 2') # Event 21
144
- 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]")
145
147
 
146
148
  next_event(:visit, '.L | 2') # Event 22
147
149
  expected_curr_parent('S[2, 3]')
148
- expected_curr_path(path_prefix + '/S[0, 3]/S[2, 3]')
150
+ expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]")
149
151
 
150
152
  next_event(:visit, 'S => . L | 2') # Event 23
151
- expected_curr_path(path_prefix + '/S[0, 3]/S[2, 3]')
153
+ expected_curr_path("#{path_prefix}/S[0, 3]/S[2, 3]")
152
154
 
153
155
  next_event(:visit, '.S | 2') # Event 24
154
- expected_curr_path(path_prefix + '/S[0, 3]')
156
+ expected_curr_path("#{path_prefix}/S[0, 3]")
155
157
 
156
158
  next_event(:visit, 'S => S + . S | 0') # Event 24
157
- expected_curr_path(path_prefix + '/S[0, 3]')
159
+ expected_curr_path("#{path_prefix}/S[0, 3]")
158
160
  expected_first_child('+[1, 2]')
159
161
 
160
162
  next_event(:visit, 'S => S . + S | 0') # Event 25
161
- expected_curr_path(path_prefix + '/S[0, 3]')
163
+ expected_curr_path("#{path_prefix}/S[0, 3]")
162
164
 
163
165
  next_event(:visit, 'S. | 0') # Event 27
164
166
  expected_curr_parent('S[0, 1]')
165
- expected_curr_path(path_prefix + '/S[0, 3]/S[0, 1]')
167
+ expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]")
166
168
 
167
169
  next_event(:visit, 'S => L . | 0') # Event 28
168
- expected_curr_path(path_prefix + '/S[0, 3]/S[0, 1]')
170
+ expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]")
169
171
 
170
172
  next_event(:visit, 'L. | 0') # Event 29
171
- 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]")
172
174
 
173
175
  next_event(:visit, 'L => integer . | 0') # Event 30
174
- 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]")
175
177
  expected_first_child('integer[0, 1]')
176
178
 
177
179
  next_event(:visit, 'L => . integer | 0') # Event 31
178
- 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]")
179
181
 
180
182
  next_event(:visit, '.L | 0') # Event 32
181
- expected_curr_path(path_prefix + '/S[0, 3]/S[0, 1]')
183
+ expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]")
182
184
 
183
185
  next_event(:visit, 'S => . L | 0') # Event 33
184
- expected_curr_path(path_prefix + '/S[0, 3]/S[0, 1]')
186
+ expected_curr_path("#{path_prefix}/S[0, 3]/S[0, 1]")
185
187
 
186
188
  next_event(:visit, '.S | 0') # Event 34
187
- expected_curr_path(path_prefix + '/S[0, 3]')
189
+ expected_curr_path("#{path_prefix}/S[0, 3]")
188
190
 
189
191
  next_event(:visit, 'S => . S + S | 0') # Event 35
190
- expected_curr_path(path_prefix + '/S[0, 3]')
192
+ expected_curr_path("#{path_prefix}/S[0, 3]")
191
193
 
192
194
  next_event(:revisit, '.S | 0') # REVISIT Event 36
193
195
  expected_curr_parent('Alt(S => S * S .)[0, 5]')
@@ -208,42 +210,42 @@ module Rley # Open this namespace to avoid module qualifier prefixes
208
210
  next_event(:backtrack, 'S. | 0') # BACKTRACK Event 41
209
211
 
210
212
  expected_curr_path('P[0, 5]/S[0, 5]')
211
-
213
+
212
214
  next_event(:visit, 'S => S + S . | 0') # Event 42
213
215
  expected_curr_parent('Alt(S => S + S .)[0, 5]')
214
216
  path_prefix = 'P[0, 5]/S[0, 5]/Alt(S => S + S .)[0, 5]'
215
217
  expected_curr_path(path_prefix)
216
218
 
217
219
  next_event(:visit, 'S. | 2') # Event 43
218
- expected_curr_path(path_prefix + '/S[2, 5]')
220
+ expected_curr_path("#{path_prefix}/S[2, 5]")
219
221
 
220
222
  next_event(:visit, 'S => S * S . | 2') # Event 44
221
- expected_curr_path(path_prefix + '/S[2, 5]')
222
-
223
+ expected_curr_path("#{path_prefix}/S[2, 5]")
224
+
223
225
  # Up to now everything was running OK.
224
- # Next steps are going wrong...
226
+ # Next steps are going wrong...
225
227
 
226
228
  next_event(:revisit, 'S. | 4') # Event 45
227
- expected_curr_path(path_prefix + '/S[2, 5]')
229
+ expected_curr_path("#{path_prefix}/S[2, 5]")
228
230
  expected_first_child('S[4, 5]')
229
-
231
+
230
232
  next_event(:visit, 'S => S * . S | 2') # Event 46
231
- expected_curr_path(path_prefix + '/S[2, 5]')
233
+ expected_curr_path("#{path_prefix}/S[2, 5]")
232
234
  expected_first_child('*[3, 4]')
233
235
 
234
236
  next_event(:visit, 'S => S . * S | 2') # Event 47
235
- expected_curr_path(path_prefix + '/S[2, 5]')
236
-
237
+ expected_curr_path("#{path_prefix}/S[2, 5]")
238
+
237
239
  next_event(:revisit, 'S. | 2') # Event 48
238
- expected_curr_path(path_prefix + '/S[2, 5]')
240
+ expected_curr_path("#{path_prefix}/S[2, 5]")
239
241
 
240
242
  next_event(:visit, 'S => . S * S | 2') # Event 49
241
- expected_curr_path(path_prefix + '/S[2, 5]')
243
+ expected_curr_path("#{path_prefix}/S[2, 5]")
242
244
 
243
245
  next_event(:revisit, '.S | 2') # Event 50
244
246
  expected_curr_parent('Alt(S => S + S .)[0, 5]')
245
247
  expected_curr_path(path_prefix)
246
-
248
+
247
249
  # TODO: review previous and next steps...
248
250
 
249
251
  next_event(:revisit, 'S => S + . S | 0') # Event 51
@@ -267,7 +269,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
267
269
  expected_curr_path('P[0, 5]')
268
270
 
269
271
  next_event(:revisit, '.P | 0') # Event 57
270
- expected_curr_path('')
272
+ expected_curr_path('')
271
273
  end
272
274
  end # context
273
275
  end # describe
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  require_relative '../../../lib/rley/parser/gfg_earley_parser'
@@ -10,16 +12,15 @@ require_relative '../support/expectation_helper'
10
12
  require_relative '../support/grammar_b_expr_helper'
11
13
  require_relative '../support/grammar_arr_int_helper'
12
14
 
13
-
14
15
  module Rley # This module is used as a namespace
15
16
  module ParseRep # This module is used as a namespace
16
17
  ArrayNode = Struct.new(:children) do
17
- def initialize()
18
+ def initialize
18
19
  super
19
20
  self.children = []
20
21
  end
21
22
 
22
- def interpret()
23
+ def interpret
23
24
  return children.map(&:interpret)
24
25
  end
25
26
  end
@@ -31,17 +32,18 @@ module Rley # This module is used as a namespace
31
32
  self.position = aPosition
32
33
  end
33
34
 
34
- def interpret()
35
+ def interpret
35
36
  value
36
37
  end
37
38
  end
38
39
 
40
+ # rubocop: disable Naming/VariableNumber
39
41
  class ASTBuilder < ASTBaseBuilder
40
42
  Terminal2NodeClass = {
41
43
  'integer' => IntegerNode
42
44
  }.freeze
43
45
 
44
- def terminal2node()
46
+ def terminal2node
45
47
  Terminal2NodeClass
46
48
  end
47
49
 
@@ -78,10 +80,10 @@ module Rley # This module is used as a namespace
78
80
  return node
79
81
  end
80
82
  end # class
83
+ # rubocop: enable Naming/VariableNumber
81
84
  end # module
82
85
  end # module
83
86
 
84
-
85
87
  module Rley # Open this namespace to avoid module qualifier prefixes
86
88
  module ParseRep
87
89
  describe ASTBuilder do
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  require_relative '../../../lib/rley/parser/gfg_earley_parser'
@@ -69,8 +71,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
69
71
  end
70
72
  end # context
71
73
 
72
-
73
-
74
+
75
+
74
76
  context 'Parse tree construction (no null symbol):' do
75
77
  before(:each) do
76
78
  parser = Parser::GFGEarleyParser.new(sample_grammar)
@@ -117,7 +119,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
117
119
  # Event: revisit .S | 0 0
118
120
  # Event: visit P => . S | 0 0
119
121
  # Event: visit .P | 0 0
120
-
122
+
121
123
  it 'should react to a first end event' do
122
124
  event = @walker.next
123
125
  expect { subject.receive_event(*event) }.not_to raise_error
@@ -426,10 +428,10 @@ module Rley # Open this namespace to avoid module qualifier prefixes
426
428
  next_event('visit P => . arr | 0 0')
427
429
  expect(stack).to be_empty
428
430
  expect(@instance.result).not_to be_nil
429
-
431
+
430
432
  next_event('visit .P | 0 0')
431
433
  expect(stack).to be_empty
432
- expect(@instance.result).not_to be_nil
434
+ expect(@instance.result).not_to be_nil
433
435
  end
434
436
  end # context
435
437
  end # describe
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Purpose: to test the parse forest generation for an emblematic
2
4
  # ambiguous sentence
3
5
  # Based on example found at: http://www.nltk.org/book_1ed/ch08.html
@@ -23,43 +25,41 @@ module Rley # Open this namespace to avoid module qualifier prefixes
23
25
  builder = Rley::Syntax::GrammarBuilder.new do
24
26
  add_terminals('N', 'V', 'Pro') # N(oun), V(erb), Pro(noun)
25
27
  add_terminals('Det', 'P') # Det(erminer), P(reposition)
26
- rule 'S' => %w[NP VP]
27
- rule 'NP' => %w[Det N]
28
- rule 'NP' => %w[Det N PP]
28
+ rule 'S' => 'NP VP'
29
+ rule 'NP' => 'Det N'
30
+ rule 'NP' => 'Det N PP'
29
31
  rule 'NP' => 'Pro'
30
- rule 'VP' => %w[V NP]
31
- rule 'VP' => %w[VP PP]
32
- rule 'PP' => %w[P NP]
32
+ rule 'VP' => 'V NP'
33
+ rule 'VP' => 'VP PP'
34
+ rule 'PP' => 'P NP'
33
35
  end
34
36
  builder.grammar
35
37
  end
36
38
 
37
39
  # The lexicon is just a Hash with pairs of the form:
38
40
  # word => terminal symbol name
39
- Groucho_lexicon = {
40
- 'elephant' => 'N',
41
- 'pajamas' => 'N',
42
- 'shot' => 'V',
43
- 'I' => 'Pro',
44
- 'an' => 'Det',
45
- 'my' => 'Det',
46
- 'in' => 'P'
47
- }.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
48
52
 
49
53
  # Highly simplified tokenizer implementation.
50
54
  def tokenizer(aText, aGrammar)
51
55
  pos = Rley::Lexical::Position.new(1, 2) # Dummy position
52
- tokens = aText.scan(/\S+/).map do |word|
53
- term_name = Groucho_lexicon[word]
54
- if term_name.nil?
55
- raise StandardError, "Word '#{word}' not found in lexicon"
56
- end
56
+ aText.scan(/\S+/).map do |word|
57
+ term = groucho_lexicon[word]
58
+ raise StandardError, "Word '#{word}' not found in lexicon" if term.nil?
57
59
 
58
- terminal = aGrammar.name2symbol[term_name]
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)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative '../../spec_helper'
2
4
 
3
5
  require_relative '../../../lib/rley/parser/gfg_earley_parser'
@@ -24,12 +26,12 @@ module Rley # Open this namespace to avoid module qualifier prefixes
24
26
  builder = Syntax::GrammarBuilder.new do
25
27
  add_terminals('a', 'b')
26
28
  rule 'Phi' => 'S'
27
- rule 'S' => %w[A T]
28
- rule 'S' => %w[a T]
29
+ rule 'S' => 'A T'
30
+ rule 'S' => 'a T'
29
31
  rule 'A' => 'a'
30
- rule 'A' => %w[B A]
32
+ rule 'A' => 'B A'
31
33
  rule 'B' => []
32
- rule 'T' => %w[b b b]
34
+ rule 'T' => 'b b b'
33
35
  end
34
36
  builder.grammar
35
37
  end
@@ -46,11 +48,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
46
48
  subject { ParseForestBuilder.new(sample_tokens) }
47
49
 
48
50
  # Emit a text representation of the current path.
49
- def path_to_s()
51
+ def path_to_s
50
52
  text_parts = subject.curr_path.map do |path_element|
51
53
  path_element.to_string(0)
52
54
  end
53
- return text_parts.join('/')
55
+ text_parts.join('/')
54
56
  end
55
57
 
56
58
  def next_event(eventType, anEntryText)
@@ -207,7 +209,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
207
209
  path_prefix = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/'
208
210
 
209
211
  next_event(:visit, 'A => a . | 0') # Event 21
210
- expected_curr_path(path_prefix + 'Alt(A => a .)[0, 1]')
212
+ expected_curr_path("#{path_prefix}Alt(A => a .)[0, 1]")
211
213
  expect(subject.curr_path[-2].refinement).to eq(:or)
212
214
 
213
215
  next_event(:visit, 'A => . a | 0') # Event 22
@@ -242,24 +244,24 @@ module Rley # Open this namespace to avoid module qualifier prefixes
242
244
  path_prefix = 'Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]/'
243
245
 
244
246
  next_event(:visit, 'A => B A . | 0') # Event 29
245
- expected_curr_path(path_prefix + 'Alt(A => B A .)[0, 1]')
247
+ expected_curr_path("#{path_prefix}Alt(A => B A .)[0, 1]")
246
248
 
247
249
  next_event(:revisit, 'A. | 0') # REVISIT Event 30
248
- expected_curr_path(path_prefix + 'Alt(A => B A .)[0, 1]')
250
+ expected_curr_path("#{path_prefix}Alt(A => B A .)[0, 1]")
249
251
 
250
252
  next_event(:visit, 'A => B . A | 0') # Event 31
251
- expected_curr_path(path_prefix + 'Alt(A => B A .)[0, 1]')
253
+ expected_curr_path("#{path_prefix}Alt(A => B A .)[0, 1]")
252
254
 
253
255
  next_event(:visit, 'B. | 0') # Event 32
254
- 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]")
255
257
 
256
258
  # Entry with empty production!
257
259
  next_event(:visit, 'B => . | 0') # Event 33
258
- 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]")
259
261
  expected_first_child('_[0, 0]')
260
262
 
261
263
  next_event(:visit, '.B | 0') # Event 34
262
- expected_curr_path(path_prefix + 'Alt(A => B A .)[0, 1]')
264
+ expected_curr_path("#{path_prefix}Alt(A => B A .)[0, 1]")
263
265
 
264
266
  next_event(:visit, 'A => . B A | 0') # Event 35
265
267
  expected_curr_path('Phi[0, 4]/S[0, 4]/Alt(S => A T .)[0, 4]/A[0, 1]')
@@ -358,46 +360,46 @@ module Rley # Open this namespace to avoid module qualifier prefixes
358
360
  next_event(:revisit, '.Nominal | 3') # REVISIT Event 15
359
361
  expected_curr_path('S[0, 5]/VP[1, 5]/NP[2, 5]')
360
362
 
361
- next_event(:visit, 'NP => Determiner . Nominal | 2') # Event 16
363
+ next_event(:visit, 'NP => Determiner . Nominal | 2') # Event 16
362
364
  expected_curr_path('S[0, 5]/VP[1, 5]/NP[2, 5]')
363
365
  expected_first_child('Determiner[2, 3]')
364
366
 
365
- next_event(:visit, 'NP => . Determiner Nominal | 2') # Event 17
367
+ next_event(:visit, 'NP => . Determiner Nominal | 2') # Event 17
366
368
  expected_curr_path('S[0, 5]/VP[1, 5]/NP[2, 5]')
367
369
 
368
- next_event(:visit, '.NP | 2') # Event 18
370
+ next_event(:visit, '.NP | 2') # Event 18
369
371
  expected_curr_path('S[0, 5]/VP[1, 5]')
370
372
 
371
- next_event(:visit, 'VP => Verb . NP | 1') # Event 19
373
+ next_event(:visit, 'VP => Verb . NP | 1') # Event 19
372
374
  expected_curr_path('S[0, 5]/VP[1, 5]')
373
375
  expected_first_child('Verb[1, 2]')
374
376
 
375
- next_event(:visit, 'VP => . Verb NP | 1') # Event 20
377
+ next_event(:visit, 'VP => . Verb NP | 1') # Event 20
376
378
  expected_curr_path('S[0, 5]/VP[1, 5]')
377
379
 
378
- next_event(:visit, '.VP | 1') # Event 21
380
+ next_event(:visit, '.VP | 1') # Event 21
379
381
  expected_curr_path('S[0, 5]')
380
382
 
381
- next_event(:visit, 'S => NP . VP | 0') # Event22
383
+ next_event(:visit, 'S => NP . VP | 0') # Event22
382
384
  expected_curr_path('S[0, 5]')
383
385
 
384
- next_event(:visit, 'NP. | 0') # Event 23
386
+ next_event(:visit, 'NP. | 0') # Event 23
385
387
  expected_curr_path('S[0, 5]/NP[0, 1]')
386
388
 
387
- next_event(:visit, 'NP => Pronoun . | 0') # Event 24
389
+ next_event(:visit, 'NP => Pronoun . | 0') # Event 24
388
390
  expected_curr_path('S[0, 5]/NP[0, 1]')
389
391
  expected_first_child('Pronoun[0, 1]')
390
392
 
391
- next_event(:visit, 'NP => . Pronoun | 0') # Event 25
393
+ next_event(:visit, 'NP => . Pronoun | 0') # Event 25
392
394
  expected_curr_path('S[0, 5]/NP[0, 1]')
393
395
 
394
- next_event(:visit, '.NP | 0') # Event 26
396
+ next_event(:visit, '.NP | 0') # Event 26
395
397
  expected_curr_path('S[0, 5]')
396
398
 
397
- next_event(:visit, 'S => . NP VP | 0') # Event 27
399
+ next_event(:visit, 'S => . NP VP | 0') # Event 27
398
400
  expected_curr_path('S[0, 5]')
399
401
 
400
- next_event(:visit, '.S | 0') # Event28
402
+ next_event(:visit, '.S | 0') # Event28
401
403
  expected_curr_path('')
402
404
  end
403
405
  end # context