loxxy 0.4.09 → 0.4.10

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.
@@ -8,7 +8,7 @@ require_relative '../../lib/loxxy/front_end/parser'
8
8
  module Loxxy
9
9
  module FrontEnd
10
10
  describe Parser do
11
- subject { Parser.new }
11
+ subject(:parser) { described_class.new }
12
12
 
13
13
  # Utility method to walk towards deeply nested node
14
14
  # @param aNTNode [Rley::PTree::NonTerminalNode]
@@ -23,12 +23,12 @@ module Loxxy
23
23
  end
24
24
 
25
25
  context 'Initialization:' do
26
- it 'should be initialized without argument' do
27
- expect { Parser.new }.not_to raise_error
26
+ it 'is initialized without argument' do
27
+ expect { described_class.new }.not_to raise_error
28
28
  end
29
29
 
30
- it 'should have its parse engine initialized' do
31
- expect(subject.engine).to be_kind_of(Rley::Engine)
30
+ it 'has its parse engine initialized' do
31
+ expect(parser.engine).to be_a(Rley::Engine)
32
32
  end
33
33
  end # context
34
34
 
@@ -37,173 +37,173 @@ module Loxxy
37
37
  # Parse results MUST to comply to grammar rule:
38
38
  # program => declaration_star EOF
39
39
  # where the declaration_star MUST be empty
40
- expect(aParseTree.root).to be_kind_of(Ast::LoxNoopExpr)
40
+ expect(aParseTree.root).to be_a(Ast::LoxNoopExpr)
41
41
  end
42
42
 
43
- it 'should cope with an empty input' do
44
- ptree = subject.parse('')
43
+ it 'copes with an empty input' do
44
+ ptree = parser.parse('')
45
45
  check_empty_input_result(ptree)
46
46
  end
47
47
 
48
- it 'should cope with whitespaces only input' do
49
- ptree = subject.parse((' ' * 80) + ("\n" * 20))
48
+ it 'copes with whitespaces only input' do
49
+ ptree = parser.parse((' ' * 80) + ("\n" * 20))
50
50
  check_empty_input_result(ptree)
51
51
  end
52
52
 
53
- it 'should cope with comments only input' do
53
+ it 'copes with comments only input' do
54
54
  input = +''
55
55
  %w[First Second Third].each do |ordinal|
56
56
  input << "// #{ordinal} comment line\r\n"
57
57
  end
58
- ptree = subject.parse(input)
58
+ ptree = parser.parse(input)
59
59
  check_empty_input_result(ptree)
60
60
  end
61
61
  end # context
62
62
 
63
63
  context 'Parsing literals:' do
64
- it 'should parse a false literal' do
64
+ it 'parses a false literal' do
65
65
  input = 'false;'
66
- ptree = subject.parse(input)
67
- expect(ptree.root).to be_kind_of(Ast::LoxSeqDecl)
66
+ ptree = parser.parse(input)
67
+ expect(ptree.root).to be_a(Ast::LoxSeqDecl)
68
68
  leaf = ptree.root.subnodes[0]
69
- expect(leaf).to be_kind_of(Ast::LoxLiteralExpr)
70
- expect(leaf.literal).to be_equal(Datatype::False.instance)
69
+ expect(leaf).to be_a(Ast::LoxLiteralExpr)
70
+ expect(leaf.literal).to equal(Datatype::False.instance)
71
71
  end
72
72
 
73
- it 'should parse a true literal' do
73
+ it 'parses a true literal' do
74
74
  input = 'true;'
75
- ptree = subject.parse(input)
76
- expect(ptree.root).to be_kind_of(Ast::LoxSeqDecl)
75
+ ptree = parser.parse(input)
76
+ expect(ptree.root).to be_a(Ast::LoxSeqDecl)
77
77
  leaf = ptree.root.subnodes[0]
