rley 0.6.00 → 0.6.01

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 (82) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -1
  3. data/CHANGELOG.md +3 -0
  4. data/Gemfile +1 -1
  5. data/examples/NLP/benchmark_pico_en.rb +6 -10
  6. data/examples/NLP/nano_eng/nano_en_demo.rb +2 -2
  7. data/examples/NLP/nano_eng/nano_grammar.rb +1 -2
  8. data/examples/data_formats/JSON/json_ast_builder.rb +8 -8
  9. data/examples/general/SRL/lib/ast_builder.rb +74 -72
  10. data/examples/general/SRL/lib/grammar.rb +2 -2
  11. data/examples/general/SRL/lib/regex/abstract_method.rb +28 -28
  12. data/examples/general/SRL/lib/regex/alternation.rb +21 -25
  13. data/examples/general/SRL/lib/regex/anchor.rb +6 -9
  14. data/examples/general/SRL/lib/regex/atomic_expression.rb +10 -15
  15. data/examples/general/SRL/lib/regex/capturing_group.rb +15 -14
  16. data/examples/general/SRL/lib/regex/char_class.rb +10 -13
  17. data/examples/general/SRL/lib/regex/char_range.rb +45 -46
  18. data/examples/general/SRL/lib/regex/char_shorthand.rb +8 -9
  19. data/examples/general/SRL/lib/regex/character.rb +196 -191
  20. data/examples/general/SRL/lib/regex/compound_expression.rb +47 -50
  21. data/examples/general/SRL/lib/regex/concatenation.rb +23 -27
  22. data/examples/general/SRL/lib/regex/expression.rb +53 -56
  23. data/examples/general/SRL/lib/regex/lookaround.rb +23 -20
  24. data/examples/general/SRL/lib/regex/match_option.rb +26 -28
  25. data/examples/general/SRL/lib/regex/monadic_expression.rb +20 -23
  26. data/examples/general/SRL/lib/regex/multiplicity.rb +17 -20
  27. data/examples/general/SRL/lib/regex/non_capturing_group.rb +9 -12
  28. data/examples/general/SRL/lib/regex/polyadic_expression.rb +51 -55
  29. data/examples/general/SRL/lib/regex/quantifiable.rb +14 -20
  30. data/examples/general/SRL/lib/regex/repetition.rb +20 -23
  31. data/examples/general/SRL/lib/regex/wildcard.rb +15 -19
  32. data/examples/general/SRL/lib/regex_repr.rb +1 -1
  33. data/examples/general/SRL/lib/tokenizer.rb +2 -2
  34. data/examples/general/SRL/spec/integration_spec.rb +17 -12
  35. data/examples/general/SRL/spec/regex/character_spec.rb +160 -153
  36. data/examples/general/SRL/spec/regex/multiplicity_spec.rb +27 -31
  37. data/examples/general/SRL/spec/spec_helper.rb +1 -1
  38. data/examples/general/SRL/spec/tokenizer_spec.rb +25 -27
  39. data/examples/general/calc_iter1/calc_ast_builder.rb +10 -10
  40. data/examples/general/calc_iter2/calc_ast_builder.rb +7 -9
  41. data/examples/general/calc_iter2/calc_ast_nodes.rb +5 -6
  42. data/examples/general/calc_iter2/calc_lexer.rb +3 -5
  43. data/examples/general/calc_iter2/spec/calculator_spec.rb +16 -14
  44. data/examples/general/left.rb +8 -8
  45. data/examples/general/right.rb +8 -8
  46. data/lib/rley/constants.rb +1 -1
  47. data/lib/rley/engine.rb +16 -20
  48. data/lib/rley/formatter/json.rb +1 -1
  49. data/lib/rley/gfg/grm_flow_graph.rb +1 -1
  50. data/lib/rley/gfg/item_vertex.rb +6 -5
  51. data/lib/rley/gfg/vertex.rb +3 -3
  52. data/lib/rley/lexical/token.rb +4 -3
  53. data/lib/rley/parse_rep/ast_base_builder.rb +4 -3
  54. data/lib/rley/parse_rep/parse_rep_creator.rb +1 -1
  55. data/lib/rley/parse_rep/parse_tree_builder.rb +3 -2
  56. data/lib/rley/parser/error_reason.rb +1 -1
  57. data/lib/rley/parser/gfg_chart.rb +6 -6
  58. data/lib/rley/parser/gfg_parsing.rb +19 -19
  59. data/lib/rley/parser/parse_entry.rb +3 -3
  60. data/lib/rley/parser/parse_entry_set.rb +1 -1
  61. data/lib/rley/parser/parse_walker_factory.rb +15 -15
  62. data/lib/rley/syntax/grammar.rb +1 -1
  63. data/lib/rley/syntax/grammar_builder.rb +2 -2
  64. data/lib/rley/syntax/production.rb +4 -3
  65. data/lib/rley/syntax/symbol_seq.rb +2 -2
  66. data/spec/rley/base/grm_items_builder_spec.rb +1 -1
  67. data/spec/rley/engine_spec.rb +3 -6
  68. data/spec/rley/formatter/asciitree_spec.rb +0 -1
  69. data/spec/rley/formatter/bracket_notation_spec.rb +0 -1
  70. data/spec/rley/formatter/debug_spec.rb +2 -3
  71. data/spec/rley/gfg/grm_flow_graph_spec.rb +19 -19
  72. data/spec/rley/parse_rep/ast_builder_spec.rb +12 -12
  73. data/spec/rley/parser/gfg_earley_parser_spec.rb +1 -1
  74. data/spec/rley/parser/parse_entry_set_spec.rb +5 -5
  75. data/spec/rley/parser/parse_state_spec.rb +8 -3
  76. data/spec/rley/parser/parse_tracer_spec.rb +3 -1
  77. data/spec/rley/parser/parse_walker_factory_spec.rb +1 -1
  78. data/spec/rley/ptree/parse_tree_node_spec.rb +1 -1
  79. data/spec/rley/syntax/grammar_builder_spec.rb +1 -1
  80. data/spec/rley/syntax/grammar_spec.rb +1 -1
  81. metadata +2 -3
  82. data/spec/rley/support/ast_builder.rb +0 -403
