rley 0.8.14 → 0.9.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 (106) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -2
  3. data/CHANGELOG.md +14 -0
  4. data/Gemfile +8 -0
  5. data/examples/general/calc_iter1/spec/calculator_spec.rb +9 -9
  6. data/examples/general/calc_iter2/spec/calculator_spec.rb +39 -39
  7. data/examples/general/recursive_right.rb +2 -2
  8. data/lib/rley/constants.rb +2 -2
  9. data/lib/rley/engine.rb +3 -1
  10. data/lib/rley/formatter/asciitree.rb +4 -1
  11. data/lib/rley/gfg/epsilon_edge.rb +0 -2
  12. data/lib/rley/gfg/grm_flow_graph.rb +7 -9
  13. data/lib/rley/gfg/item_vertex.rb +1 -1
  14. data/lib/rley/gfg/vertex.rb +11 -0
  15. data/lib/rley/lexical/token.rb +10 -3
  16. data/lib/rley/parse_forest_visitor.rb +3 -3
  17. data/lib/rley/parse_rep/ast_base_builder.rb +6 -5
  18. data/lib/rley/parse_rep/parse_forest_builder.rb +4 -2
  19. data/lib/rley/parse_rep/parse_tree_builder.rb +14 -2
  20. data/lib/rley/parse_rep/parse_tree_factory.rb +1 -1
  21. data/lib/rley/parser/error_reason.rb +2 -2
  22. data/lib/rley/parser/gfg_chart.rb +2 -2
  23. data/lib/rley/parser/gfg_earley_parser.rb +2 -2
  24. data/lib/rley/parser/gfg_parsing.rb +1 -1
  25. data/lib/rley/parser/parse_entry.rb +4 -4
  26. data/lib/rley/parser/parse_entry_set.rb +4 -2
  27. data/lib/rley/parser/parse_entry_tracker.rb +10 -7
  28. data/lib/rley/parser/parse_walker_factory.rb +9 -8
  29. data/lib/rley/ptree/parse_tree_node.rb +6 -0
  30. data/lib/rley/ptree/terminal_node.rb +1 -1
  31. data/lib/rley/rgn/ast_builder.rb +2 -2
  32. data/lib/rley/rgn/ast_node.rb +11 -1
  33. data/lib/rley/rgn/ast_visitor.rb +2 -2
  34. data/lib/rley/rgn/composite_node.rb +1 -1
  35. data/lib/rley/rgn/grammar_builder.rb +12 -14
  36. data/lib/rley/rgn/parser.rb +2 -2
  37. data/lib/rley/rgn/tokenizer.rb +1 -1
  38. data/lib/rley/rley_error.rb +0 -4
  39. data/lib/rley/sppf/composite_node.rb +6 -0
  40. data/lib/rley/sppf/parse_forest.rb +7 -7
  41. data/lib/rley/sppf/sppf_node.rb +15 -1
  42. data/lib/rley/syntax/base_grammar_builder.rb +3 -12
  43. data/lib/rley/syntax/grammar.rb +9 -4
  44. data/lib/rley/syntax/production.rb +1 -1
  45. data/spec/rley/base/dotted_item_spec.rb +46 -46
  46. data/spec/rley/base/grm_items_builder_spec.rb +1 -1
  47. data/spec/rley/engine_spec.rb +50 -50
  48. data/spec/rley/formatter/asciitree_spec.rb +8 -8
  49. data/spec/rley/formatter/bracket_notation_spec.rb +10 -10
  50. data/spec/rley/formatter/debug_spec.rb +10 -10
  51. data/spec/rley/formatter/json_spec.rb +6 -7
  52. data/spec/rley/gfg/call_edge_spec.rb +6 -6
  53. data/spec/rley/gfg/edge_spec.rb +8 -7
  54. data/spec/rley/gfg/end_vertex_spec.rb +8 -7
  55. data/spec/rley/gfg/epsilon_edge_spec.rb +5 -4
  56. data/spec/rley/gfg/grm_flow_graph_spec.rb +33 -34
  57. data/spec/rley/gfg/item_vertex_spec.rb +34 -36
  58. data/spec/rley/gfg/non_terminal_vertex_spec.rb +12 -12
  59. data/spec/rley/gfg/return_edge_spec.rb +6 -6
  60. data/spec/rley/gfg/scan_edge_spec.rb +7 -6
  61. data/spec/rley/gfg/shortcut_edge_spec.rb +15 -15
  62. data/spec/rley/gfg/start_vertex_spec.rb +8 -8
  63. data/spec/rley/gfg/vertex_spec.rb +18 -18
  64. data/spec/rley/lexical/literal_spec.rb +5 -5
  65. data/spec/rley/lexical/token_range_spec.rb +55 -55
  66. data/spec/rley/lexical/token_spec.rb +17 -16
  67. data/spec/rley/parse_forest_visitor_spec.rb +30 -32
  68. data/spec/rley/parse_rep/ambiguous_parse_spec.rb +2 -2
  69. data/spec/rley/parse_rep/ast_builder_spec.rb +30 -30
  70. data/spec/rley/parse_rep/cst_builder_spec.rb +85 -85
  71. data/spec/rley/parse_rep/groucho_spec.rb +23 -23
  72. data/spec/rley/parse_rep/parse_forest_builder_spec.rb +42 -42
  73. data/spec/rley/parse_rep/parse_forest_factory_spec.rb +10 -12
  74. data/spec/rley/parse_rep/parse_tree_factory_spec.rb +10 -15
  75. data/spec/rley/parse_tree_visitor_spec.rb +43 -46
  76. data/spec/rley/parser/dangling_else_spec.rb +12 -12
  77. data/spec/rley/parser/error_reason_spec.rb +37 -37
  78. data/spec/rley/parser/gfg_chart_spec.rb +27 -29
  79. data/spec/rley/parser/gfg_earley_parser_spec.rb +55 -56
  80. data/spec/rley/parser/gfg_parsing_spec.rb +106 -103
  81. data/spec/rley/parser/parse_entry_set_spec.rb +63 -61
  82. data/spec/rley/parser/parse_entry_spec.rb +73 -71
  83. data/spec/rley/parser/parse_walker_factory_spec.rb +14 -15
  84. data/spec/rley/ptree/non_terminal_node_spec.rb +16 -16
  85. data/spec/rley/ptree/parse_tree_node_spec.rb +11 -11
  86. data/spec/rley/ptree/parse_tree_spec.rb +6 -8
  87. data/spec/rley/ptree/terminal_node_spec.rb +6 -6
  88. data/spec/rley/rgn/grammar_builder_spec.rb +69 -67
  89. data/spec/rley/rgn/parser_spec.rb +63 -63
  90. data/spec/rley/rgn/repetition_node_spec.rb +15 -15
  91. data/spec/rley/rgn/sequence_node_spec.rb +10 -10
  92. data/spec/rley/rgn/symbol_node_spec.rb +5 -6
  93. data/spec/rley/rgn/tokenizer_spec.rb +68 -67
  94. data/spec/rley/sppf/alternative_node_spec.rb +16 -16
  95. data/spec/rley/sppf/non_terminal_node_spec.rb +20 -20
  96. data/spec/rley/sppf/token_node_spec.rb +13 -13
  97. data/spec/rley/syntax/base_grammar_builder_spec.rb +76 -86
  98. data/spec/rley/syntax/grammar_spec.rb +40 -78
  99. data/spec/rley/syntax/grm_symbol_spec.rb +7 -7
  100. data/spec/rley/syntax/match_closest_spec.rb +8 -8
  101. data/spec/rley/syntax/non_terminal_spec.rb +25 -25
  102. data/spec/rley/syntax/production_spec.rb +33 -33
  103. data/spec/rley/syntax/symbol_seq_spec.rb +27 -27
  104. data/spec/rley/syntax/terminal_spec.rb +12 -11
  105. data/spec/support/base_tokenizer_spec.rb +9 -8
  106. metadata +8 -25