78
- expect(leaf).to be_kind_of(Ast::LoxLiteralExpr)
79
- expect(leaf.literal).to be_equal(Datatype::True.instance)
78
+ expect(leaf).to be_a(Ast::LoxLiteralExpr)
79
+ expect(leaf.literal).to equal(Datatype::True.instance)
80
80
  end
81
81
 
82
- it 'should parse number literals' do
82
+ it 'parses number literals' do
83
83
  inputs = %w[1234; 12.34;]
84
84
  inputs.each do |source|
85
- ptree = subject.parse(source)
85
+ ptree = parser.parse(source)
86
86
  leaf = ptree.root.subnodes[0]
87
- expect(leaf).to be_kind_of(Ast::LoxLiteralExpr)
88
- expect(leaf.literal).to be_kind_of(Datatype::Number)
87
+ expect(leaf).to be_a(Ast::LoxLiteralExpr)
88
+ expect(leaf.literal).to be_a(Datatype::Number)
89
89
  expect(leaf.literal.value).to eq(source.to_f)
90
90
  end
91
91
  end
92
92
 
93
- it 'should parse string literals' do
93
+ it 'parses string literals' do
94
94
  inputs = [
95
95
  '"I am a string";',
96
96
  '"";',
97
97
  '"123";'
98
98
  ]
99
99
  inputs.each do |source|
100
- ptree = subject.parse(source)
100
+ ptree = parser.parse(source)
101
101
  leaf = ptree.root.subnodes[0]
102
- expect(leaf).to be_kind_of(Ast::LoxLiteralExpr)
103
- expect(leaf.literal).to be_kind_of(Datatype::LXString)
102
+ expect(leaf).to be_a(Ast::LoxLiteralExpr)
103
+ expect(leaf.literal).to be_a(Datatype::LXString)
104
104
  expect(leaf.literal.value).to eq(source.gsub(/(^")|(";$)/, ''))
105
105
  end
106
106
  end
107
107
 
108
- it 'should parse a nil literal' do
108
+ it 'parses a nil literal' do
109
109
  input = 'nil;'
110
- ptree = subject.parse(input)
110
+ ptree = parser.parse(input)
111
111
  leaf = ptree.root.subnodes[0]
112
- expect(leaf).to be_kind_of(Ast::LoxLiteralExpr)
113
- expect(leaf.literal).to be_equal(Datatype::Nil.instance)
112
+ expect(leaf).to be_a(Ast::LoxLiteralExpr)
113
+ expect(leaf.literal).to equal(Datatype::Nil.instance)
114
114
  end
115
115
  end
116
116
 
117
117
  context 'Parsing expressions:' do
118
- it 'should parse a hello world program' do
118
+ it 'parses a hello world program' do
119
119
  program = <<-LOX_END
120
120
  // Your first Lox program!
121
121
  print "Hello, world!";
122
122
  LOX_END
123
- ptree = subject.parse(program)
123
+ ptree = parser.parse(program)
124
124
  prnt_stmt = ptree.root.subnodes[0]
125
- expect(prnt_stmt).to be_kind_of(Ast::LoxPrintStmt)
126
- expect(prnt_stmt.subnodes[0]).to be_kind_of(Ast::LoxLiteralExpr)
127
- expect(prnt_stmt.subnodes[0].literal).to be_kind_of(Loxxy::Datatype::LXString)
125
+ expect(prnt_stmt).to be_a(Ast::LoxPrintStmt)
126
+ expect(prnt_stmt.subnodes[0]).to be_a(Ast::LoxLiteralExpr)
127
+ expect(prnt_stmt.subnodes[0].literal).to be_a(Loxxy::Datatype::LXString)
128
128
  expect(prnt_stmt.subnodes[0].literal.value).to eq('Hello, world!')
129
129
  end
130
130
  end # context
131
131
 
132
132
  context 'Parsing arithmetic operations' do
133
- it 'should parse the addition of two number literals' do
133
+ it 'parses the addition of two number literals' do
134
134
  input = '123 + 456;'