@@ -31,8 +31,8 @@ module Rley # This module is used as a namespace
31
31
  # production.
32
32
  # @return [String]
33
33
  def inspect()
34
- result = selfie()
35
- result << " @antecedents=["
34
+ result = selfie
35
+ result << ' @antecedents=['
36
36
  antecedents.each do |antec|
37
37
  result << antec.selfie
38
38
  end
@@ -147,7 +147,7 @@ module Rley # This module is used as a namespace
147
147
  # Returns a human-readable and partial representation of itself.
148
148
  # @return [String]
149
149
  def selfie()
150
- result = "#<#{self.class.name}:#{self.object_id}"
150
+ result = "#<#{self.class.name}:#{object_id}"
151
151
  result << " @vertex=<#{vertex.class.name}:#{vertex.object_id}"
152
152
  result << " label=#{vertex.label}>"
153
153
  result << " @origin=#{origin}"
@@ -25,7 +25,7 @@ module Rley # This module is used as a namespace
25
25
  # set of parse entries.
26
26
  # @return [String]
27
27
  def inspect()
28
- result = "#<#{self.class.name}:#{self.object_id}"
28
+ result = "#<#{self.class.name}:#{object_id}"
29
29
  result << ' @entries=['
30
30
  entries.each { |e| result << e.inspect }
31
31
  result << ']>'
@@ -19,7 +19,7 @@ module Rley # This module is used as a namespace
19
19
  # non-terminal symbol => { index(=origin) => start entry }
20
20
  :return_stack, # @return [Array<ParseEntry>] A stack of parse entries
21
21
  :backtrack_points,
