rley 0.8.14 → 0.8.15

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 (76) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +20 -2
  3. data/CHANGELOG.md +3 -0
  4. data/examples/general/calc_iter1/spec/calculator_spec.rb +9 -9
  5. data/examples/general/calc_iter2/spec/calculator_spec.rb +39 -39
  6. data/examples/general/recursive_right.rb +2 -2
  7. data/lib/rley/constants.rb +1 -1
  8. data/lib/rley/gfg/grm_flow_graph.rb +0 -1
  9. data/lib/rley/parser/parse_entry_set.rb +0 -1
  10. data/lib/rley/parser/parse_walker_factory.rb +0 -1
  11. data/lib/rley/rgn/grammar_builder.rb +0 -2
  12. data/lib/rley/rgn/tokenizer.rb +1 -1
  13. data/lib/rley/syntax/base_grammar_builder.rb +0 -1
  14. data/lib/rley/syntax/grammar.rb +0 -1
  15. data/spec/rley/base/dotted_item_spec.rb +46 -46
  16. data/spec/rley/base/grm_items_builder_spec.rb +1 -1
  17. data/spec/rley/engine_spec.rb +50 -50
  18. data/spec/rley/formatter/asciitree_spec.rb +8 -8
  19. data/spec/rley/formatter/bracket_notation_spec.rb +10 -10
  20. data/spec/rley/formatter/debug_spec.rb +10 -10
  21. data/spec/rley/formatter/json_spec.rb +6 -7
  22. data/spec/rley/gfg/call_edge_spec.rb +6 -6
  23. data/spec/rley/gfg/edge_spec.rb +8 -7
  24. data/spec/rley/gfg/end_vertex_spec.rb +8 -7
  25. data/spec/rley/gfg/epsilon_edge_spec.rb +5 -4
  26. data/spec/rley/gfg/grm_flow_graph_spec.rb +33 -34
  27. data/spec/rley/gfg/item_vertex_spec.rb +34 -36
  28. data/spec/rley/gfg/non_terminal_vertex_spec.rb +12 -12
  29. data/spec/rley/gfg/return_edge_spec.rb +6 -6
  30. data/spec/rley/gfg/scan_edge_spec.rb +7 -6
  31. data/spec/rley/gfg/shortcut_edge_spec.rb +15 -15
  32. data/spec/rley/gfg/start_vertex_spec.rb +8 -8
  33. data/spec/rley/gfg/vertex_spec.rb +18 -18
  34. data/spec/rley/lexical/literal_spec.rb +5 -5
  35. data/spec/rley/lexical/token_range_spec.rb +55 -55
  36. data/spec/rley/lexical/token_spec.rb +17 -16
  37. data/spec/rley/parse_forest_visitor_spec.rb +30 -32
  38. data/spec/rley/parse_rep/ambiguous_parse_spec.rb +2 -2
  39. data/spec/rley/parse_rep/ast_builder_spec.rb +30 -30
  40. data/spec/rley/parse_rep/cst_builder_spec.rb +85 -85
  41. data/spec/rley/parse_rep/groucho_spec.rb +23 -23
  42. data/spec/rley/parse_rep/parse_forest_builder_spec.rb +42 -42
  43. data/spec/rley/parse_rep/parse_forest_factory_spec.rb +10 -12
  44. data/spec/rley/parse_rep/parse_tree_factory_spec.rb +10 -15
  45. data/spec/rley/parse_tree_visitor_spec.rb +43 -46
  46. data/spec/rley/parser/dangling_else_spec.rb +12 -12
  47. data/spec/rley/parser/error_reason_spec.rb +37 -37
  48. data/spec/rley/parser/gfg_chart_spec.rb +27 -29
  49. data/spec/rley/parser/gfg_earley_parser_spec.rb +55 -56
  50. data/spec/rley/parser/gfg_parsing_spec.rb +106 -103
  51. data/spec/rley/parser/parse_entry_set_spec.rb +63 -61
  52. data/spec/rley/parser/parse_entry_spec.rb +73 -71
  53. data/spec/rley/parser/parse_walker_factory_spec.rb +14 -15
  54. data/spec/rley/ptree/non_terminal_node_spec.rb +16 -16
  55. data/spec/rley/ptree/parse_tree_node_spec.rb +11 -11
  56. data/spec/rley/ptree/parse_tree_spec.rb +6 -8
  57. data/spec/rley/ptree/terminal_node_spec.rb +6 -6
  58. data/spec/rley/rgn/grammar_builder_spec.rb +69 -67
  59. data/spec/rley/rgn/parser_spec.rb +63 -63
  60. data/spec/rley/rgn/repetition_node_spec.rb +15 -15
  61. data/spec/rley/rgn/sequence_node_spec.rb +10 -10
  62. data/spec/rley/rgn/symbol_node_spec.rb +5 -6
  63. data/spec/rley/rgn/tokenizer_spec.rb +68 -67
  64. data/spec/rley/sppf/alternative_node_spec.rb +16 -16
  65. data/spec/rley/sppf/non_terminal_node_spec.rb +20 -20
  66. data/spec/rley/sppf/token_node_spec.rb +13 -13
  67. data/spec/rley/syntax/base_grammar_builder_spec.rb +76 -86
  68. data/spec/rley/syntax/grammar_spec.rb +40 -78
  69. data/spec/rley/syntax/grm_symbol_spec.rb +7 -7
  70. data/spec/rley/syntax/match_closest_spec.rb +8 -8
  71. data/spec/rley/syntax/non_terminal_spec.rb +25 -25
  72. data/spec/rley/syntax/production_spec.rb +33 -33
  73. data/spec/rley/syntax/symbol_seq_spec.rb +27 -27
  74. data/spec/rley/syntax/terminal_spec.rb +12 -11
  75. data/spec/support/base_tokenizer_spec.rb +9 -8
  76. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cf803f55dde48af888bfb7e0be524e66b8d2357aa85ae6292cf8c70d7a521273