135
- ptree = subject.parse(input)
135
+ ptree = parser.parse(input)
136
136
  expr = ptree.root.subnodes[0]
137
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
137
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
138
138
  expect(expr.operator).to eq(:+)
139
139
  expect(expr.operands[0].literal.value).to eq(123)
140
140
  expect(expr.operands[1].literal.value).to eq(456)
141
141
  end
142
142
 
143
- it 'should parse the subtraction of two number literals' do
143
+ it 'parses the subtraction of two number literals' do
144
144
  input = '4 - 3;'
145
- ptree = subject.parse(input)
145
+ ptree = parser.parse(input)
146
146
  expr = ptree.root.subnodes[0]
147
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
147
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
148
148
  expect(expr.operator).to eq(:-)
149
149
  expect(expr.operands[0].literal.value).to eq(4)
150
150
  expect(expr.operands[1].literal.value).to eq(3)
151
151
  end
152
152
 
153
- it 'should parse multiple additive operations' do
153
+ it 'parses multiple additive operations' do
154
154
  input = '5 + 2 - 3;'
155
- ptree = subject.parse(input)
155
+ ptree = parser.parse(input)
156
156
  expr = ptree.root.subnodes[0]
157
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
157
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
158
158
  expect(expr.operator).to eq(:-)
159
- expect(expr.operands[0]).to be_kind_of(Ast::LoxBinaryExpr)
159
+ expect(expr.operands[0]).to be_a(Ast::LoxBinaryExpr)
160
160
  expect(expr.operands[0].operator).to eq(:+)
161
161
  expect(expr.operands[0].operands[0].literal.value).to eq(5)
162
162
  expect(expr.operands[0].operands[1].literal.value).to eq(2)
163
163
  expect(expr.operands[1].literal.value).to eq(3)
164
164
  end
165
165
 
166
- it 'should parse the division of two number literals' do
166
+ it 'parses the division of two number literals' do
167
167
  input = '8 / 2;'
168
- ptree = subject.parse(input)
168
+ ptree = parser.parse(input)
169
169
  expr = ptree.root.subnodes[0]
170
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
170
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
171
171
  expect(expr.operator).to eq(:/)
172
172
  expect(expr.operands[0].literal.value).to eq(8)
173
173
  expect(expr.operands[1].literal.value).to eq(2)
174
174
  end
175
175
 
176
- it 'should parse the product of two number literals' do
176
+ it 'parses the product of two number literals' do
177
177
  input = '12.34 * 0.3;'
178
- ptree = subject.parse(input)
178
+ ptree = parser.parse(input)
179
179
  expr = ptree.root.subnodes[0]
180
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
180
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
181
181
  expect(expr.operator).to eq(:*)
182
182
  expect(expr.operands[0].literal.value).to eq(12.34)
183
183
  expect(expr.operands[1].literal.value).to eq(0.3)
184
184
  end
185
185
 
186
- it 'should parse multiple multiplicative operations' do
186
+ it 'parses multiple multiplicative operations' do
187
187
  input = '5 * 2 / 3;'
188
- ptree = subject.parse(input)
188
+ ptree = parser.parse(input)
189
189
  expr = ptree.root.subnodes[0]
190
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
190
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
191
191
  expect(expr.operator).to eq(:/)
192
- expect(expr.operands[0]).to be_kind_of(Ast::LoxBinaryExpr)
192
+ expect(expr.operands[0]).to be_a(Ast::LoxBinaryExpr)
193
193
  expect(expr.operands[0].operator).to eq(:*)
194
194
  expect(expr.operands[0].operands[0].literal.value).to eq(5)
195
195
  expect(expr.operands[0].operands[1].literal.value).to eq(2)
196
196
  expect(expr.operands[1].literal.value).to eq(3)
197
197
  end
198
198
 
199
- it 'should parse combination of terms and factors' do
199
+ it 'parses combination of terms and factors' do
200
200
  input = '5 + 2 / 3;'