22
- :lazy_walk # If true and revisit end vertex then jump to start vertex
22
+ :lazy_walk # If true and revisit end vertex then jump to start vertex
23
23
  )
24
24
 
25
25
 
@@ -27,29 +27,29 @@ module Rley # This module is used as a namespace
27
27
  :entry_set_index, # Sigma set index of current parse entry
28
28
  :return_stack, # A stack of parse entries
29
29
  :visitee, # The parse entry being visited
30
- :antecedent_index,
30
+ :antecedent_index
31
31
  )
32
32
 
33
33
  # A factory that creates an Enumerator object
34
34
  # that itself walks through a GFGParsing object.
35
- # The walker (= Enumerator) yields visit events.
35
+ # The walker (= Enumerator) yields visit events.
36
36
  # This class implements an external iterator
37
37
  # for a given GFGParsing object.
38
- # This is different from the internal iterators, usually implemented
38
+ # This is different from the internal iterators, usually implemented
39
39
  # in Ruby with an :each method.
40
40
  # Allows to perform a backwards traversal over the relevant parse entries.
41
- # backwards traversal means that the traversal starts from the
41
+ # backwards traversal means that the traversal starts from the
42
42
  # accepting (final) parse entries and goes to the initial parse entry.
43
43
  # Relevant parse entries are parse entries that "count" in the parse
44
44
  # (i.e. they belong to a path that leads to the accepting parse entry)
45
45
  class ParseWalkerFactory
46
46
  # Build an Enumerator that will yield the parse entries as it
47
47
  # walks backwards on the parse graph.
48
- # @param acceptingEntry [ParseEntry] the final ParseEntry of a
48
+ # @param acceptingEntry [ParseEntry] the final ParseEntry of a
49
49
  # successful parse.
50
50
  # @param maxIndex [Integer] the index of the last input token.
51
51
  # @param lazyWalk [Boolean] if true then take some shortcut in re-visits.
52
- # @return [Enumerator] yields visit events when walking over the
52
+ # @return [Enumerator] yields visit events when walking over the
53
53
  # parse result
54
54
  def build_walker(acceptingEntry, maxIndex, lazyWalk = false)
55
55
  # Local context for the enumerator
@@ -93,12 +93,12 @@ module Rley # This module is used as a namespace
93
93
 
94
94
  return context
95
95
  end
96
-
96
+
97
97
  # Initialize the non-terminal to start entry mapping
98
98
  def init_nterm2start()
99
99
  h = Hash.new do |hsh, defval|
100
100
  entry, index = defval
101
- nonterm = entry.vertex.non_terminal
101
+ nonterm = entry.vertex.non_terminal
102
102
  if hsh.include? nonterm
103
103
  pre = hsh[nonterm]
104
104
  pre[index] = entry
@@ -106,7 +106,7 @@ module Rley # This module is used as a namespace
106
106
  hsh[nonterm] = { index => entry }
107
107
  end
108
108
  end
109
-
109
+
110
110
  return h
111
111
  end
112
112
 
@@ -134,7 +134,7 @@ module Rley # This module is used as a namespace
134
134
 
135
135
  when GFG::ItemVertex
136
136
  # Even for non-ambiguous parse, can be caused by
137
- # left recursive rule e.g. (S => S A)
137
+ # left recursive rule e.g. (S => S A)
138
138
  # Skip item entries while revisiting
139
139
  event = [:revisit, anEntry, index]
140
140
  else
@@ -207,19 +207,19 @@ module Rley # This module is used as a namespace
207
207
 
208
208
  when GFG::StartVertex
209
209
  new_entry = select_calling_entry(aContext)
210
-
210
+
211
211
  when GFG::ItemVertex
212
212
  # Push current entry onto stack
213
213
  # puts "Special push on return stack #{aContext.curr_entry}"
214
- aContext.return_stack << aContext.curr_entry
214
+ aContext.return_stack << aContext.curr_entry
215
215
  # puts "Add special backtrack point stack #{aContext.curr_entry}"