4
- data.tar.gz: f9cf09dffb9939c03b2c301c4669600d6d8f3bcefac20313fd54406456ed800a
3
+ metadata.gz: 7e2ff00bd9b05a972b081dbcde3e9b6ff36f639fc9a9b2ae3bd22a494dd991d8
4
+ data.tar.gz: 17cc2cd1544312b3781a9015de83df250519f9dc39353d172cdcfa70597af181
5
5
  SHA512:
6
- metadata.gz: fa9e22773d7679b615d9119be340aac8ad91890dab9e1fe79c240883cb8059bed11dc48be011649ba068db7c62de23d25f3637acd2c3112b92f057e8319bae9e
7
- data.tar.gz: 892e9fdb184f4ab33de790fe998504b8ab9fbacdcd19f1ce389ca39cdddc4c28634742cef281036a67a4e8cdb1b7d301df15a6846386f279eb971def3d083820
6
+ metadata.gz: 2f90be1939b2698dfb830b765e2857693b55b3626c610c220d2abb8beecf0e67e23c02ebb65da3dd57fbcb6e08e5170ac0847d8677b370bcdd9b119c3f59346a
7
+ data.tar.gz: 7c689384cc04ec1dd61b098a2280b8814611ba220ef7f745f55872b2e03ecdd7bc6f62de527a47a04e432ead8346a411c49995a429a5677320217abe7a30d1e4
data/.rubocop.yml CHANGED
@@ -438,6 +438,9 @@ Lint/TopLevelReturnWithArgument:
438
438
  Lint/UnreachableLoop:
439
439
  Enabled: true
440
440
 
441
+ Naming/BlockForwarding:
442
+ EnforcedStyle: explicit
443
+
441
444
  Style/AccessorGrouping:
442
445
  Enabled: true
443
446
 
@@ -505,7 +508,22 @@ Style/StringConcatenation:
505
508
  # Enabled: false
506
509
  #
507
510
  #RSpec/ExampleLength:
508
- # Max: 50
511
+ # Max: 350
512
+ #
513
+ #RSpec/IndexedLet:
514
+ # Enabled: false
515
+ #
516
+ #RSpec/MultipleDescribes:
517
+ # Enabled: false
509
518
  #