201
- ptree = subject.parse(input)
201
+ ptree = parser.parse(input)
202
202
  expr = ptree.root.subnodes[0]
203
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
203
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
204
204
  expect(expr.operator).to eq(:+)
205
205
  expect(expr.operands[0].literal.value).to eq(5)
206
- expect(expr.operands[1]).to be_kind_of(Ast::LoxBinaryExpr)
206
+ expect(expr.operands[1]).to be_a(Ast::LoxBinaryExpr)
207
207
  expect(expr.operands[1].operator).to eq(:/)
208
208
  expect(expr.operands[1].operands[0].literal.value).to eq(2)
209
209
  expect(expr.operands[1].operands[1].literal.value).to eq(3)
@@ -211,11 +211,11 @@ LOX_END
211
211
  end # context
212
212
 
213
213
  context 'Parsing string concatenation' do
214
- it 'should parse the concatenation of two string literals' do
214
+ it 'parses the concatenation of two string literals' do
215
215
  input = '"Lo" + "ve";'
216
- ptree = subject.parse(input)
216
+ ptree = parser.parse(input)
217
217
  expr = ptree.root.subnodes[0]
218
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
218
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
219
219
  expect(expr.operator).to eq(:+)
220
220
  expect(expr.operands[0].literal.value).to eq('Lo')
221
221
  expect(expr.operands[1].literal.value).to eq('ve')
@@ -223,12 +223,12 @@ LOX_END
223
223
  end # context
224
224
 
225
225
  context 'Parsing comparison expressions' do
226
- it 'should parse the comparison of two number literals' do
226
+ it 'parses the comparison of two number literals' do
227
227
  %w[> >= < <=].each do |predicate|
228
228
  input = "3 #{predicate} 2;"
229
- ptree = subject.parse(input)
229
+ ptree = parser.parse(input)
230
230
  expr = ptree.root.subnodes[0]
231
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
231
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
232
232
  expect(expr.operator).to eq(predicate.to_sym)
233
233
  expect(expr.operands[0].literal.value).to eq(3)
234
234
  expect(expr.operands[1].literal.value).to eq(2)
@@ -237,25 +237,25 @@ LOX_END
237
237
  end # context
238
238
 
239
239
  context 'Parsing equality expressions' do
240
- it 'should parse the equality of two number literals' do
240
+ it 'parses the equality of two number literals' do
241
241
  %w[!= ==].each do |predicate|
242
242
  input = "3 #{predicate} 2;"
243
- ptree = subject.parse(input)
243
+ ptree = parser.parse(input)
244
244
  expr = ptree.root.subnodes[0]
245
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
245
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
246
246
  expect(expr.operator).to eq(predicate.to_sym)
247
247
  expect(expr.operands[0].literal.value).to eq(3)
248
248
  expect(expr.operands[1].literal.value).to eq(2)
249
249
  end
250
250
  end
251
251
 
252
- it 'should parse combination of equality expressions' do
252
+ it 'parses combination of equality expressions' do
253
253
  input = '5 != 2 == false; // A bit contrived example'
254
- ptree = subject.parse(input)
254
+ ptree = parser.parse(input)
255
255
  expr = ptree.root.subnodes[0]
256
- expect(expr).to be_kind_of(Ast::LoxBinaryExpr)
256
+ expect(expr).to be_a(Ast::LoxBinaryExpr)
257
257
  expect(expr.operator).to eq(:==)
258
- expect(expr.operands[0]).to be_kind_of(Ast::LoxBinaryExpr)
258
+ expect(expr.operands[0]).to be_a(Ast::LoxBinaryExpr)
259
259
  expect(expr.operands[0].operator).to eq(:!=)
260
260
  expect(expr.operands[0].operands[0].literal.value).to eq(5)
261
261
  expect(expr.operands[0].operands[1].literal.value).to eq(2)