216
216
  bp = add_backtrack_point(aContext)
217
- new_entry = bp.visitee.antecedents[bp.antecedent_index]
217
+ new_entry = bp.visitee.antecedents[bp.antecedent_index]
218
218
  else
219
219
  raise StandardError, 'Internal error'
220
220
  end
221
221
 
222
- return [ new_entry ]
222
+ return [new_entry]
223
223
  end
224
224
 
225
225
  def add_backtrack_point(aContext)
@@ -190,7 +190,7 @@ module Rley # This module is used as a namespace
190
190
  # A nullable nonterminal is a nonterminal that can match an empty string.
191
191
  def compute_nullable()
192
192
  non_terminals.each { |nterm| nterm.nullable = false }
193
- nullable_sets = [ direct_nullable ]
193
+ nullable_sets = [direct_nullable]
194
194
 
195
195
  # Drop productions with one terminal in rhs or with a nullable lhs
196
196
  filtered_rules = rules.reject do |prod|
@@ -75,9 +75,9 @@ module Rley # This module is used as a namespace
75
75
  when Array
76
76
  rhs_constituents = rhs_repr.map { |name| get_nonterminal(name) }
77
77
  when String
78
- rhs_constituents = [ get_nonterminal(rhs_repr) ]
78
+ rhs_constituents = [get_nonterminal(rhs_repr)]
79
79
  when Terminal
80
- rhs_constituents = [ rhs_repr ]
80
+ rhs_constituents = [rhs_repr]
81
81
  end
82
82
  new_prod = Production.new(lhs, rhs_constituents)
83
83
  productions << new_prod
@@ -16,7 +16,8 @@ module Rley # This module is used as a namespace
16
16
  # @return [NonTerminal] The left-hand side of the rule.
17
17
  attr_reader(:lhs)
18
18
 
19
- # @return [String] The name of the production rule. It must be unique in a grammar.
19
+ # @return [String]
20
+ # The name of the production rule. It must be unique in a grammar.
20
21
  attr_accessor(:name)
21
22
 
22
23
  # @return [Boolean] A production is generative when all of its
@@ -55,8 +56,8 @@ module Rley # This module is used as a namespace
55
56
  # production.
56
57
  # @return [String]
57
58
  def inspect()
58
- result = "#<#{self.class.name}:#{self.object_id}"
59
- result << " @name=\"#{self.name}\""
59
+ result = "#<#{self.class.name}:#{object_id}"
60
+ result << " @name=\"#{name}\""
60
61
  result << " @lhs=#{lhs.name}"
61
62
  result << " @rhs=#{rhs.inspect}"
62
63
  result << " @generative=#{@generative}>"
@@ -38,8 +38,8 @@ module Rley # This module is used as a namespace
38
38
  # sequence of symbols.
39
39
  # @return [String]
40
40
  def inspect()
41
- result = "#<#{self.class.name}:#{self.object_id}"
42
- symbol_names = self.members.map(&:name)
41
+ result = "#<#{self.class.name}:#{object_id}"
42
+ symbol_names = members.map(&:name)
43
43
  result << " @members=#{symbol_names}>"
44
44
  return result
45
45
  end
@@ -23,7 +23,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
23
23
  # Next line calls method from mixin module under test
24
24
  items = build_dotted_items(grammar_abc)
25
25
  expect(items.size).to eq(8)