@@ -11,21 +11,22 @@ require_relative '../../../lib/rley/gfg/edge'
11
11
  module Rley # Open this namespace to avoid module qualifier prefixes
12
12
  module GFG # Open this namespace to avoid module qualifier prefixes
13
13
  describe Edge do
14
+ subject(:an_edge) { described_class.new(vertex1, vertex2) }
15
+
14
16
  let(:vertex1) { StartVertex.new('from') }
15
17
  let(:vertex2) { StartVertex.new('to') }
16
- subject { Edge.new(vertex1, vertex2) }
17
18
 
18
19
  context 'Initialization:' do
19
- it 'should be created with two vertice arguments' do
20
- expect { Edge.new(vertex1, vertex2) }.not_to raise_error
20
+ it 'is created with two vertice arguments' do
21
+ expect { described_class.new(vertex1, vertex2) }.not_to raise_error
21
22
  end
22
23
 
23
- it 'should be registered by the predecessor vertex' do
24
- expect(subject).to eq(vertex1.edges.last)
24
+ it 'is registered by the predecessor vertex' do
25
+ expect(an_edge).to eq(vertex1.edges.last)
25
26
  end
26
27
 
27
- it 'should know the successor vertex' do
28
- expect(subject.successor).to eq(vertex2)
28
+ it 'knows the successor vertex' do
29
+ expect(an_edge.successor).to eq(vertex2)
29
30
  end
30
31
  end # context
31
32
  end # describe
@@ -9,24 +9,25 @@ require_relative '../../../lib/rley/gfg/end_vertex'
9
9
  module Rley # Open this namespace to avoid module qualifier prefixes
10
10
  module GFG # Open this namespace to avoid module qualifier prefixes
11
11
  describe EndVertex do
12
+ subject(:a_vertex) { described_class.new(sample_nt) }
13
+
12
14
  let(:sample_nt) { Syntax::NonTerminal.new('NT') }