@@ -264,42 +264,42 @@ LOX_END
264
264
  end # context
265
265
 
266
266
  context 'Parsing logical expressions' do
267
- it 'should parse the logical operations between two sub-expression' do
267
+ it 'parses the logical operations between two sub-expression' do
268
268
  %w[or and].each do |connector|
269
269
  input = "5 > 2 #{connector} 3 <= 4;"
270
- ptree = subject.parse(input)
270
+ ptree = parser.parse(input)
271
271
  expr = ptree.root.subnodes[0]
272
- expect(expr).to be_kind_of(Ast::LoxLogicalExpr)
272
+ expect(expr).to be_a(Ast::LoxLogicalExpr)
273
273
  expect(expr.operator).to eq(connector.to_sym)
274
- expect(expr.operands[0]).to be_kind_of(Ast::LoxBinaryExpr)
274
+ expect(expr.operands[0]).to be_a(Ast::LoxBinaryExpr)
275
275
  expect(expr.operands[0].operator).to eq(:>)
276
276
  expect(expr.operands[0].operands[0].literal.value).to eq(5)
277
277
  expect(expr.operands[0].operands[1].literal.value).to eq(2)
278
- expect(expr.operands[1]).to be_kind_of(Ast::LoxBinaryExpr)
278
+ expect(expr.operands[1]).to be_a(Ast::LoxBinaryExpr)
279
279
  expect(expr.operands[1].operator).to eq(:<=)
280
280
  expect(expr.operands[1].operands[0].literal.value).to eq(3)
281
281
  expect(expr.operands[1].operands[1].literal.value).to eq(4)
282
282
  end
283
283
  end
284
284
 
285
- it 'should parse a combinations of logical expressions' do
285
+ it 'parses a combinations of logical expressions' do
286
286
  input = '4 > 3 and 1 < 2 or 4 >= 5;'
287
- ptree = subject.parse(input)
287
+ ptree = parser.parse(input)
288
288
  expr = ptree.root.subnodes[0]
289
- expect(expr).to be_kind_of(Ast::LoxLogicalExpr)
289
+ expect(expr).to be_a(Ast::LoxLogicalExpr)
290
290
  expect(expr.operator).to eq(:or) # or has lower precedence than and
291
- expect(expr.operands[0]).to be_kind_of(Ast::LoxLogicalExpr)
291
+ expect(expr.operands[0]).to be_a(Ast::LoxLogicalExpr)
292
292
  expect(expr.operands[0].operator).to eq(:and)
293
293
  conjuncts = expr.operands[0].operands
294
- expect(conjuncts[0]).to be_kind_of(Ast::LoxBinaryExpr)
294
+ expect(conjuncts[0]).to be_a(Ast::LoxBinaryExpr)
295
295
  expect(conjuncts[0].operator).to eq(:>)
296
296
  expect(conjuncts[0].operands[0].literal.value).to eq(4)
297
297
  expect(conjuncts[0].operands[1].literal.value).to eq(3)
298
- expect(conjuncts[1]).to be_kind_of(Ast::LoxBinaryExpr)
298
+ expect(conjuncts[1]).to be_a(Ast::LoxBinaryExpr)
299
299
  expect(conjuncts[1].operator).to eq(:<)
300
300
  expect(conjuncts[1].operands[0].literal.value).to eq(1)
301
301
  expect(conjuncts[1].operands[1].literal.value).to eq(2)
302
- expect(expr.operands[1]).to be_kind_of(Ast::LoxBinaryExpr)
302
+ expect(expr.operands[1]).to be_a(Ast::LoxBinaryExpr)
303
303
  expect(expr.operands[1].operator).to eq(:>=)
304
304
  expect(expr.operands[1].operands[0].literal.value).to eq(4)
305
305
  expect(expr.operands[1].operands[1].literal.value).to eq(5)
@@ -307,18 +307,18 @@ LOX_END
307
307
  end # context