510
519
  #RSpec/MultipleExpectations:
511
- # Max: 15
520
+ # Max: 55
521
+ #
522
+ #RSpec/MultipleMemoizedHelpers:
523
+ # Max: 30
524
+ #
525
+ #RSpec/NoExpectationExample:
526
+ # Enabled: false
527
+ #
528
+ #RSpec/VerifiedDoubles:
529
+ # Enabled: false
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ### 0.8.15 / 2025-02-28
2
+ - [FIX] Re-styled spec files
3
+
1
4
  ### 0.8.14 / 2025-02-26
2
5
  - [FIX] Re-styled spec files of tutorial/iter4 folder
3
6
 
@@ -33,39 +33,39 @@ describe 'Calculator' do
33
33
  return result
34
34
  end
35
35
 
36
- it 'should evaluate simple number literals' do
36
+ it 'evaluates simple number literals' do
37
37
  expect_expr('2').to eq(2)
38
38
  end
39
39
 
40
- it 'should evaluate addition' do
40
+ it 'evaluates addition' do
41
41
  expect_expr('2 + 2').to eq(4)
42
42
  end
43
43
 
44
- it 'should evaluate subtraction' do
44
+ it 'evaluates subtraction' do
45
45
  expect_expr('2.1 - 2').to be_within(0.000000000000001).of(0.1)
46
46
  end
47
47
 
48
- it 'should evaluate division' do
48
+ it 'evaluates division' do
49
49
  expect_expr('10.5 / 5').to eq(2.1)
50
50
  end
51
51
 
52
- it 'should evaluate multiplication' do
52
+ it 'evaluates multiplication' do
53
53
  expect_expr('2 * 3.1').to eq(6.2)
54
54
  end
55
55
 
56
- it 'should evaluate parentheses' do
56
+ it 'evaluates parentheses' do
57
57
  expect_expr('2 * (2.1 + 1)').to eq(6.2)
58
58
  end
59
59
 
60
- it 'should evaluate regardless of whitespace' do
60
+ it 'evaluates regardless of whitespace' do
61
61
  expect_expr("2*(1+\t1)").to eq(4)
62
62
  end
63
63
 
64
- it 'should evaluate order of operations' do
64
+ it 'evaluates order of operations' do
65
65
  expect_expr('2 * 2.1 + 1 / 2').to eq 4.7
66
66
  end
67
67
 
68
- it 'should evaluate multiple levels of parentheses' do
68
+ it 'evaluates multiple levels of parentheses' do
69
69
  expect_expr('2*(1/(1+3))').to eq(0.5)
70
70
  end
71
71
  end # describe
@@ -41,152 +41,152 @@ describe 'Calculator' do
41
41
  context 'Parsing valid expressions' do
42
42
  let(:epsilon) { 0.0000000001 }
43
43
 
44
- it 'should evaluate simple integer literals' do
44
+ it 'evaluates simple integer literals' do
45
45
  expect_expr('2').to eq(2)
46
46
  end
47
47
 
48
- it 'should evaluate simple floating-point literals' do
48
+ it 'evaluates simple floating-point literals' do
49
49
  expect_expr('3.1').to eq(3.1)
50
50
  end
51
51
 
52
- it 'should evaluate positive integer literals' do
52
+ it 'evaluates positive integer literals' do
53
53
  expect_expr('+2').to eq(2)
54
54
  expect_expr('+ 2').to eq(2)
55
55
  end
56
56
 
57
- it 'should evaluate positive floating-point literals' do
57
+ it 'evaluates positive floating-point literals' do
58
58
  expect_expr('+3.1').to eq(3.1)
59
59
  expect_expr('+ 3.1').to eq(3.1)
60
60
  end
61
61
 
62
- it 'should evaluate negative integer literals' do
62
+ it 'evaluates negative integer literals' do
63
63
  expect_expr('-2').to eq(-2)
64
64
  expect_expr('- 2').to eq(-2)