13
- subject { EndVertex.new(sample_nt) }
14
15
 
15
16
  context 'Initialization:' do
16
- it 'should be created with a non-terminal symbol' do
17
- expect { EndVertex.new(sample_nt) }.not_to raise_error
17
+ it 'is created with a non-terminal symbol' do
18
+ expect { described_class.new(sample_nt) }.not_to raise_error
18
19
  end
19
20
 
20
- it 'should know its label' do
21
+ it 'knows its label' do
21
22
  expect(sample_nt).to receive(:to_s).and_return('NT')
22
- expect(subject.label).to eq('NT.')
23
+ expect(a_vertex.label).to eq('NT.')
23
24
  end
24
25
  end # context
25
26
 
26
27
  context 'Provided services:' do
27
- it 'should provide human-readable representation of itself' do
28
+ it 'provides human-readable representation of itself' do
28
29
  pattern = /^#<Rley::GFG::EndVertex:\d+ label="NT\."/
29
- expect(subject.inspect).to match(pattern)
30
+ expect(a_vertex.inspect).to match(pattern)
30
31
  end
31
32
  end # context
32
33
  end # describe
@@ -10,14 +10,15 @@ require_relative '../../../lib/rley/gfg/epsilon_edge'
10
10
 
11
11
  module Rley # Open this namespace to avoid module qualifier prefixes
12
12
  module GFG # Open this namespace to avoid module qualifier prefixes
13
- describe Edge do
13
+ describe EpsilonEdge do
14
+ subject { described_class.new(vertex1, vertex2) }
15
+
14
16
  let(:vertex1) { StartVertex.new('from') }
15
17
  let(:vertex2) { StartVertex.new('to') }
16
- subject { EpsilonEdge.new(vertex1, vertex2) }
17
18
 
18
19
  context 'Initialization:' do
19
- it 'should be created with two vertice arguments' do
20
- expect { EpsilonEdge.new(vertex1, vertex2) }.not_to raise_error
20
+ it 'is created with two vertice arguments' do
21
+ expect { described_class.new(vertex1, vertex2) }.not_to raise_error
21
22
  end
22
23
  end # context
23
24
  end # describe
@@ -34,6 +34,9 @@ module Rley # Open this namespace to avoid module qualifier prefixes
34
34
  end
35
35
  end
36
36
 
37
+ # Default instantiation rule
38
+ subject(:a_graph) { described_class.new(items_from_grammar) }
39
+
37
40
  # Factory method. Build a production with the given sequence
38
41
  # of symbols as its rhs.
39
42
  let(:grammar_abc) do
@@ -45,52 +48,48 @@ module Rley # Open this namespace to avoid module qualifier prefixes
45
48
  # from the abc grammar
46
49
  let(:items_from_grammar) { build_items_for_grammar(grammar_abc) }
47
50
 
48
- # Default instantiation rule
49
- subject { GrmFlowGraph.new(items_from_grammar) }
50
-
51
-
52
51
  context 'Initialization:' do
53
- it 'should be created with an array of dotted items' do
54
- expect { GrmFlowGraph.new(items_from_grammar) }.not_to raise_error
52
+ it 'is created with an array of dotted items' do
53
+ expect { described_class.new(items_from_grammar) }.not_to raise_error
55
54
  end
56
55
 
57
- it 'should know its main start vertex' do
58
- expect(subject.start_vertex).to eq(subject.vertices.first)
56
+ it 'knows its main start vertex' do
57
+ expect(a_graph.start_vertex).to eq(a_graph.vertices.first)
59
58
  end
60
59
 
61
- it 'should have the correct number of vertices' do
60
+ it 'has the correct number of vertices' do
62
61
  # Number of vertices = count of dotted items +...
63
62
  # ... 2 * count of non-terminals
64
63
  count_vertices = 2 * grammar_abc.non_terminals.size
65
64
  count_vertices += items_from_grammar.size
66
- expect(subject.vertices.size).to eq(count_vertices)
65
+ expect(a_graph.vertices.size).to eq(count_vertices)
67
66
  end
68
67
 
69
- it 'should have for each non-terminal one start and end vertex' do
68
+ it 'has for each non-terminal one start and end vertex' do
70
69
  # Iterate over all non-terminals of grammar...
71
70
  grammar_abc.non_terminals.each do |nterm|
72
71
  # ...to each non-terminal there should be a start vertex
73
- start_vertex = subject.start_vertex_for[nterm]
74
- expect(start_vertex).to be_kind_of(StartVertex)
72
+ start_vertex = a_graph.start_vertex_for[nterm]
73
+ expect(start_vertex).to be_a(StartVertex)
75
74
  expect(start_vertex.label).to eq(".#{nterm}")
76
75
 
77
76
  # ...to each non-terminal there should be an end vertex