308
308
 
309
309
  context 'Object orientation:' do
310
- it 'should parse object property get access' do
310
+ it 'parses object property get access' do
311
311
  input = 'print someObject.someProperty;'
312
- ptree = subject.parse(input)
312
+ ptree = parser.parse(input)
313
313
  expr = ptree.root.subnodes[0]
314
- expect(expr).to be_kind_of(Ast::LoxPrintStmt)
314
+ expect(expr).to be_a(Ast::LoxPrintStmt)
315
315
  get_expr = expr.subnodes[0]
316
- expect(get_expr).to be_kind_of(Ast::LoxGetExpr)
316
+ expect(get_expr).to be_a(Ast::LoxGetExpr)
317
317
  expect(get_expr.object.name).to eq('someObject')
318
318
  expect(get_expr.property).to eq('someProperty')
319
319
  end
320
320
 
321
- it 'should parse nested call expressions' do
321
+ it 'parses nested call expressions' do
322
322
  input = 'print egg.scramble(3).with(cheddar);'
323
323
  # From section 12.3.1, one expects something like:
324
324
  # LoxCallExpr
@@ -330,34 +330,34 @@ LOX_END
330
330
  # +- callee = LoxGetExpr
331
331
  # +- property = 'scramble'
332
332
  # +- object = variable 'egg'
333
- ptree = subject.parse(input)
333
+ ptree = parser.parse(input)
334
334
  print_stmt = ptree.root.subnodes[0]
335
- expect(print_stmt).to be_kind_of(Ast::LoxPrintStmt)
335
+ expect(print_stmt).to be_a(Ast::LoxPrintStmt)
336
336
  outer_call = print_stmt.subnodes[0]
337
- expect(outer_call).to be_kind_of(Ast::LoxCallExpr)
337
+ expect(outer_call).to be_a(Ast::LoxCallExpr)
338
338
  expect(outer_call.arguments[0].name).to eq('cheddar')
339
- expect(outer_call.callee).to be_kind_of(Ast::LoxGetExpr)
339
+ expect(outer_call.callee).to be_a(Ast::LoxGetExpr)
340
340
  expect(outer_call.callee.property).to eq('with')
341
341
  inner_call = outer_call.callee.object
342
- expect(inner_call).to be_kind_of(Ast::LoxCallExpr)
342
+ expect(inner_call).to be_a(Ast::LoxCallExpr)
343
343
  expect(inner_call.arguments[0].literal).to eq(3)
344
- expect(inner_call.callee).to be_kind_of(Ast::LoxGetExpr)
344
+ expect(inner_call.callee).to be_a(Ast::LoxGetExpr)
345
345
  expect(inner_call.callee.property).to eq('scramble')
346
346
  expect(inner_call.callee.object.name).to eq('egg')
347
347
  end
348
348
 
349
- it 'should parse object property set access' do
349
+ it 'parses object property set access' do
350
350
  input = 'someObject.someProperty = value;'
351
- ptree = subject.parse(input)
351
+ ptree = parser.parse(input)
352
352
  expr = ptree.root.subnodes[0]
353
- expect(expr).to be_kind_of(Ast::LoxSetExpr)
353
+ expect(expr).to be_a(Ast::LoxSetExpr)
354
354
  expect(expr.object.name).to eq('someObject')
355
355
  expect(expr.property).to eq('someProperty')
356
- expect(expr.value).to be_kind_of(Ast::LoxVariableExpr)
356
+ expect(expr.value).to be_a(Ast::LoxVariableExpr)
357
357
  expect(expr.value.name).to eq('value')
358
358
  end
359
359
 
360
- it 'should parse complex set access' do
360
+ it 'parses complex set access' do
361
361
  input = 'breakfast.omelette.filling.meat = ham;'
362
362
  # From section 12.3.2, one expects something like:
363
363
  # LoxSetExpr
@@ -368,17 +368,17 @@ LOX_END
368
368
  # +- object = LoxGetExpr