26
- expectations = [
26
+ expectations = [
27
27
  'S => . A',
28
28
  'S => A .',
29
29
  'A => . a A c',
@@ -19,9 +19,9 @@ module Rley # Open this namespace to avoid module qualifier prefixes
19
19
 
20
20
  it 'could be created with block argument' do
21
21
  expect { Engine.new do |config|
22
- config.parse_repr = :raw
23
- end
24
- }.not_to raise_error
22
+ config.parse_repr = :raw
23
+ end
24
+ }.not_to raise_error
25
25
  end
26
26
 
27
27
  it "shouldn't have a link to a grammar yet" do
@@ -87,8 +87,6 @@ module Rley # Open this namespace to avoid module qualifier prefixes
87
87
  end
88
88
  end # context
89
89
 
90
-
91
-
92
90
  context 'Parse tree manipulation:' do
93
91
  subject do
94
92
  instance = Engine.new
@@ -124,4 +122,3 @@ module Rley # Open this namespace to avoid module qualifier prefixes
124
122
  end # context
125
123
  end # describe
126
124
  end # module
127
-
@@ -13,7 +13,6 @@ require_relative '../../../lib/rley/formatter/asciitree'
13
13
  module Rley # Re-open the module to get rid of qualified names
14
14
  module Formatter
15
15
  describe Asciitree do
16
-
17
16
  # Factory method. Build a production with the given sequence
18
17
  # of symbols as its rhs.
19
18
  let(:grammar_abc) do
@@ -13,7 +13,6 @@ require_relative '../../../lib/rley/formatter/bracket_notation'
13
13
  module Rley # Re-open the module to get rid of qualified names
14
14
  module Formatter
15
15
  describe BracketNotation do
16
-
17
16
  # Factory method. Build a production with the given sequence
18
17
  # of symbols as its rhs.
19
18
  let(:grammar_abc) do
@@ -13,9 +13,8 @@ require_relative '../../../lib/rley/formatter/debug'
13
13
  module Rley # Re-open the module to get rid of qualified names
14
14
  module Formatter
15
15
  describe Debug do
16
-
17
- # Factory method. Build a production with the given sequence
18
- # of symbols as its rhs.
16
+ # Factory method. Build a production with the given sequence
17
+ # of symbols as its rhs.
19
18
  let(:grammar_abc) do
20
19
  sandbox = Object.new
21
20
  sandbox.extend(GrammarABCHelper)
@@ -139,12 +139,12 @@ module Rley # Open this namespace to avoid module qualifier prefixes
139
139
  subject.vertices.each do |a_vertex|
140
140
  next unless a_vertex.kind_of?(ItemVertex)
141
141
  if a_vertex.next_symbol.kind_of?(Syntax::NonTerminal)
142
- expect(a_vertex.shortcut).not_to be_nil
142
+ expect(a_vertex.shortcut).not_to be_nil
143
143
  my_d_item = a_vertex.dotted_item
144
-
144
+
145
145
  # Retrieve dotted item of shortcut successor
146
146
  other_d_item = a_vertex.shortcut.successor.dotted_item
147
-
147
+
148
148
  # Now the checks...
149
149
  expect(my_d_item.production).to eq(other_d_item.production)
150
150
  expect(my_d_item.position).to eq(other_d_item.prev_position)
@@ -154,7 +154,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
154
154
  end
155
155
  end
156
156
  end # context
157
-
157
+
158
158
  context 'Provided services:' do
159
159
  let(:problematic_grammar) do
160
160
  # Based on grammar example in book
@@ -166,14 +166,14 @@ module Rley # Open this namespace to avoid module qualifier prefixes
166
166
  builder.add_production('A' => 'a')
167
167
  # There is no edge between .B and B => B . b => non-generative
168
168
  builder.add_production('B' => %w[B b])
169
-
169
+
170
170
  # Non-terminal symbol C is unreachable
171
- builder.add_production('C' => 'c')
171
+ builder.add_production('C' => 'c')
172
172
 
173
173
  # And now build the grammar...
174
- builder.grammar
174
+ builder.grammar
175
175
  end
176
-
176
+
177
177
  it 'should provide depth-first traversal' do
178
178
  result = []
179
179
  subject.traverse_df(subject.start_vertex) do |vertex|
@@ -196,16 +196,16 @@ module Rley # Open this namespace to avoid module qualifier prefixes
196
196
  ]
197
197
  expect(result).to eq(expected)
198
198
  end
199
-
199
+
200
200
  it 'should provide human-readable representation of itself' do