78
- end_vertex = subject.end_vertex_for[nterm]
79
- expect(end_vertex).to be_kind_of(EndVertex)
77
+ end_vertex = a_graph.end_vertex_for[nterm]
78
+ expect(end_vertex).to be_a(EndVertex)
80
79
  expect(end_vertex.label).to eq("#{nterm}.")
81
80
  end
82
81
  end
83
82
 
84
- it 'should have one or more entry edges per start vertex' do
85
- subject.start_vertex_for.each_value do |a_start|
83
+ it 'has one or more entry edges per start vertex' do
84
+ a_graph.start_vertex_for.each_value do |a_start|
86
85
  expect(a_start.edges.size >= 1).to be_truthy
87
86
  a_start.edges.each do |edge|
88
- expect(edge.successor.dotted_item.at_start?).to be_truthy
87
+ expect(edge.successor.dotted_item).to be_at_start
89
88
  end
90
89
  end
91
90
  end
92
91
 
93
- it 'should have the correct graph structure' do
92
+ it 'has the correct graph structure' do
94
93
  # We use the abc grammar
95
94
  expected = [
96
95
  '.S --> S => . A',
@@ -108,10 +107,10 @@ module Rley # Open this namespace to avoid module qualifier prefixes
108
107
  'A => b . --> A.'
109
108
  ]
110
109
 
111
- compare_graph_expectations(subject, expected)
110
+ compare_graph_expectations(a_graph, expected)
112
111
  end
113
112
 
114
- it 'should handle empty productions' do
113
+ it 'handles empty productions' do
115
114
  builder = Rley::Syntax::BaseGrammarBuilder.new
116
115
  builder.add_terminals('a')
117
116
  builder.add_production('S' => 'A')
@@ -121,7 +120,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
121
120
  grammar = builder.grammar
122
121
  items = build_items_for_grammar(grammar)
123
122
 