65
65
  end
66
66
 
67
- it 'should evaluate negative floating-point literals' do
67
+ it 'evaluates negative floating-point literals' do
68
68
  expect_expr('-3.1').to eq(-3.1)
69
69
  expect_expr('- 3.1').to eq(-3.1)
70
70
  end
71
71
 
72
- it 'should evaluate the pi constant' do
72
+ it 'evaluates the pi constant' do
73
73
  expect_expr('PI').to eq(3.141592653589793)
74
74
  end
75
75
 
76
- it 'should evaluate the negated pi constant' do
76
+ it 'evaluates the negated pi constant' do
77
77
  expect_expr('-PI').to eq(-3.141592653589793)
78
78
  end
79
79
 
80
- it "should evaluate Neper's e constant" do
80
+ it "evaluates Neper's e constant" do
81
81
  expect_expr('E').to eq(2.718281828459045)
82
82
  end
83
83
 
84
- it "should evaluate negated Neper's e constant" do
84
+ it "evaluates negated Neper's e constant" do
85
85
  expect_expr('-E').to eq(-2.718281828459045)
86
86
  end
87
87
 
88
- it 'should evaluate integer addition' do
88
+ it 'evaluates integer addition' do
89
89
  expect_expr('2 + 2').to eq(4)
90
90
  end
91
91
 
92
- it 'should evaluate floating-point addition' do
92
+ it 'evaluates floating-point addition' do
93
93
  expect_expr('2.0 + 3.1').to eq(5.1)
94
94
  end
95
95
 
96
- it 'should evaluate integer subtraction' do
96
+ it 'evaluates integer subtraction' do
97
97
  expect_expr('2 - 3').to eq(-1)
98
98
  end
99
99
 
100
- it 'should evaluate floating-point subtraction' do
100
+ it 'evaluates floating-point subtraction' do
101
101
  expect_expr('3.1 - 2').to eq(1.1)
102
102
  end
103
103
 
104
- it 'should handle negation of negative numbers' do
104
+ it 'handles negation of negative numbers' do
105
105
  expect_expr('3--2').to eq(5)
106
106
  end
107
107
 
108
- it 'should evaluate integer multiplication' do
108
+ it 'evaluates integer multiplication' do
109
109
  expect_expr('2 * 3').to eq(6)
110
110
  end
111
111
 
112
- it 'should evaluate floating-point multiplication' do
112
+ it 'evaluates floating-point multiplication' do
113
113
  expect_expr('2 * 3.1').to eq(6.2)
114
114
  end
115
115
 
116
- it 'should evaluate division of integers' do
116
+ it 'evaluates division of integers' do
117
117
  expect_expr('5 / 2').to eq(2.5)
118
118
  end
119
119
 
120
- it 'should evaluate floating-point division' do
120
+ it 'evaluates floating-point division' do
121
121
  expect_expr('10.5 / 5').to eq(2.1)
122
122
  end
123
123
 
124
- it 'should evaluate integer exponent' do
124
+ it 'evaluates integer exponent' do
125
125
  expect_expr('5 ** (3 - 1)').to eq(25)
126
126
  end
127
127
 
128
- it 'should evaluate floating-point exponent' do
128
+ it 'evaluates floating-point exponent' do
129
129
  expect_expr('25 ** 0.5').to eq(5)
130
130
  end
131
131
 
132
- it 'should evaluate negative exponent' do
132
+ it 'evaluates negative exponent' do
133
133
  expect_expr('5 ** -2').to eq(0.04)
134
134
  end
135
135
 
136
- it 'should handle nested exponentiations' do
136
+ it 'handles nested exponentiations' do
137
137
  expect_expr('2 ** 2**2').to eq(16)
138
138
  end
139
139
 
140
- it 'should change sign of expression in parentheses' do
140
+ it 'changes sign of expression in parentheses' do
141
141
  expect_expr('- (2 * 5)').to eq(-10)
142
142
  end
143
143
 
144
- it 'should evaluate parentheses' do
144
+ it 'evaluates parentheses' do
145
145
  expect_expr('2 * (2.1 + 1)').to eq(6.2)