201
201
  prefix = /^#<Rley::GFG::GrmFlowGraph:\d+ @vertices=\[/
202
202
  expect(subject.inspect).to match(prefix)
203
- pattern = /@vertices=\[#<Rley::GFG::StartVertex:\d+ label="\.S"/
203
+ pattern = /@vertices=\[#<Rley::GFG::StartVertex:\d+ label="\.S"/
204
204
  expect(subject.inspect).to match(pattern)
205
- suffix = /]>$/
206
- expect(subject.inspect).to match(suffix)
207
- end
208
-
205
+ suffix = /]>$/
206
+ expect(subject.inspect).to match(suffix)
207
+ end
208
+
209
209
  it 'should perform a diagnosis of a correct grammar' do
210
210
  expect { subject.diagnose }.not_to raise_error
211
211
  grammar_abc.non_terminals.each do |nterm|
@@ -213,22 +213,22 @@ module Rley # Open this namespace to avoid module qualifier prefixes
213
213
  expect(nterm).not_to be_unreachable
214
214
  end
215
215
  end
216
-
216
+
217
217
  it 'should detect when a non-terminal is unreachable' do
218
218
  grammar = problematic_grammar
219
219
  items = build_items_for_grammar(grammar)
220
220
 
221
- graph = GrmFlowGraph.new(items)
221
+ graph = GrmFlowGraph.new(items)
222
222
  expect { graph.diagnose }.not_to raise_error
223
223
  grammar.non_terminals.each do |nterm|
224
224
  expect(nterm).not_to be_undefined
225
225
  end
226
-
226
+
227
227
  unreachable = grammar.non_terminals.select(&:unreachable?)
228
228
  expect(unreachable.size).to eq(1)
229
229
  expect(unreachable[0].name).to eq('C')
230
- end
231
- end # context
230
+ end
231
+ end # context
232
232
  end # describe
233
233
  end # module
234
234
  end # module
@@ -45,8 +45,8 @@ module Rley # This module is used as a namespace
45
45
  Terminal2NodeClass
46
46
  end
47
47
 
48
- def reduce_P_0(_aProd, _range, _tokens, theChildren)
49
- return_first_child(_range, _tokens, theChildren)
48
+ def reduce_P_0(_aProd, aRange, theTokens, theChildren)
49
+ return_first_child(aRange, theTokens, theChildren)
50
50
  end
51
51
 
52
52
  # rule 'arr' => %w([ sequence ])
@@ -55,8 +55,8 @@ module Rley # This module is used as a namespace
55
55
  end
56
56
 
57
57
  # rule 'sequence' => ['list']
58
- def reduce_sequence_0(_aProd, _range, _tokens, theChildren)
59
- return_first_child(_range, _tokens, theChildren)
58
+ def reduce_sequence_0(_aProd, aRange, theTokens, theChildren)
59
+ return_first_child(aRange, theTokens, theChildren)
60
60
  end
61
61
 
62
62
  # rule 'sequence' => []
@@ -187,15 +187,15 @@ module Rley # Open this namespace to avoid module qualifier prefixes
187
187
  # Event: visit P => . arr | 0 0
188
188
  # Event: visit .P | 0 0
189
189
 
190
- # it 'should accept a first visit event' do
191
- # stack = get_stack(subject)
190
+ it 'should accept a first visit event' do
191
+ stack = get_stack(subject)
192
192
 
193
- # next_event('visit P. | 0 7')
194
- # expect(stack.size).to eq(1)
195
- # # stack: [P[0, 7]]
196
- # expect(stack.last.range).to eq(create_range(0, 7))
197
- # expect(stack.last.children).to be_nil
198
- # end
193
+ next_event('visit P. | 0 7')
194
+ expect(stack.size).to eq(1)
195
+ # stack: [P[0, 7]]
196
+ expect(stack.last.range).to eq(create_range(0, 7))
197
+ expect(stack.last.children).to be_nil
198
+ end
199
199
 