124
- graph = GrmFlowGraph.new(items)
123
+ graph = described_class.new(items)
125
124
  expected = [
126
125
  '.S --> S => . A',
127
126
  '.A --> A => . a',
@@ -137,8 +136,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
137
136
  compare_graph_expectations(graph, expected)
138
137
  end
139
138
 
140
- it 'should have shortcut edges' do
141
- subject.vertices.each do |a_vertex|
139
+ it 'has shortcut edges' do
140
+ a_graph.vertices.each do |a_vertex|
142
141
  next unless a_vertex.kind_of?(ItemVertex)
143
142
 
144
143
  if a_vertex.next_symbol.kind_of?(Syntax::NonTerminal)
@@ -177,9 +176,9 @@ module Rley # Open this namespace to avoid module qualifier prefixes
177
176
  builder.grammar
178
177
  end
179
178
 
180
- it 'should provide depth-first traversal' do
179
+ it 'provides depth-first traversal' do
181
180
  result = []
182
- subject.traverse_df(subject.start_vertex) do |vertex|
181
+ a_graph.traverse_df(a_graph.start_vertex) do |vertex|
183
182
  result << vertex.label
184
183
  end
185
184
 
@@ -200,28 +199,28 @@ module Rley # Open this namespace to avoid module qualifier prefixes
200
199
  expect(result).to eq(expected)
201
200
  end
202
201
 
203
- it 'should provide human-readable representation of itself' do
202
+ it 'provides human-readable representation of itself' do
204
203
  prefix = /^#<Rley::GFG::GrmFlowGraph:\d+ @vertices=\[/
205
- expect(subject.inspect).to match(prefix)
204
+ expect(a_graph.inspect).to match(prefix)
206
205
  pattern = /@vertices=\[#<Rley::GFG::StartVertex:\d+ label="\.S"/
207
- expect(subject.inspect).to match(pattern)
206
+ expect(a_graph.inspect).to match(pattern)
208
207
  suffix = /]>$/
209
- expect(subject.inspect).to match(suffix)
208
+ expect(a_graph.inspect).to match(suffix)
210
209
  end
211
210
 
212
- it 'should perform a diagnosis of a correct grammar' do
213
- expect { subject.diagnose }.not_to raise_error
211
+ it 'performs a diagnosis of a correct grammar' do
212
+ expect { a_graph.diagnose }.not_to raise_error
214
213
  grammar_abc.non_terminals.each do |nterm|
215
214
  expect(nterm).not_to be_undefined
216
215
  expect(nterm).not_to be_unreachable
217
216
  end
218
217
  end
219
218
 
220
- it 'should detect when a non-terminal is unreachable' do
219
+ it 'detects when a non-terminal is unreachable' do
221
220
  grammar = problematic_grammar
222
221
  items = build_items_for_grammar(grammar)
223
222
 
224
- graph = GrmFlowGraph.new(items)
223
+ graph = described_class.new(items)
225
224
  expect { graph.diagnose }.not_to raise_error
226
225
  grammar.non_terminals.each do |nterm|
227
226
  expect(nterm).not_to be_undefined
@@ -18,6 +18,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
18
18
  def build_prod(theLHS, *theRHSSymbols)
19
19
  return Syntax::Production.new(theLHS, theRHSSymbols)
20
20
  end
21
+ subject(:a_vertex) { described_class.new(sample_item) }
21
22
 
22
23
  let(:t_a) { Rley::Syntax::Terminal.new('a') }
23
24
  let(:t_b) { Rley::Syntax::Terminal.new('b') }
@@ -31,101 +32,98 @@ module Rley # Open this namespace to avoid module qualifier prefixes
31
32
  let(:empty_prod) { build_prod(nt_sentence) }
32
33
  let(:sample_item) { Base::DottedItem.new(sample_prod, 1) }
33
34
  let(:next_item) { Base::DottedItem.new(sample_prod, 2) }
34
- subject { ItemVertex.new(sample_item) }
35
35
 
36
36
  context 'Initialization:' do
37
- it 'should be created with a dotted item' do
38
- expect { ItemVertex.new(sample_item) }.not_to raise_error
37
+ it 'is created with a dotted item' do
38
+ expect { described_class.new(sample_item) }.not_to raise_error
39
39
  end
40
40
 
41
- it 'should know its dotted item' do
42
- expect(subject.dotted_item).to eq(sample_item)
41
+ it 'knows its dotted item' do
42
+ expect(a_vertex.dotted_item).to eq(sample_item)
43
43
  end
44
44
 
45
- it 'should not have any shortcut edge at start' do
46
- expect(subject.shortcut).to be_nil
45
+ it 'does not have any shortcut edge at start' do
46
+ expect(a_vertex.shortcut).to be_nil
47
47
  end
48
48
  end # context
49
49
 
50
50
  context 'Provided services:' do
51
- it 'should know its label' do
52
- expect(subject.label).to eq(sample_item.to_s)
51
+ it 'knows its label' do
52
+ expect(a_vertex.label).to eq(sample_item.to_s)
53
53
  end
54
54
 
55
- it 'should know the lhs of the production' do
56
- expect(subject.lhs).to eq(nt_sentence)
55
+ it 'knows the lhs of the production' do
56
+ expect(a_vertex.lhs).to eq(nt_sentence)
57
57
  end
58
58
 
59
- it 'should know whether it has a dot at the end of the rhs' do
59
+ it 'knows whether it has a dot at the end of the rhs' do
60
60
  # Case: dot not at the end
61
- expect(subject).not_to be_complete
61
+ expect(a_vertex).not_to be_complete
62
62
 
63
63
  # Case: dot at the end
64
- instance1 = ItemVertex.new(Base::DottedItem.new(sample_prod, 3))
64
+ instance1 = described_class.new(Base::DottedItem.new(sample_prod, 3))
65
65
  expect(instance1).to be_complete
66
66
 
67
67
  # Case: empty production
68
- instance2 = ItemVertex.new(Base::DottedItem.new(empty_prod, 0))
68
+ instance2 = described_class.new(Base::DottedItem.new(empty_prod, 0))
69
69
  expect(instance2).to be_complete
70
70
  end
71
71
 
72
- it 'should know the previous symbol (if any) in the rhs' do
72
+ it 'knows the previous symbol (if any) in the rhs (i)' do
73
73
  # Case: dot is after first symbol
74
- instance1 = ItemVertex.new(sample_item)
74
+ instance1 = described_class.new(sample_item)
75
75
  expect(instance1.prev_symbol).to eq(t_a)
76
76
 
77
77
  # Case: dot is after second or later symbol
78
- instance2 = ItemVertex.new(next_item)
78
+ instance2 = described_class.new(next_item)
79
79
  expect(instance2.prev_symbol).to eq(nt_b_sequence)
80
80
 
81
81
  # Case: dot is at begin
82
- instance3 = ItemVertex.new(Base::DottedItem.new(sample_prod, 0))
82
+ instance3 = described_class.new(Base::DottedItem.new(sample_prod, 0))
83
83
  expect(instance3.prev_symbol).to be_nil
84
84
 
85
85
  # Case: empty production
86
- instance4 = ItemVertex.new(Base::DottedItem.new(empty_prod, 0))
86
+ instance4 = described_class.new(Base::DottedItem.new(empty_prod, 0))
87
87
  expect(instance4.prev_symbol).to be_nil
88
88
  end
89
89
 
90
90
 
91
- it 'should know the next symbol (if any) in the rhs' do
91
+ it 'knows the next symbol (if any) in the rhs (ii)' do
92
92
  # Case: dot is not penultimate
93
- expect(subject.next_symbol).to eq(nt_b_sequence)
93
+ expect(a_vertex.next_symbol).to eq(nt_b_sequence)
94
94
 
95
95
  # Case: dot is penultimate
96
- instance1 = ItemVertex.new(next_item)
96
+ instance1 = described_class.new(next_item)
97
97
  expect(instance1.next_symbol).to eq(t_c)
98
98
 
99
99
  # Case: dot is at end
100
- instance2 = ItemVertex.new(Base::DottedItem.new(sample_prod, 3))
100
+ instance2 = described_class.new(Base::DottedItem.new(sample_prod, 3))
101
101
  expect(instance2.next_symbol).to be_nil
102
102
 
103
103
  # Case: empty production
104
- instance3 = ItemVertex.new(Base::DottedItem.new(empty_prod, 0))
104
+ instance3 = described_class.new(Base::DottedItem.new(empty_prod, 0))
105
105
  expect(instance3.next_symbol).to be_nil
106
106
  end
107
107
 
108
- it 'should accept a shortcut edge' do
109
- next_vertex = ItemVertex.new(next_item)
108
+ it 'accepts a shortcut edge' do
109
+ next_vertex = described_class.new(next_item)
110
110
 
111
111
  # The ShortcutEdge constructor invokes the shortcut setter
112
- shortcut = ShortcutEdge.new(subject, next_vertex)
113
- expect(subject.shortcut).to eq(shortcut)
112
+ shortcut = ShortcutEdge.new(a_vertex, next_vertex)
113
+ expect(a_vertex.shortcut).to eq(shortcut)
114
114
  end
115
115
 
116
- it 'should reject an invalid shortcut edge' do
116
+ it 'rejects an invalid shortcut edge' do
117
117
  err = StandardError
118
118
  err_msg = 'Invalid shortcut argument'
119
- expect { subject.shortcut = 'invalid' }.to raise_error(err, err_msg)
119
+ expect { a_vertex.shortcut = 'invalid' }.to raise_error(err, err_msg)
120
120
  end
121
- end # context
122
121
 
123
- context 'Provided services:' do
124
- it 'should provide human-readable representation of itself' do
122
+ it 'provides human-readable representation of itself' do
125
123
  prefix = /^#<Rley::GFG::ItemVertex:\d+/
126
- expect(subject.inspect).to match(prefix)
124
+ expect(a_vertex.inspect).to match(prefix)
127
125
  suffix = /label="sentence => a \. b_sequence c">$/
128
- expect(subject.inspect).to match(suffix)
126
+ expect(a_vertex.inspect).to match(suffix)
129
127
  end
130
128
  end # context
131
129
  end # describe
@@ -8,30 +8,30 @@ require_relative '../../../lib/rley/gfg/non_terminal_vertex'
8
8
  module Rley # Open this namespace to avoid module qualifier prefixes
9
9
  module GFG # Open this namespace to avoid module qualifier prefixes
10
10
  describe NonTerminalVertex do
11
+ subject(:a_vertex) { described_class.new(sample_nt) }
11
12
  let(:sample_nt) { double('fake-non-terminal') }
12
- subject { NonTerminalVertex.new(sample_nt) }
13
13
 
14
14
  context 'Initialization:' do
15
- it 'should be created with a non-terminal symbol' do
16
- expect { NonTerminalVertex.new(sample_nt) }.not_to raise_error
15
+ it 'is created with a non-terminal symbol' do
16
+ expect { described_class.new(sample_nt) }.not_to raise_error
17
17
  end
18
18
 
19
- it 'should know its non-terminal' do
20
- expect(subject.non_terminal).to eq(sample_nt)
19
+ it 'knows its non-terminal' do
20
+ expect(a_vertex.non_terminal).to eq(sample_nt)
21
21
  end
22
22
 
23
23
 
24
- it 'should accept at more than one outgoing edge' do
24
+ it 'accepts at more than one outgoing edge' do
25
25
  edge1 = double('fake-edge1')
26
26
  edge2 = double('fake-edge2')
27
27
 
28
- expect { subject.add_edge(edge1) }.not_to raise_error
29
- expect(subject.edges.size).to eq(1)
30
- expect(subject.edges.last).to eq(edge1)
28
+ expect { a_vertex.add_edge(edge1) }.not_to raise_error
29
+ expect(a_vertex.edges.size).to eq(1)
30
+ expect(a_vertex.edges.last).to eq(edge1)
31
31
 
32
- expect { subject.add_edge(edge2) }.not_to raise_error
33
- expect(subject.edges.size).to eq(2)
34
- expect(subject.edges.last).to eq(edge2)
32
+ expect { a_vertex.add_edge(edge2) }.not_to raise_error
33
+ expect(a_vertex.edges.size).to eq(2)
34
+ expect(a_vertex.edges.last).to eq(edge2)
35
35
  end
36
36
  end # context
37
37
  end # describe
@@ -21,6 +21,8 @@ module Rley # Open this namespace to avoid module qualifier prefixes
21
21
  return Syntax::Production.new(theLHS, theRHSSymbols)
22
22
  end
23
23
 
24
+ subject(:an_edge) { described_class.new(vertex1, vertex2) }
25
+
24
26
  let(:t_a) { Rley::Syntax::Terminal.new('a') }
25
27
  let(:t_b) { Rley::Syntax::Terminal.new('b') }
26
28
  let(:t_c) { Rley::Syntax::Terminal.new('c') }
@@ -28,22 +30,20 @@ module Rley # Open this namespace to avoid module qualifier prefixes
28
30
  let(:nt_b_sequence) { Rley::Syntax::NonTerminal.new('b_sequence') }
29
31
  let(:sample_prod) { build_prod(nt_sentence, t_a, nt_b_sequence, t_c) }
30
32
  let(:sample_item) { Base::DottedItem.new(sample_prod, 1) }
31
-
32
33
  let(:vertex1) { EndVertex.new('from') }
33
34
  let(:vertex2) { ItemVertex.new(sample_item) }
34
- subject { ReturnEdge.new(vertex1, vertex2) }
35
35
 
36
36
  context 'Initialization:' do
37
- it 'should be created with two vertice arguments' do
38
- expect { ReturnEdge.new(vertex1, vertex2) }.not_to raise_error
37
+ it 'is created with two vertice arguments' do
38
+ expect { described_class.new(vertex1, vertex2) }.not_to raise_error
39
39
  end
40
40
  end # context
41
41
 
42
42
  context 'Provided services:' do
43
- it 'should know its key' do
43
+ it 'knows its key' do
44
44
  pos = sample_item.position
45
45
  expectation = "RET_#{sample_prod.object_id}_#{pos - 1}"
46
- expect(subject.key).to eq(expectation)
46
+ expect(an_edge.key).to eq(expectation)
47
47
  end
48
48
  end # context
49
49
  end # describe
@@ -10,21 +10,22 @@ require_relative '../../../lib/rley/gfg/scan_edge'
10
10
 
11
11
  module Rley # Open this namespace to avoid module qualifier prefixes
12
12
  module GFG # Open this namespace to avoid module qualifier prefixes
13
- describe Edge do
13
+ describe ScanEdge do
14
+ subject(:an_edge) { described_class.new(vertex1, vertex2, sample_terminal) }
15
+
14
16
  let(:vertex1) { StartVertex.new('from') }
15
17
  let(:vertex2) { StartVertex.new('to') }
16
18
  let(:sample_terminal) { double('fake-terminal') }
17
- subject { ScanEdge.new(vertex1, vertex2, sample_terminal) }
18
19
 
19
20
  context 'Initialization:' do
20
- it 'should be created with two vertice arguments & a terminal' do
21
+ it 'is created with two vertice arguments & a terminal' do
21
22
  v1 = vertex1
22
23
  v2 = vertex2
23
- expect { ScanEdge.new(v1, v2, sample_terminal) }.not_to raise_error
24
+ expect { described_class.new(v1, v2, sample_terminal) }.not_to raise_error
24
25
  end
25
26
 
26
- it 'should know the related terminal' do
27
- expect(subject.terminal).to eq(sample_terminal)
27
+ it 'knows the related terminal' do
28
+ expect(an_edge.terminal).to eq(sample_terminal)
28
29
  end
29
30
  end # context
30
31
  end # describe
@@ -8,34 +8,34 @@ require_relative '../../../lib/rley/gfg/shortcut_edge'
8
8
 
9
9
  module Rley # Open this namespace to avoid module qualifier prefixes
10
10
  module GFG # Open this namespace to avoid module qualifier prefixes
11
- describe Edge do
12
- let(:nt_b_sequence) { Rley::Syntax::NonTerminal.new('b_sequence') }
11
+ describe ShortcutEdge do
12
+ subject(:an_edge) { described_class.new(vertex1, vertex2) }
13
13
 
14
+ let(:nt_b_sequence) { Rley::Syntax::NonTerminal.new('b_sequence') }
14
15
  let(:vertex1) { double('fake_vertex1') }
15
16
  let(:vertex2) { double('fake_vertex2') }
16
- subject { ShortcutEdge.new(vertex1, vertex2) }
17
17
 
18
18
  context 'Initialization:' do
19
- it 'should be created with two vertice arguments & a non-terminal' do
20
- expect(vertex1).to receive(:shortcut=)
21
- expect(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
19
+ it 'is created with two vertice arguments & a non-terminal' do
20
+ allow(vertex1).to receive(:shortcut=)
21
+ allow(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
22
22
 
23
- expect { ShortcutEdge.new(vertex1, vertex2) }
23
+ expect { described_class.new(vertex1, vertex2) }
24
24
  .not_to raise_error
25
25
  end
26
26
 
27
- it 'should know the successor vertex' do
28
- expect(vertex1).to receive(:shortcut=)
29
- expect(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
27
+ it 'knows the successor vertex' do
28
+ allow(vertex1).to receive(:shortcut=)
29
+ allow(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
30
30
 
31
- expect(subject.successor).to eq(vertex2)
31
+ expect(an_edge.successor).to eq(vertex2)
32
32
  end
33
33
 
34
- it 'should know the related terminal' do
35
- expect(vertex1).to receive(:shortcut=)
36
- expect(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
34
+ it 'knows the related terminal' do
35
+ allow(vertex1).to receive(:shortcut=)
36
+ allow(vertex1).to receive(:next_symbol).and_return(nt_b_sequence)
37
37
 
38
- expect(subject.nonterminal).to eq(nt_b_sequence)
38
+ expect(an_edge.nonterminal).to eq(nt_b_sequence)
39
39
  end
40
40
  end # context
41
41
  end # describe
@@ -9,24 +9,24 @@ require_relative '../../../lib/rley/gfg/start_vertex'
9
9
  module Rley # Open this namespace to avoid module qualifier prefixes
10
10
  module GFG # Open this namespace to avoid module qualifier prefixes
11
11
  describe StartVertex do
12
+ subject(:a_vertex) { described_class.new(sample_nt) }
12
13
  let(:sample_nt) { Syntax::NonTerminal.new('NT') }
13
- subject { StartVertex.new(sample_nt) }
14
14
 
15
15
  context 'Initialization:' do
16
- it 'should be created with a non-terminal symbol' do
17
- expect { StartVertex.new(sample_nt) }.not_to raise_error
16
+ it 'is created with a non-terminal symbol' do
17
+ expect { described_class.new(sample_nt) }.not_to raise_error
18
18
  end
19
19
 
20
- it 'should know its label' do
21
- expect(sample_nt).to receive(:to_s).and_return('NT')
22
- expect(subject.label).to eq('.NT')
20
+ it 'knows its label' do
21
+ allow(sample_nt).to receive(:to_s).and_return('NT')
22
+ expect(a_vertex.label).to eq('.NT')
23
23
  end
24
24
  end # context
25
25
 
26
26
  context 'Provided services:' do
27
- it 'should provide human-readable representation of itself' do
27
+ it 'provides human-readable representation of itself' do
28
28
  pattern = /^#<Rley::GFG::StartVertex:\d+ label="\.NT"/
29
- expect(subject.inspect).to match(pattern)
29
+ expect(a_vertex.inspect).to match(pattern)
30
30
  end
31
31
  end # context
32
32
  end # describe
@@ -8,44 +8,44 @@ require_relative '../../../lib/rley/gfg/vertex'
8
8
  module Rley # Open this namespace to avoid module qualifier prefixes
9
9
  module GFG # Open this namespace to avoid module qualifier prefixes
10
10
  describe Vertex do
11
- subject { Vertex.new }
11
+ subject(:a_vertex) { described_class.new }
12
12
 
13
13
  context 'Initialization:' do
14
- it 'should be created without argument' do
15
- expect { Vertex.new }.not_to raise_error
14
+ it 'is created without argument' do
15
+ expect { described_class.new }.not_to raise_error
16
16
  end
17
17
 
18
- it "shouldn't have edges at start" do
19
- expect(subject.edges.empty?).to eq(true)
18
+ it "doesn't have edges at start" do
19
+ expect(a_vertex.edges.empty?).to be(true)
20
20
  end
21
21
  end # context
22
22
 
23
23
  context 'Provided services:' do
24
- it 'should know whether it has a dot at the end of the rhs' do
25
- expect(subject).not_to be_complete
24
+ it 'knows whether it has a dot at the end of the rhs' do
25
+ expect(a_vertex).not_to be_complete
26
26
  end
27
27
 
28
- it 'should know the previous symbol (if any) in the rhs' do
29
- expect(subject.prev_symbol).to be_nil
28
+ it 'knows the previous symbol (if any) in the rhs' do
29
+ expect(a_vertex.prev_symbol).to be_nil
30
30
  end
31
31
 
32
- it 'should know the next symbol (if any) in the rhs' do
33
- expect(subject.next_symbol).to be_nil
32
+ it 'knows the next symbol (if any) in the rhs' do
33
+ expect(a_vertex.next_symbol).to be_nil
34
34
  end
35
35
 
36
- it 'should accept at most one new edge' do
36
+ it 'accepts at most one new edge' do
37
37
  edge1 = double('fake-edge1')
38
38
  edge2 = double('fake-edge2')
39
39
 
40
- expect { subject.add_edge(edge1) }.not_to raise_error
41
- expect(subject.edges.size).to eq(1)
42
- expect(subject.edges.last).to eq(edge1)
40
+ expect { a_vertex.add_edge(edge1) }.not_to raise_error
41
+ expect(a_vertex.edges.size).to eq(1)
42
+ expect(a_vertex.edges.last).to eq(edge1)
43
43
 
44
44
  err = StandardError
45
45
  msg = 'At most one edge accepted'
46
- expect { subject.add_edge(edge2) }.to raise_error err, msg
47
- expect(subject.edges.size).to eq(1)
48
- expect(subject.edges.last).to eq(edge1)
46
+ expect { a_vertex.add_edge(edge2) }.to raise_error err, msg
47
+ expect(a_vertex.edges.size).to eq(1)
48
+ expect(a_vertex.edges.last).to eq(edge1)
49
49
  end
50
50
  end # context
51
51
  end # describe