146
146
  end
147
147
 
148
- it 'should evaluate regardless of whitespace' do
148
+ it 'evaluates regardless of whitespace' do
149
149
  expect_expr("2*(1+\t1)").to eq(4)
150
150
  end
151
151
 
152
- it 'should evaluate order of operations' do
152
+ it 'evaluates order of operations' do
153
153
  expect_expr('2 * 2.1 + 1 / 2').to eq 4.7
154
154
  end
155
155
 
156
- it 'should evaluate multiple levels of parentheses' do
156
+ it 'evaluates multiple levels of parentheses' do
157
157
  expect_expr('2*(1/(1+3))').to eq(0.5)
158
158
  end
159
159
 
160
160
  # Some special functions
161
- it 'should evaluate square root of expressions' do
161
+ it 'evaluates square root of expressions' do
162
162
  expect_expr('sqrt(0)').to eq(0)
163
163
  expect_expr('sqrt(1)').to eq(1)
164
164
  expect_expr('sqrt(1 + 1)').to eq(Math.sqrt(2))
165
165
  expect_expr('sqrt(5 * 5)').to eq(5)
166
166
  end
167
167
 
168
- it 'should evaluate cubic root of expressions' do
168
+ it 'evaluates cubic root of expressions' do
169
169
  expect_expr('cbrt(0)').to eq(0)
170
170
  expect_expr('cbrt(1)').to eq(1)
171
171
  expect_expr('cbrt(1 + 1)').to eq(Math.cbrt(2))
172
172
  expect_expr('cbrt(5 * 5 * 5)').to eq(5)
173
173
  end
174
174
 
175
- it 'should evaluate exponential of expressions' do
175
+ it 'evaluates exponential of expressions' do
176
176
  expect_expr('exp(-1)').to eq(1 / Math::E)
177
177
  expect_expr('exp(0)').to eq(1)
178
178
  expect_expr('exp(1)').to eq(Math::E)
179
179
  expect_expr('exp(2)').to be_within(epsilon).of(Math::E * Math::E)
180
180
  end
181
181
 
182
- it 'should evaluate natural logarithm of expressions' do
182
+ it 'evaluates natural logarithm of expressions' do
183
183
  expect_expr('ln(1/E)').to eq(-1)
184
184
  expect_expr('ln(1)').to eq(0)
185
185
  expect_expr('ln(E)').to eq(1)
186
186
  expect_expr('ln(E * E)').to eq(2)
187
187
  end
188
188
 
189
- it 'should evaluate the logarithm base 10 of expressions' do
189
+ it 'evaluates the logarithm base 10 of expressions' do
190
190
  expect_expr('log(1/10)').to eq(-1)
191
191
  expect_expr('log(1)').to eq(0)
192
192
  expect_expr('log(10)').to eq(1)
@@ -195,19 +195,19 @@ describe 'Calculator' do
195
195
 
196
196
  # Trigonometric functions
197
197
 
198
- it 'should compute the sinus of an expression' do
198
+ it 'computes the sinus of an expression' do
199
199
  expect_expr('sin(0)').to eq(0)
200
200
  expect_expr('sin(PI/6)').to be_within(epsilon).of(0.5)
201
201
  expect_expr('sin(PI/2)').to eq(1)
202
202
  end
203
203
 
204
- it 'should compute the cosinus of an expression' do
204
+ it 'computes the cosinus of an expression' do
205
205
  expect_expr('cos(0)').to eq(1)
206
206
  expect_expr('cos(PI/3)').to be_within(epsilon).of(0.5)
207
207
  expect_expr('cos(PI/2)').to be_within(epsilon).of(0)
208
208
  end
209
209
 
210
- it 'should compute the tangent of an expression' do
210
+ it 'computes the tangent of an expression' do
211
211
  expect_expr('tan(0)').to eq(0)
212
212
  expect_expr('tan(PI/4)').to be_within(epsilon).of(1)
213
213
  expect_expr('tan(5*PI/12)').to be_within(epsilon).of(2 + Math.sqrt(3))
