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.
- checksums.yaml +4 -4
- data/.rubocop.yml +20 -2
- data/CHANGELOG.md +3 -0
- data/examples/general/calc_iter1/spec/calculator_spec.rb +9 -9
- data/examples/general/calc_iter2/spec/calculator_spec.rb +39 -39
- data/examples/general/recursive_right.rb +2 -2
- data/lib/rley/constants.rb +1 -1
- data/lib/rley/gfg/grm_flow_graph.rb +0 -1
- data/lib/rley/parser/parse_entry_set.rb +0 -1
- data/lib/rley/parser/parse_walker_factory.rb +0 -1
- data/lib/rley/rgn/grammar_builder.rb +0 -2
- data/lib/rley/rgn/tokenizer.rb +1 -1
- data/lib/rley/syntax/base_grammar_builder.rb +0 -1
- data/lib/rley/syntax/grammar.rb +0 -1
- data/spec/rley/base/dotted_item_spec.rb +46 -46
- data/spec/rley/base/grm_items_builder_spec.rb +1 -1
- data/spec/rley/engine_spec.rb +50 -50
- data/spec/rley/formatter/asciitree_spec.rb +8 -8
- data/spec/rley/formatter/bracket_notation_spec.rb +10 -10
- data/spec/rley/formatter/debug_spec.rb +10 -10
- data/spec/rley/formatter/json_spec.rb +6 -7
- data/spec/rley/gfg/call_edge_spec.rb +6 -6
- data/spec/rley/gfg/edge_spec.rb +8 -7
- data/spec/rley/gfg/end_vertex_spec.rb +8 -7
- data/spec/rley/gfg/epsilon_edge_spec.rb +5 -4
- data/spec/rley/gfg/grm_flow_graph_spec.rb +33 -34
- data/spec/rley/gfg/item_vertex_spec.rb +34 -36
- data/spec/rley/gfg/non_terminal_vertex_spec.rb +12 -12
- data/spec/rley/gfg/return_edge_spec.rb +6 -6
- data/spec/rley/gfg/scan_edge_spec.rb +7 -6
- data/spec/rley/gfg/shortcut_edge_spec.rb +15 -15
- data/spec/rley/gfg/start_vertex_spec.rb +8 -8
- data/spec/rley/gfg/vertex_spec.rb +18 -18
- data/spec/rley/lexical/literal_spec.rb +5 -5
- data/spec/rley/lexical/token_range_spec.rb +55 -55
- data/spec/rley/lexical/token_spec.rb +17 -16
- data/spec/rley/parse_forest_visitor_spec.rb +30 -32
- data/spec/rley/parse_rep/ambiguous_parse_spec.rb +2 -2
- data/spec/rley/parse_rep/ast_builder_spec.rb +30 -30
- data/spec/rley/parse_rep/cst_builder_spec.rb +85 -85
- data/spec/rley/parse_rep/groucho_spec.rb +23 -23
- data/spec/rley/parse_rep/parse_forest_builder_spec.rb +42 -42
- data/spec/rley/parse_rep/parse_forest_factory_spec.rb +10 -12
- data/spec/rley/parse_rep/parse_tree_factory_spec.rb +10 -15
- data/spec/rley/parse_tree_visitor_spec.rb +43 -46
- data/spec/rley/parser/dangling_else_spec.rb +12 -12
- data/spec/rley/parser/error_reason_spec.rb +37 -37
- data/spec/rley/parser/gfg_chart_spec.rb +27 -29
- data/spec/rley/parser/gfg_earley_parser_spec.rb +55 -56
- data/spec/rley/parser/gfg_parsing_spec.rb +106 -103
- data/spec/rley/parser/parse_entry_set_spec.rb +63 -61
- data/spec/rley/parser/parse_entry_spec.rb +73 -71
- data/spec/rley/parser/parse_walker_factory_spec.rb +14 -15
- data/spec/rley/ptree/non_terminal_node_spec.rb +16 -16
- data/spec/rley/ptree/parse_tree_node_spec.rb +11 -11
- data/spec/rley/ptree/parse_tree_spec.rb +6 -8
- data/spec/rley/ptree/terminal_node_spec.rb +6 -6
- data/spec/rley/rgn/grammar_builder_spec.rb +69 -67
- data/spec/rley/rgn/parser_spec.rb +63 -63
- data/spec/rley/rgn/repetition_node_spec.rb +15 -15
- data/spec/rley/rgn/sequence_node_spec.rb +10 -10
- data/spec/rley/rgn/symbol_node_spec.rb +5 -6
- data/spec/rley/rgn/tokenizer_spec.rb +68 -67
- data/spec/rley/sppf/alternative_node_spec.rb +16 -16
- data/spec/rley/sppf/non_terminal_node_spec.rb +20 -20
- data/spec/rley/sppf/token_node_spec.rb +13 -13
- data/spec/rley/syntax/base_grammar_builder_spec.rb +76 -86
- data/spec/rley/syntax/grammar_spec.rb +40 -78
- data/spec/rley/syntax/grm_symbol_spec.rb +7 -7
- data/spec/rley/syntax/match_closest_spec.rb +8 -8
- data/spec/rley/syntax/non_terminal_spec.rb +25 -25
- data/spec/rley/syntax/production_spec.rb +33 -33
- data/spec/rley/syntax/symbol_seq_spec.rb +27 -27
- data/spec/rley/syntax/terminal_spec.rb +12 -11
- data/spec/support/base_tokenizer_spec.rb +9 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e2ff00bd9b05a972b081dbcde3e9b6ff36f639fc9a9b2ae3bd22a494dd991d8
|
4
|
+
data.tar.gz: 17cc2cd1544312b3781a9015de83df250519f9dc39353d172cdcfa70597af181
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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:
|
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:
|
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
@@ -33,39 +33,39 @@ describe 'Calculator' do
|
|
33
33
|
return result
|
34
34
|
end
|
35
35
|
|
36
|
-
it '
|
36
|
+
it 'evaluates simple number literals' do
|
37
37
|
expect_expr('2').to eq(2)
|
38
38
|
end
|
39
39
|
|
40
|
-
it '
|
40
|
+
it 'evaluates addition' do
|
41
41
|
expect_expr('2 + 2').to eq(4)
|
42
42
|
end
|
43
43
|
|
44
|
-
it '
|
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 '
|
48
|
+
it 'evaluates division' do
|
49
49
|
expect_expr('10.5 / 5').to eq(2.1)
|
50
50
|
end
|
51
51
|
|
52
|
-
it '
|
52
|
+
it 'evaluates multiplication' do
|
53
53
|
expect_expr('2 * 3.1').to eq(6.2)
|
54
54
|
end
|
55
55
|
|
56
|
-
it '
|
56
|
+
it 'evaluates parentheses' do
|
57
57
|
expect_expr('2 * (2.1 + 1)').to eq(6.2)
|
58
58
|
end
|
59
59
|
|
60
|
-
it '
|
60
|
+
it 'evaluates regardless of whitespace' do
|
61
61
|
expect_expr("2*(1+\t1)").to eq(4)
|
62
62
|
end
|
63
63
|
|
64
|
-
it '
|
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 '
|
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 '
|
44
|
+
it 'evaluates simple integer literals' do
|
45
45
|
expect_expr('2').to eq(2)
|
46
46
|
end
|
47
47
|
|
48
|
-
it '
|
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 '
|
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 '
|
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 '
|
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 '
|
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 '
|
72
|
+
it 'evaluates the pi constant' do
|
73
73
|
expect_expr('PI').to eq(3.141592653589793)
|
74
74
|
end
|
75
75
|
|
76
|
-
it '
|
76
|
+
it 'evaluates the negated pi constant' do
|
77
77
|
expect_expr('-PI').to eq(-3.141592653589793)
|
78
78
|
end
|
79
79
|
|
80
|
-
it "
|
80
|
+
it "evaluates Neper's e constant" do
|
81
81
|
expect_expr('E').to eq(2.718281828459045)
|
82
82
|
end
|
83
83
|
|
84
|
-
it "
|
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 '
|
88
|
+
it 'evaluates integer addition' do
|
89
89
|
expect_expr('2 + 2').to eq(4)
|
90
90
|
end
|
91
91
|
|
92
|
-
it '
|
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 '
|
96
|
+
it 'evaluates integer subtraction' do
|
97
97
|
expect_expr('2 - 3').to eq(-1)
|
98
98
|
end
|
99
99
|
|
100
|
-
it '
|
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 '
|
104
|
+
it 'handles negation of negative numbers' do
|
105
105
|
expect_expr('3--2').to eq(5)
|
106
106
|
end
|
107
107
|
|
108
|
-
it '
|
108
|
+
it 'evaluates integer multiplication' do
|
109
109
|
expect_expr('2 * 3').to eq(6)
|
110
110
|
end
|
111
111
|
|
112
|
-
it '
|
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 '
|
116
|
+
it 'evaluates division of integers' do
|
117
117
|
expect_expr('5 / 2').to eq(2.5)
|
118
118
|
end
|
119
119
|
|
120
|
-
it '
|
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 '
|
124
|
+
it 'evaluates integer exponent' do
|
125
125
|
expect_expr('5 ** (3 - 1)').to eq(25)
|
126
126
|
end
|
127
127
|
|
128
|
-
it '
|
128
|
+
it 'evaluates floating-point exponent' do
|
129
129
|
expect_expr('25 ** 0.5').to eq(5)
|
130
130
|
end
|
131
131
|
|
132
|
-
it '
|
132
|
+
it 'evaluates negative exponent' do
|
133
133
|
expect_expr('5 ** -2').to eq(0.04)
|
134
134
|
end
|
135
135
|
|
136
|
-
it '
|
136
|
+
it 'handles nested exponentiations' do
|
137
137
|
expect_expr('2 ** 2**2').to eq(16)
|
138
138
|
end
|
139
139
|
|
140
|
-
it '
|
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 '
|
144
|
+
it 'evaluates parentheses' do
|
145
145
|
expect_expr('2 * (2.1 + 1)').to eq(6.2)
|
146
146
|
end
|
147
147
|
|
148
|
-
it '
|
148
|
+
it 'evaluates regardless of whitespace' do
|
149
149
|
expect_expr("2*(1+\t1)").to eq(4)
|
150
150
|
end
|
151
151
|
|
152
|
-
it '
|
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 '
|
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 '
|
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 '
|
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 '
|
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 '
|
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 '
|
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 '
|
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 '
|
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 '
|
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 '
|
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 '
|
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 '
|
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
|
-
|
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, &
|
329
|
+
def df_traversal(aVertex, &_visit_action)
|
330
330
|
visit = [aVertex]
|
331
331
|
vtx2count = { aVertex => 0 }
|
332
332
|
|
data/lib/rley/constants.rb
CHANGED
data/lib/rley/rgn/tokenizer.rb
CHANGED
data/lib/rley/syntax/grammar.rb
CHANGED
@@ -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 {
|
30
|
+
subject(:an_item) { described_class.new(sample_prod, 1) }
|
31
31
|
|
32
32
|
context 'Initialization:' do
|
33
|
-
it '
|
34
|
-
expect {
|
35
|
-
expect {
|
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 '
|
38
|
+
it 'complains when the index is out-of-bounds' do
|
39
39
|
err = StandardError
|
40
40
|
msg = 'Out of bound index'
|
41
|
-
expect {
|
41
|
+
expect { described_class.new(sample_prod, 4) }.to raise_error(err, msg)
|
42
42
|
end
|
43
43
|
|
44
|
-
it '
|
45
|
-
expect(
|
44
|
+
it 'knows its production' do
|
45
|
+
expect(an_item.production).to eq(sample_prod)
|
46
46
|
end
|
47
47
|
|
48
|
-
it '
|
49
|
-
expect(
|
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 '
|
52
|
+
it 'knows its position' do
|
53
53
|
# At start position
|
54
|
-
instance1 =
|
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 =
|
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 =
|
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 =
|
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 '
|
73
|
-
expect(
|
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 =
|
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 =
|
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 '
|
85
|
-
expect(
|
84
|
+
it 'knows whether it is a reduce item' do
|
85
|
+
expect(an_item).not_to be_reduce_item
|
86
86
|
|
87
|
-
first_instance =
|
87
|
+
first_instance = described_class.new(sample_prod, 3)
|
88
88
|
expect(first_instance).to be_reduce_item
|
89
89
|
|
90
|
-
second_instance =
|
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 '
|
95
|
-
expect(
|
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 =
|
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 =
|
102
|
+
instance = described_class.new(sample_prod, 0)
|
103
103
|
expect(instance.prev_symbol).to be_nil
|
104
104
|
end
|
105
105
|
|
106
|
-
it '
|
107
|
-
expect(
|
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 '
|
111
|
-
expect(
|
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 =
|
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 =
|
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 =
|
122
|
+
instance = described_class.new(other_prod, 1)
|
123
123
|
expect(instance.prev_position).to eq(0)
|
124
124
|
end
|
125
125
|
|
126
|
-
it '
|
127
|
-
expect(
|
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 =
|
131
|
-
expect(
|
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 =
|
135
|
-
expect(
|
136
|
-
expect(instance).not_to be_successor_of(
|
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 =
|
139
|
+
instance2 = described_class.new(sample_prod, 2)
|
140
140
|
expect(instance).not_to be_successor_of(instance2)
|
141
|
-
expect(
|
142
|
-
expect(instance2).to be_successor_of(
|
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 '
|
147
|
+
it 'gives its text representation' do
|
148
148
|
expectation = 'sentence => A . B C'
|
149
|
-
expect(
|
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 '
|
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)
|