200
200
  it 'should build a tree for an empty array' do
201
201
  stack = get_stack(subject)
@@ -288,7 +288,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
288
288
  builder.add_terminals(t_x)
289
289
  builder.add_production('Ss' => %w[A A x])
290
290
  builder.add_production('A' => [])
291
- tokens = [ Lexical::Token.new('x', t_x) ]
291
+ tokens = [Lexical::Token.new('x', t_x)]
292
292
 
293
293
  instance = GFGEarleyParser.new(builder.grammar)
294
294
  expect { instance.parse(tokens) }.not_to raise_error
@@ -76,7 +76,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
76
76
  subject.push_entry(entry2)
77
77
  expect(subject.entries4term(t_b)).to eq([entry1, entry2])
78
78
  end
79
-
79
+
80
80
  it 'should list the expected terminals' do
81
81
  subject.push_entry(entry1)
82
82
  subject.push_entry(entry2)
@@ -90,20 +90,20 @@ module Rley # Open this namespace to avoid module qualifier prefixes
90
90
  subject.push_entry(entry3)
91
91
  expect(subject.entries4n_term(nt_rep_c)).to eq([entry3])
92
92
  end
93
-
93
+
94
94
  it 'should provide human-readable representation of itself' do
95
95
  # Case 1: empty set
96
96
  pattern_empty = /^#<Rley::Parser::ParseEntrySet:\d+ @entries=\[\]>$/
97
97
  expect(subject.inspect).to match(pattern_empty)
98
-
98
+
99
99
  # Case 2: non-empty set
100
100
  subject.push_entry(entry1)
101
101
  prefix = /^#<Rley::Parser::ParseEntrySet:\d+ @entries=\[#<Rley/
102
102
  expect(subject.inspect).to match(prefix)
103
- pattern_entry = /ParseEntry:\d+ @vertex=<Rley::GFG::ItemVertex:\d+/
103
+ pattern_entry = /ParseEntry:\d+ @vertex=<Rley::GFG::ItemVertex:\d+/
104
104
  expect(subject.inspect).to match(pattern_entry)
105
105
  suffix = /=> a \. b b Repetition> @origin=2 @antecedents=\[\]>\]>$/
106
- expect(subject.inspect).to match(suffix)
106
+ expect(subject.inspect).to match(suffix)
107
107
  end
108
108
 
109
109
  =begin
@@ -57,6 +57,11 @@ module Rley # Open this namespace to avoid module qualifier prefixes
57
57
  end # context
58
58
 
59
59
  context 'Provided services:' do
60
+ def new_parse_state(aProd, aRank, aVal)
61
+ item = Base::DottedItem.new(aProd, aRank)
62
+ ParseState.new(item, aVal)
63
+ end
64
+
60
65
  it 'should compare with itself' do
61
66
  synonym = subject # Fool Rubocop
62
67
  expect(subject == synonym).to eq(true)
@@ -97,12 +102,12 @@ module Rley # Open this namespace to avoid module qualifier prefixes
97
102
 
98
103
  it 'should know whether another instance follows this one' do
99
104
  expect(subject.precedes?(subject)).to eq(false)
100
- state1 = ParseState.new(Base::DottedItem.new(sample_prod, 1), origin_val)
105
+ state1 = new_parse_state(sample_prod, 1, origin_val)
101
106
  expect(state1.precedes?(subject)).to eq(true)
102
- state0 = ParseState.new(Base::DottedItem.new(sample_prod, 0), origin_val)
107
+ state0 = new_parse_state(sample_prod, 0, origin_val)
103
108
  expect(state0.precedes?(state1)).to eq(true)
104
109
  expect(state0.precedes?(subject)).to eq(false)
105
- state3 = ParseState.new(Base::DottedItem.new(sample_prod, 3), origin_val)
110
+ state3 = new_parse_state(sample_prod, 3, origin_val)
106
111
  expect(state3.precedes?(state0)).to eq(false)
107
112
  end
108
113