@@ -215,19 +215,19 @@ describe 'Calculator' do
215
215
 
216
216
  # Inverse trigonometric functions
217
217
 
218
- it 'should compute the arcsinus of an expression' do
218
+ it 'computes the arcsinus of an expression' do
219
219
  expect_expr('asin(0)').to eq(0)
220
220
  expect_expr('asin(0.5)').to be_within(epsilon).of(Math::PI / 6)
221
221
  expect_expr('asin(1)').to eq(Math::PI / 2)
222
222
  end
223
223
 
224
- it 'should compute the arccosinus of an expression' do
224
+ it 'computes the arccosinus of an expression' do
225
225
  expect_expr('acos(1)').to eq(0)
226
226
  expect_expr('acos(0.5)').to be_within(epsilon).of(Math::PI / 3)
227
227
  expect_expr('acos(0)').to be_within(epsilon).of(Math::PI / 2)
228
228
  end
229
229
 
230
- it 'should compute the tangent of an expression' do
230
+ it 'computes the arctangent of an expression' do
231
231
  expect_expr('atan(0)').to eq(0)
232
232
  pi = Math::PI
233
233
  expect_expr('atan(1)').to be_within(epsilon).of(pi / 4)
@@ -143,7 +143,7 @@ find every scan edge
143
143
  def build_gfg(aGrammar)
144
144
  items_builder = Object.new.extend(Rley::Base::GrmItemsBuilder)
145
145
  items = items_builder.build_dotted_items(aGrammar)
146
- gfg = Rley::GFG::GrmFlowGraph.new(items)
146
+ Rley::GFG::GrmFlowGraph.new(items)
147
147
  end
148
148
 
149
149
  graph = build_gfg(right_recursive_grammar)
@@ -326,7 +326,7 @@ module GraphMixin
326
326
 
327
327
  # visit_action takes two arguments: a vertex and an edge
328
328
  # return true/false if false stop traversal
329
- def df_traversal(aVertex, &visit_action)
329
+ def df_traversal(aVertex, &_visit_action)
330
330
  visit = [aVertex]
331
331
  vtx2count = { aVertex => 0 }
332
332
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  module Rley # Module used as a namespace
7
7
  # The version number of the gem.
8
- Version = '0.8.14'
8
+ Version = '0.8.15'
9
9
 
10
10
  # Brief description of the gem.
11
11
  Description = "Ruby implementation of the Earley's parsing algorithm"
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
4
3
  require_relative 'start_vertex'
5
4
  require_relative 'end_vertex'
6
5
  require_relative 'item_vertex'
@@ -1,7 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable' # For the Delegation pattern
4
- require 'set'
5
4
 
6
5
  require_relative '../syntax/terminal'
7
6
  require_relative '../syntax/non_terminal'
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
4
3
  require_relative '../gfg/call_edge'
5
4
  require_relative '../gfg/scan_edge'
6
5
  require_relative '../gfg/epsilon_edge'
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
4
-
5
3
  require_relative 'parser'
6
4
  require_relative 'ast_visitor'
7
5
  require_relative '../syntax/match_closest'
@@ -41,7 +41,7 @@ module Rley
41
41
  '?' => 'QUESTION_MARK',
42
42
  '*' => 'STAR',
43
43
  '..' => 'ELLIPSIS'
44
- }
44
+ }.freeze
45
45
 
46
46
  # Here are all the implemented Rley notation keywords