369
369
  # +- property = 'omelette'
370
370
  # +- object = LoxVariableExpr 'breakfast'
371
- ptree = subject.parse(input)
371
+ ptree = parser.parse(input)
372
372
  expr = ptree.root.subnodes[0]
373
- expect(expr).to be_kind_of(Ast::LoxSetExpr)
373
+ expect(expr).to be_a(Ast::LoxSetExpr)
374
374
  expect(expr.property).to eq('meat')
375
- expect(expr.value).to be_kind_of(Ast::LoxVariableExpr)
375
+ expect(expr.value).to be_a(Ast::LoxVariableExpr)
376
376
  expect(expr.value.name).to eq('ham')
377
- expect(expr.object).to be_kind_of(Ast::LoxGetExpr)
377
+ expect(expr.object).to be_a(Ast::LoxGetExpr)
378
378
  expect(expr.object.property).to eq('filling')
379
- expect(expr.object.object).to be_kind_of(Ast::LoxGetExpr)
379
+ expect(expr.object.object).to be_a(Ast::LoxGetExpr)
380
380
  expect(expr.object.object.property).to eq('omelette')
381
- expect(expr.object.object.object).to be_kind_of(Ast::LoxVariableExpr)
381
+ expect(expr.object.object.object).to be_a(Ast::LoxVariableExpr)
382
382
  expect(expr.object.object.object.name).to eq('breakfast')
383
383
  end
384
384
  end # context
@@ -8,15 +8,15 @@ require_relative '../../lib/loxxy/front_end/raw_parser'
8
8
  module Loxxy
9
9
  module FrontEnd
10
10
  describe RawParser do
11
- subject { RawParser.new }
11
+ subject(:raw_parser) { described_class.new }
12
12
 
13
13
  context 'Initialization:' do
14
- it 'should be initialized without argument' do
15
- expect { RawParser.new }.not_to raise_error
14
+ it 'is initialized without argument' do
15
+ expect { described_class.new }.not_to raise_error
16
16
  end
17
17
 
18
- it 'should have its parse engine initialized' do
19
- expect(subject.engine).to be_kind_of(Rley::Engine)
18
+ it 'has its parse engine initialized' do
19
+ expect(raw_parser.engine).to be_a(Rley::Engine)
20
20
  end
21
21
  end # context
22
22
 
@@ -27,29 +27,29 @@ module Loxxy
27
27
  # where the declaration_star MUST be empty
28
28
  expect(aParseTree.root.symbol.name).to eq('program')
29
29
  (decls, eof) = aParseTree.root.subnodes
30
- expect(decls).to be_kind_of(Rley::PTree::NonTerminalNode)
30
+ expect(decls).to be_a(Rley::PTree::NonTerminalNode)
31
31
  expect(decls.symbol.name).to eq('rep_declaration_star')
32
32
  expect(decls.subnodes).to be_empty
33
- expect(eof).to be_kind_of(Rley::PTree::TerminalNode)
33
+ expect(eof).to be_a(Rley::PTree::TerminalNode)
34
34
  expect(eof.symbol.name).to eq('EOF')
35
35
  end
36
36
 
37
- it 'should cope with an empty input' do
38
- ptree = subject.parse('')
37
+ it 'copes with an empty input' do
38
+ ptree = raw_parser.parse('')
39
39
  check_empty_input_result(ptree)
40
40
  end
41
41
 
42
- it 'should cope with whitespaces only input' do
43
- ptree = subject.parse((' ' * 80) + ("\n" * 20))
42
+ it 'copes with whitespaces only input' do
43
+ ptree = raw_parser.parse((' ' * 80) + ("\n" * 20))
44
44
  check_empty_input_result(ptree)
45
45
  end
46
46
 
47
- it 'should cope with comments only input' do
47
+ it 'copes with comments only input' do
48
48
  input = +''
49
49
  %w[First Second Third].each do |ordinal|