47
47
  @@keywords = %w[
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
4
3
  require_relative 'terminal'
5
4
  require_relative 'non_terminal'
6
5
  require_relative 'production'
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'set'
4
3
  require_relative '../rley_error'
5
4
 
6
5
  module Rley # This module is used as a namespace
@@ -27,126 +27,126 @@ module Rley # Open this namespace to avoid module qualifier prefixes
27
27
  let(:empty_prod) { build_prod(nt_sentence) }
28
28
 
29
29
  # Default instantiation rule
30
- subject { DottedItem.new(sample_prod, 1) }
30
+ subject(:an_item) { described_class.new(sample_prod, 1) }
31
31
 
32
32
  context 'Initialization:' do
33
- it 'should be created with a production and an index' do
34
- expect { DottedItem.new(sample_prod, 0) }.not_to raise_error
35
- expect { DottedItem.new(sample_prod, 3) }.not_to raise_error
33
+ it 'is created with a production and an index' do
34
+ expect { described_class.new(sample_prod, 0) }.not_to raise_error
35
+ expect { described_class.new(sample_prod, 3) }.not_to raise_error
36
36
  end
37
37
 
38
- it 'should complain when the index is out-of-bounds' do
38
+ it 'complains when the index is out-of-bounds' do
39
39
  err = StandardError
40
40
  msg = 'Out of bound index'
41
- expect { DottedItem.new(sample_prod, 4) }.to raise_error(err, msg)
41
+ expect { described_class.new(sample_prod, 4) }.to raise_error(err, msg)
42
42
  end
43
43
 
44
- it 'should know its production' do
45
- expect(subject.production).to eq(sample_prod)
44
+ it 'knows its production' do
45
+ expect(an_item.production).to eq(sample_prod)
46
46
  end
47
47
 
48
- it 'should know the lhs of the production' do
49
- expect(subject.lhs).to eq(sample_prod.lhs)
48
+ it 'knows the lhs of the production' do
49
+ expect(an_item.lhs).to eq(sample_prod.lhs)
50
50
  end
51
51
 
52
- it 'should know its position' do
52
+ it 'knows its position' do
53
53
  # At start position
54
- instance1 = DottedItem.new(sample_prod, 0)
54
+ instance1 = described_class.new(sample_prod, 0)
55
55
  expect(instance1.position).to eq(0)
56
56
 
57
57
  # At (before) last symbol
58
- instance2 = DottedItem.new(sample_prod, 2)
58
+ instance2 = described_class.new(sample_prod, 2)
59
59
  expect(instance2.position).to eq(2)
60
60
 
61
61
  # After all symbols in rhs
62
- instance3 = DottedItem.new(sample_prod, 3)
62
+ instance3 = described_class.new(sample_prod, 3)
63
63
  expect(instance3.position).to eq(-1)
64
64
 
65
65
  # At start/end at the same time (production is empty)
66
- instance4 = DottedItem.new(build_prod(nt_sentence), 0)
66
+ instance4 = described_class.new(build_prod(nt_sentence), 0)
67
67
  expect(instance4.position).to eq(-2)
68
68
  end
69
69
  end # context
70
70
 
71
71
  context 'Provided service:' do
72
- it 'should whether its dot is at start position' do
73
- expect(subject).not_to be_at_start
72
+ it 'knows whether its dot is at start position' do
73
+ expect(an_item).not_to be_at_start
74
74
 
75
75
  # At start position
76
- instance1 = DottedItem.new(sample_prod, 0)
76
+ instance1 = described_class.new(sample_prod, 0)
77
77
  expect(instance1).to be_at_start
78
78
 
79
79
  # At start/end at the same time (production is empty)
80
- instance2 = DottedItem.new(build_prod(nt_sentence), 0)
80
+ instance2 = described_class.new(build_prod(nt_sentence), 0)
81
81
  expect(instance2).to be_at_start
82
82
  end
83
83
 
84
- it 'should whether it is a reduce item' do
85
- expect(subject).not_to be_reduce_item
84
+ it 'knows whether it is a reduce item' do
85
+ expect(an_item).not_to be_reduce_item
86
86
 
87
- first_instance = DottedItem.new(sample_prod, 3)
87
+ first_instance = described_class.new(sample_prod, 3)
88
88
  expect(first_instance).to be_reduce_item
89
89
 
90
- second_instance = DottedItem.new(empty_prod, 0)
90
+ second_instance = described_class.new(empty_prod, 0)
91
91
  expect(second_instance).to be_reduce_item
92
92
  end
93
93
 
94
- it 'should know the symbol before the dot' do
95
- expect(subject.prev_symbol).to eq(t_a)
94
+ it 'knows the symbol before the dot' do
95
+ expect(an_item.prev_symbol).to eq(t_a)
96
96
 
97
97
  # Case of an empty production
98
- instance = DottedItem.new(empty_prod, 0)
98
+ instance = described_class.new(empty_prod, 0)
99
99
  expect(instance.prev_symbol).to be_nil
100
100
 
101
101
  # Case of a dot at start position
102
- instance = DottedItem.new(sample_prod, 0)
102
+ instance = described_class.new(sample_prod, 0)
103
103
  expect(instance.prev_symbol).to be_nil
104
104
  end
105
105
 
106
- it 'should know the symbol after the dot' do
107
- expect(subject.next_symbol).to eq(t_b)
106
+ it 'knows the symbol after the dot' do
107
+ expect(an_item.next_symbol).to eq(t_b)
108
108
  end
109
109
 
110
- it 'should calculate the previous position of the dot' do
111
- expect(subject.prev_position).to eq(0)
110
+ it 'calculates the previous position of the dot' do
111
+ expect(an_item.prev_position).to eq(0)
112
112
 
113
113
  # Case of an empty production
114
- instance = DottedItem.new(empty_prod, 0)
114
+ instance = described_class.new(empty_prod, 0)
115
115
  expect(instance.prev_position).to be_nil
116
116
 
117
117
  # Case of a dot at start position
118
- instance = DottedItem.new(sample_prod, 0)
118
+ instance = described_class.new(sample_prod, 0)
119
119
  expect(instance.prev_position).to be_nil
120
120
 
121
121
  # Case of single symbol production
122
- instance = DottedItem.new(other_prod, 1)
122
+ instance = described_class.new(other_prod, 1)
123
123
  expect(instance.prev_position).to eq(0)
124
124
  end
125
125
 
126
- it 'should determine if it is a successor of another dotted item' do
127
- expect(subject).not_to be_successor_of(subject)
126
+ it 'determines if it is a successor of another dotted item' do
127
+ expect(an_item).not_to be_successor_of(an_item)
128
128
 
129
129
  # Case: different productions
130
- instance = DottedItem.new(empty_prod, 0)
131
- expect(subject).not_to be_successor_of(instance)
130
+ instance = described_class.new(empty_prod, 0)
131
+ expect(an_item).not_to be_successor_of(instance)
132
132
 
133
133
  # Case: one position difference
134
- instance = DottedItem.new(sample_prod, 0)
135
- expect(subject).to be_successor_of(instance)
136
- expect(instance).not_to be_successor_of(subject)
134
+ instance = described_class.new(sample_prod, 0)
135
+ expect(an_item).to be_successor_of(instance)
136
+ expect(instance).not_to be_successor_of(an_item)
137
137
 
138
138
  # Case: more than one position difference
139
- instance2 = DottedItem.new(sample_prod, 2)
139
+ instance2 = described_class.new(sample_prod, 2)
140
140
  expect(instance).not_to be_successor_of(instance2)
141
- expect(subject).not_to be_successor_of(instance2)
142
- expect(instance2).to be_successor_of(subject)
141
+ expect(an_item).not_to be_successor_of(instance2)
142
+ expect(instance2).to be_successor_of(an_item)
143
143
  end
144
144
 
145
145
 
146
146
 
147
- it 'should give its text representation' do
147
+ it 'gives its text representation' do
148
148
  expectation = 'sentence => A . B C'
149
- expect(subject.to_s).to eq(expectation)
149
+ expect(an_item.to_s).to eq(expectation)
150
150
  end
151
151
  end
152
152
  end # describe
@@ -21,7 +21,7 @@ module Rley # Open this namespace to avoid module qualifier prefixes
21
21
  end
22
22
 
23
23
  context 'Builder pattern behaviour' do
24
- it 'should create dotted items for a grammar' do
24
+ it 'creates dotted items for a grammar' do
25
25
  # Next line calls method from mixin module under test
26
26
  items = build_dotted_items(grammar_abc)
27
27
  expect(items.size).to eq(8)