50
50
  input << "// #{ordinal} comment line\r\n"
51
51
  end
52
- ptree = subject.parse(input)
52
+ ptree = raw_parser.parse(input)
53
53
  check_empty_input_result(ptree)
54
54
  end
55
55
  end # context
@@ -66,37 +66,37 @@ module Loxxy
66
66
 
67
67
  curr_node
68
68
  end
69
- it 'should parse a hello world program' do
69
+ it 'parses a hello world program' do
70
70
  program = <<-LOX_END
71
71
  // Your first Lox program!
72
72
  print "Hello, world!";
73
73
  LOX_END
74
- ptree = subject.parse(program)
74
+ ptree = raw_parser.parse(program)
75
75
  root = ptree.root
76
76
  expect(root.symbol.name).to eq('program')
77
77
  (decls, eof) = root.subnodes
78
- expect(decls).to be_kind_of(Rley::PTree::NonTerminalNode)
78
+ expect(decls).to be_a(Rley::PTree::NonTerminalNode)
79
79
  expect(decls.symbol.name).to eq('rep_declaration_star')
80
- expect(decls.subnodes[0]).to be_kind_of(Rley::PTree::NonTerminalNode)
80
+ expect(decls.subnodes[0]).to be_a(Rley::PTree::NonTerminalNode)
81
81
  expect(decls.subnodes[0].symbol.name).to eq('rep_declaration_star')
82
- expect(decls.subnodes[1]).to be_kind_of(Rley::PTree::NonTerminalNode)
82
+ expect(decls.subnodes[1]).to be_a(Rley::PTree::NonTerminalNode)
83
83
  expect(decls.subnodes[1].symbol.name).to eq('declaration')
84
84
  statement = decls.subnodes[1].subnodes[0]
85
- expect(statement).to be_kind_of(Rley::PTree::NonTerminalNode)
85
+ expect(statement).to be_a(Rley::PTree::NonTerminalNode)
86
86
  expect(statement.symbol.name).to eq('statement')
87
87
  prnt_stmt = statement.subnodes[0]
88
- expect(prnt_stmt).to be_kind_of(Rley::PTree::NonTerminalNode)
88
+ expect(prnt_stmt).to be_a(Rley::PTree::NonTerminalNode)
89
89
  expect(prnt_stmt.subnodes.size).to eq(3)
90
- expect(prnt_stmt.subnodes[0]).to be_kind_of(Rley::PTree::TerminalNode)
90
+ expect(prnt_stmt.subnodes[0]).to be_a(Rley::PTree::TerminalNode)
91
91
  expect(prnt_stmt.subnodes[0].symbol.name).to eq('PRINT')
92
- expect(prnt_stmt.subnodes[1]).to be_kind_of(Rley::PTree::NonTerminalNode)
92
+ expect(prnt_stmt.subnodes[1]).to be_a(Rley::PTree::NonTerminalNode)
93
93
  leaf_node = walk_subnodes(prnt_stmt, [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0])
94
- expect(leaf_node).to be_kind_of(Rley::PTree::TerminalNode)
94
+ expect(leaf_node).to be_a(Rley::PTree::TerminalNode)
95
95
  expect(leaf_node.symbol.name).to eq('STRING')
96
96
  expect(leaf_node.token.value).to eq('Hello, world!')
97
- expect(prnt_stmt.subnodes[2]).to be_kind_of(Rley::PTree::TerminalNode)
97
+ expect(prnt_stmt.subnodes[2]).to be_a(Rley::PTree::TerminalNode)
98
98
  expect(prnt_stmt.subnodes[2].symbol.name).to eq('SEMICOLON')
99
- expect(eof).to be_kind_of(Rley::PTree::TerminalNode)
99
+ expect(eof).to be_a(Rley::PTree::TerminalNode)
100
100
  expect(eof.symbol.name).to eq('EOF')
101
101
  end
102
102
  end