loxxy 0.4.08 → 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.
- checksums.yaml +4 -4
- data/.rubocop.yml +33 -305
- data/CHANGELOG.md +9 -1
- data/LICENSE.txt +1 -1
- data/README.md +6 -4
- data/lib/loxxy/ast/ast_builder.rb +3 -3
- data/lib/loxxy/back_end/engine.rb +2 -0
- data/lib/loxxy/back_end/environment.rb +1 -1
- data/lib/loxxy/back_end/resolver.rb +0 -2
- data/lib/loxxy/datatype/number.rb +0 -2
- data/lib/loxxy/front_end/scanner.rb +10 -10
- data/lib/loxxy/interpreter.rb +3 -3
- data/lib/loxxy/version.rb +1 -1
- data/loxxy.gemspec +8 -8
- data/spec/back_end/engine_spec.rb +21 -19
- data/spec/back_end/environment_spec.rb +20 -19
- data/spec/back_end/symbol_table_spec.rb +67 -67
- data/spec/back_end/variable_spec.rb +14 -13
- data/spec/datatype/boolean_spec.rb +9 -8
- data/spec/datatype/lx_string_spec.rb +16 -15
- data/spec/datatype/nil_spec.rb +5 -5
- data/spec/datatype/number_spec.rb +18 -17
- data/spec/front_end/parser_spec.rb +110 -110
- data/spec/front_end/raw_parser_spec.rb +25 -25
- data/spec/front_end/scanner_spec.rb +77 -76
- data/spec/interpreter_spec.rb +114 -118
- data/spec/loxxy_spec.rb +1 -1
- metadata +34 -18
- data/.travis.yml +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21a1cbd9499c50fc448238c4b46fabf32add037e813d073df2e88126682076cb
|
4
|
+
data.tar.gz: 54b00da85e3b48be9506ad9f5c52e4844c26491dcf3007a360af2c5a925296d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a35a3aefa589ba7d2d5d0c3e2f9b21b837855ea46e93817e890649d5a0a8fc7f0d02b3fd2fdf0072c0f2b7ccdd4ad6c77e4c585f7dd08fe6394ee5f08dca23af
|
7
|
+
data.tar.gz: e5d91111f82398021791ef5e6c3f0625e3b16527aec81948dc730381b6da882a86ec7c6a11fd25273c2b8e06efb781421ee2de9b586833f0eb234cbbfcc67982
|
data/.rubocop.yml
CHANGED
@@ -2,8 +2,16 @@ AllCops:
|
|
2
2
|
Exclude:
|
3
3
|
- 'exp/**/*'
|
4
4
|
- 'demo/**/*'
|
5
|
+
NewCops: enable
|
6
|
+
SuggestExtensions: false
|
5
7
|
|
6
|
-
Gemspec/
|
8
|
+
Gemspec/DeprecatedAttributeAssignment:
|
9
|
+
Enabled: true
|
10
|
+
|
11
|
+
Gemspec/DevelopmentDependencies:
|
12
|
+
EnforcedStyle: gemspec
|
13
|
+
|
14
|
+
Gemspec/RequireMFA: # new in 1.23
|
7
15
|
Enabled: true
|
8
16
|
|
9
17
|
Layout/ArgumentAlignment:
|
@@ -60,117 +68,12 @@ Layout/MultilineMethodCallBraceLayout:
|
|
60
68
|
Enabled: true
|
61
69
|
EnforcedStyle: same_line
|
62
70
|
|
63
|
-
Layout/SpaceAroundOperators:
|
64
|
-
Enabled: true
|
65
|
-
|
66
|
-
Layout/SpaceBeforeBrackets:
|
67
|
-
Enabled: true
|
68
|
-
|
69
|
-
Layout/SpaceInsideParens:
|
70
|
-
Enabled: true
|
71
|
-
|
72
|
-
Layout/IndentationStyle:
|
73
|
-
Enabled: true
|
74
|
-
|
75
|
-
Layout/SpaceAroundMethodCallOperator:
|
76
|
-
Enabled: true
|
77
|
-
|
78
|
-
Layout/TrailingEmptyLines:
|
79
|
-
Enabled: true
|
80
|
-
|
81
|
-
Layout/TrailingWhitespace:
|
82
|
-
Enabled: true
|
83
|
-
|
84
|
-
Lint/AmbiguousAssignment:
|
85
|
-
Enabled: true
|
86
|
-
|
87
71
|
Lint/AmbiguousOperatorPrecedence: # new in 1.21
|
88
72
|
Enabled: true
|
89
73
|
|
90
|
-
Lint/AmbiguousRange:
|
91
|
-
Enabled: true
|
92
|
-
|
93
|
-
Lint/DeprecatedConstants:
|
94
|
-
Enabled: true
|
95
|
-
|
96
|
-
Lint/DuplicateBranch:
|
97
|
-
Enabled: true
|
98
|
-
|
99
|
-
Lint/DuplicateRegexpCharacterClassElement:
|
100
|
-
Enabled: true
|
101
|
-
|
102
|
-
Lint/EmptyBlock:
|
103
|
-
Enabled: true
|
104
|
-
|
105
74
|
Lint/EmptyClass:
|
106
75
|
Enabled: false
|
107
76
|
|
108
|
-
Lint/EmptyInPattern:
|
109
|
-
Enabled: true
|
110
|
-
|
111
|
-
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
|
112
|
-
Enabled: true
|
113
|
-
|
114
|
-
Lint/LambdaWithoutLiteralBlock:
|
115
|
-
Enabled: true
|
116
|
-
|
117
|
-
Lint/Loop:
|
118
|
-
Enabled: true
|
119
|
-
|
120
|
-
Lint/NoReturnInBeginEndBlocks:
|
121
|
-
Enabled: true
|
122
|
-
|
123
|
-
Lint/NumberedParameterAssignment:
|
124
|
-
Enabled: true
|
125
|
-
|
126
|
-
Lint/OrAssignmentToConstant:
|
127
|
-
Enabled: true
|
128
|
-
|
129
|
-
Lint/RaiseException:
|
130
|
-
Enabled: true
|
131
|
-
|
132
|
-
Lint/RedundantDirGlobSort:
|
133
|
-
Enabled: true
|
134
|
-
|
135
|
-
Lint/RequireRelativeSelfPath: # new in 1.22
|
136
|
-
Enabled: true
|
137
|
-
|
138
|
-
Lint/RescueException:
|
139
|
-
Enabled: true
|
140
|
-
|
141
|
-
Lint/StructNewOverride:
|
142
|
-
Enabled: true
|
143
|
-
|
144
|
-
Lint/SymbolConversion:
|
145
|
-
Enabled: true
|
146
|
-
|
147
|
-
Lint/ToEnumArguments:
|
148
|
-
Enabled: true
|
149
|
-
|
150
|
-
Lint/TripleQuotes:
|
151
|
-
Enabled: true
|
152
|
-
|
153
|
-
Lint/UnexpectedBlockArity:
|
154
|
-
Enabled: true
|
155
|
-
|
156
|
-
Lint/UnmodifiedReduceAccumulator:
|
157
|
-
Enabled: true
|
158
|
-
|
159
|
-
Lint/UnusedMethodArgument:
|
160
|
-
Enabled: true
|
161
|
-
|
162
|
-
Lint/UselessAccessModifier:
|
163
|
-
Enabled: true
|
164
|
-
|
165
|
-
Lint/UselessRuby2Keywords: # new in 1.23
|
166
|
-
Enabled: true
|
167
|
-
|
168
|
-
Lint/Void:
|
169
|
-
Enabled: false
|
170
|
-
|
171
|
-
Lint/UselessAssignment:
|
172
|
-
Enabled: true
|
173
|
-
|
174
77
|
Metrics/AbcSize:
|
175
78
|
Enabled: false
|
176
79
|
|
@@ -204,21 +107,12 @@ Metrics/ModuleLength:
|
|
204
107
|
Metrics/PerceivedComplexity:
|
205
108
|
Enabled: false
|
206
109
|
|
207
|
-
Naming/BlockForwarding: # new in 1.24
|
208
|
-
Enabled: true
|
209
|
-
|
210
110
|
Naming/ConstantName:
|
211
111
|
Enabled: false
|
212
112
|
|
213
113
|
Naming/ClassAndModuleCamelCase:
|
214
114
|
Enabled: false
|
215
115
|
|
216
|
-
Naming/BlockParameterName:
|
217
|
-
Enabled: true
|
218
|
-
|
219
|
-
Naming/InclusiveLanguage:
|
220
|
-
Enabled: true
|
221
|
-
|
222
116
|
Naming/MethodParameterName:
|
223
117
|
Enabled: false
|
224
118
|
|
@@ -228,15 +122,6 @@ Naming/MethodName:
|
|
228
122
|
Naming/VariableName:
|
229
123
|
Enabled: false
|
230
124
|
|
231
|
-
Security/IoMethods: # new in 1.22
|
232
|
-
Enabled: true
|
233
|
-
|
234
|
-
Style/Alias:
|
235
|
-
Enabled: true
|
236
|
-
|
237
|
-
Style/ArgumentsForwarding:
|
238
|
-
Enabled: true
|
239
|
-
|
240
125
|
Style/AsciiComments:
|
241
126
|
Enabled: false
|
242
127
|
|
@@ -255,9 +140,6 @@ Style/ClassCheck:
|
|
255
140
|
Style/ClassVars:
|
256
141
|
Enabled: false
|
257
142
|
|
258
|
-
Style/CollectionCompact:
|
259
|
-
Enabled: true
|
260
|
-
|
261
143
|
Style/ColonMethodCall:
|
262
144
|
Enabled: false
|
263
145
|
|
@@ -270,223 +152,69 @@ Style/CommentedKeyword:
|
|
270
152
|
Style/ConditionalAssignment:
|
271
153
|
Enabled: false
|
272
154
|
|
273
|
-
Style/DefWithParentheses:
|
274
|
-
Enabled: true
|
275
|
-
|
276
155
|
Style/Documentation:
|
277
156
|
Enabled: false
|
278
157
|
|
279
|
-
Style/DocumentDynamicEvalDefinition:
|
280
|
-
Enabled: true
|
281
|
-
|
282
158
|
Style/ExpandPathArguments:
|
283
159
|
Enabled: false
|
284
160
|
|
285
|
-
Style/ExponentialNotation:
|
286
|
-
Enabled: true
|
287
|
-
|
288
161
|
Style/GuardClause:
|
289
162
|
Enabled: false
|
290
163
|
|
291
|
-
Style/HashEachMethods:
|
292
|
-
Enabled: true
|
293
|
-
|
294
|
-
Style/HashExcept:
|
295
|
-
Enabled: true
|
296
|
-
|
297
|
-
Style/HashTransformKeys:
|
298
|
-
Enabled: true
|
299
|
-
|
300
|
-
Style/HashTransformValues:
|
301
|
-
Enabled: true
|
302
|
-
|
303
164
|
Style/IfUnlessModifier:
|
304
165
|
Enabled: false
|
305
166
|
|
306
|
-
Style/InPatternThen:
|
307
|
-
Enabled: true
|
308
|
-
|
309
167
|
Style/InverseMethods:
|
310
168
|
Enabled: false
|
311
169
|
|
312
170
|
Style/MissingRespondToMissing:
|
313
171
|
Enabled: false
|
314
172
|
|
315
|
-
Style/MultilineInPatternThen:
|
316
|
-
Enabled: true
|
317
|
-
|
318
|
-
Style/NegatedIfElseCondition:
|
319
|
-
Enabled: true
|
320
|
-
|
321
173
|
Style/Next:
|
322
174
|
Enabled: false
|
323
175
|
|
324
|
-
Style/NilLambda:
|
325
|
-
Enabled: true
|
326
|
-
|
327
|
-
Style/NumberedParameters: # new in 1.22
|
328
|
-
Enabled: true
|
329
|
-
|
330
|
-
Style/NumberedParametersLimit: # new in 1.22
|
331
|
-
Enabled: true
|
332
|
-
|
333
176
|
Style/NumericLiterals:
|
334
177
|
Enabled: false
|
335
178
|
|
336
|
-
Style/QuotedSymbols:
|
337
|
-
Enabled: true
|
338
|
-
|
339
|
-
Style/RaiseArgs:
|
340
|
-
Enabled: true
|
341
|
-
|
342
|
-
Style/RedundantArgument:
|
343
|
-
Enabled: true
|
344
|
-
|
345
179
|
Style/RedundantReturn:
|
346
180
|
Enabled: false
|
347
181
|
|
348
|
-
Style/RedundantSelf:
|
349
|
-
Enabled: true
|
350
|
-
|
351
|
-
Style/RedundantSelfAssignmentBranch:
|
352
|
-
Enabled: true
|
353
|
-
|
354
182
|
Style/RegexpLiteral:
|
355
183
|
Enabled: false
|
356
184
|
|
357
185
|
Style/PercentLiteralDelimiters:
|
358
186
|
Enabled: false
|
359
187
|
|
360
|
-
Style/SelectByRegexp: # new in 1.22
|
361
|
-
Enabled: true
|
362
|
-
|
363
188
|
Style/StderrPuts:
|
364
189
|
Enabled: false
|
365
190
|
|
366
|
-
Style/StringLiterals:
|
367
|
-
Enabled: true
|
368
|
-
|
369
|
-
Style/SwapValues:
|
370
|
-
Enabled: true
|
371
|
-
|
372
191
|
Style/TernaryParentheses:
|
373
192
|
Enabled: false
|
374
193
|
|
375
194
|
Style/UnlessElse:
|
376
195
|
Enabled: false
|
377
196
|
|
378
|
-
|
379
|
-
|
380
|
-
Enabled:
|
381
|
-
|
382
|
-
|
383
|
-
Enabled:
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
Enabled:
|
393
|
-
|
394
|
-
|
395
|
-
Enabled:
|
396
|
-
|
397
|
-
|
398
|
-
Enabled:
|
399
|
-
|
400
|
-
|
401
|
-
Enabled:
|
402
|
-
|
403
|
-
Lint/MixedRegexpCaptureTypes:
|
404
|
-
Enabled: true
|
405
|
-
|
406
|
-
Lint/OutOfRangeRegexpRef:
|
407
|
-
Enabled: true
|
408
|
-
|
409
|
-
Lint/SelfAssignment:
|
410
|
-
Enabled: true
|
411
|
-
|
412
|
-
Lint/TopLevelReturnWithArgument:
|
413
|
-
Enabled: true
|
414
|
-
|
415
|
-
Lint/UnreachableLoop:
|
416
|
-
Enabled: true
|
417
|
-
|
418
|
-
Style/AccessorGrouping:
|
419
|
-
Enabled: true
|
420
|
-
|
421
|
-
Style/ArrayCoercion:
|
422
|
-
Enabled: true
|
423
|
-
|
424
|
-
Style/BisectedAttrAccessor:
|
425
|
-
Enabled: true
|
426
|
-
|
427
|
-
Style/CaseLikeIf:
|
428
|
-
Enabled: true
|
429
|
-
|
430
|
-
Style/EndlessMethod:
|
431
|
-
Enabled: true
|
432
|
-
|
433
|
-
Style/ExplicitBlockArgument:
|
434
|
-
Enabled: true
|
435
|
-
|
436
|
-
Style/FileRead: # new in 1.24
|
437
|
-
Enabled: true
|
438
|
-
|
439
|
-
Style/FileWrite: # new in 1.24
|
440
|
-
Enabled: true
|
441
|
-
|
442
|
-
Style/GlobalStdStream:
|
443
|
-
Enabled: true
|
444
|
-
|
445
|
-
Style/HashAsLastArrayItem:
|
446
|
-
Enabled: true
|
447
|
-
|
448
|
-
Style/HashConversion:
|
449
|
-
Enabled: true
|
450
|
-
|
451
|
-
Style/HashLikeCase:
|
452
|
-
Enabled: true
|
453
|
-
|
454
|
-
Style/IfWithBooleanLiteralBranches:
|
455
|
-
Enabled: true
|
456
|
-
|
457
|
-
Style/MapToHash: # new in 1.24
|
458
|
-
Enabled: true
|
459
|
-
|
460
|
-
Style/OpenStructUse: # new in 1.23
|
461
|
-
Enabled: true
|
462
|
-
|
463
|
-
Style/OptionalBooleanParameter:
|
464
|
-
Enabled: true
|
465
|
-
|
466
|
-
|
467
|
-
Style/RedundantAssignment:
|
468
|
-
Enabled: true
|
469
|
-
|
470
|
-
Style/RedundantFetchBlock:
|
471
|
-
Enabled: true
|
472
|
-
|
473
|
-
Style/RedundantFileExtensionInRequire:
|
474
|
-
Enabled: true
|
475
|
-
|
476
|
-
Style/RedundantRegexpCharacterClass:
|
477
|
-
Enabled: true
|
478
|
-
|
479
|
-
Style/RedundantRegexpEscape:
|
480
|
-
Enabled: true
|
481
|
-
|
482
|
-
Style/SingleArgumentDig:
|
483
|
-
Enabled: true
|
484
|
-
|
485
|
-
Style/SlicingWithRange:
|
486
|
-
Enabled: true
|
487
|
-
|
488
|
-
Style/StringChars:
|
489
|
-
Enabled: true
|
490
|
-
|
491
|
-
Style/StringConcatenation:
|
492
|
-
Enabled: true
|
197
|
+
## Optional rubocop-rspec plugin rule checking
|
198
|
+
#RSpec/ContextWording:
|
199
|
+
# Enabled: false
|
200
|
+
#
|
201
|
+
#RSpec/DescribeClass:
|
202
|
+
# Enabled: false
|
203
|
+
#
|
204
|
+
#RSpec/ExampleLength:
|
205
|
+
# Max: 40
|
206
|
+
#
|
207
|
+
#RSpec/MultipleExpectations:
|
208
|
+
# Max: 25
|
209
|
+
#
|
210
|
+
#RSpec/NoExpectationExample:
|
211
|
+
# Enabled: false
|
212
|
+
#
|
213
|
+
#RSpec/RepeatedDescription:
|
214
|
+
# Enabled: false
|
215
|
+
#
|
216
|
+
#RSpec/RepeatedExample:
|
217
|
+
# Enabled: false
|
218
|
+
#
|
219
|
+
#RSpec/RepeatedExampleGroupDescription:
|
220
|
+
# Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
## [0.4.10] - 2025-0x-xx
|
2
|
+
- Tested with Rley 0.9.02 and Rubocop 1.74
|
3
|
+
|
4
|
+
## [0.4.09] - 2025-01-16
|
5
|
+
- Tested with MRI Ruby 3.4.1.
|
6
|
+
- Minor changes
|
7
|
+
- [NEW] Added `demo` folder
|
8
|
+
- [FIX] Some Rubocop 1.72.0 offences fixed.
|
9
|
+
|
1
10
|
## [0.4.08] - 2022-04-09
|
2
11
|
- Refactoring of the `Scanner` class.
|
3
12
|
|
@@ -14,7 +23,6 @@
|
|
14
23
|
- File `duplicate_local.lox` Fixed typo in error message.
|
15
24
|
- File `duplicate_parameter.lox` Fixed typo in error message.
|
16
25
|
|
17
|
-
|
18
26
|
## [0.4.06] - 2021-11-01
|
19
27
|
- Code update to cope with `Rley` v.0.8.08 changes
|
20
28
|
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -19,8 +19,8 @@ Although __Lox__ is fairly simple, it is far from being a toy language:
|
|
19
19
|
### Loxxy gem features
|
20
20
|
- Complete tree-walking interpreter including lexer, parser and resolver
|
21
21
|
- 100% pure Ruby with clean design (not a port from some other language)
|
22
|
-
- Passes the `
|
23
|
-
- Can run a Lox
|
22
|
+
- Passes the `jlox` (THE reference `Lox` implementation) test suite
|
23
|
+
- Can run a Lox interpreter implemented in ... `Lox` [LoxLox](https://github.com/benhoyt/loxlox),
|
24
24
|
- Minimal runtime dependency (Rley gem). Won't drag a bunch of gems...
|
25
25
|
- Ruby API for integrating a Lox interpreter with your code.
|
26
26
|
- A command-line interpreter `loxxy`
|
@@ -55,7 +55,7 @@ And then execute:
|
|
55
55
|
Create a text file and enter the following lines:
|
56
56
|
```javascript
|
57
57
|
// hello.lox
|
58
|
-
// Your
|
58
|
+
// Your first Lox program
|
59
59
|
print "Hello, world.";
|
60
60
|
```
|
61
61
|
|
@@ -326,7 +326,9 @@ lox_input = <<-LOX_END
|
|
326
326
|
print "Hello, world!";
|
327
327
|
LOX_END
|
328
328
|
|
329
|
-
|
329
|
+
lox = Loxxy::Interpreter.new
|
330
|
+
lox.evaluate(lox_program) # => Hello, world!
|
331
|
+
```
|
330
332
|
|
331
333
|
## Suppported Lox language features
|
332
334
|
|
@@ -47,7 +47,7 @@ module Loxxy
|
|
47
47
|
# Create a new AST builder instance.
|
48
48
|
# @param theTokens [Array<Rley::Lexical::Token>] The sequence of input tokens.
|
49
49
|
def initialize(theTokens)
|
50
|
-
super
|
50
|
+
super
|
51
51
|
@strict = false
|
52
52
|
end
|
53
53
|
|
@@ -188,7 +188,7 @@ module Loxxy
|
|
188
188
|
# rule('varDecl' => 'VAR IDENTIFIER (EQUAL expression)? SEMICOLON')
|
189
189
|
def reduce_var_declaration(_production, _range, tokens, theChildren)
|
190
190
|
var_name = theChildren[1].token.lexeme.dup
|
191
|
-
init_val = theChildren[2]
|
191
|
+
init_val = theChildren[2]&.last
|
192
192
|
Ast::LoxVarStmt.new(tokens[1].position, var_name, init_val)
|
193
193
|
end
|
194
194
|
|
@@ -260,7 +260,7 @@ module Loxxy
|
|
260
260
|
|
261
261
|
# rule('returnStmt' => 'RETURN expression? SEMICOLON')
|
262
262
|
def reduce_return_stmt(_production, _range, tokens, theChildren)
|
263
|
-
ret_expr = theChildren[1]
|
263
|
+
ret_expr = theChildren[1]&.first
|
264
264
|
Ast::LoxReturnStmt.new(tokens[1].position, ret_expr)
|
265
265
|
end
|
266
266
|
|
@@ -446,6 +446,7 @@ module Loxxy
|
|
446
446
|
add_native_fun('print_error', native_print_error)
|
447
447
|
end
|
448
448
|
|
449
|
+
# rubocop: disable Lint/UselessConstantScoping
|
449
450
|
NativeFunction = Struct.new(:callable, :interp) do
|
450
451
|
def accept(_visitor)
|
451
452
|
interp.expr_stack.push self
|
@@ -459,6 +460,7 @@ module Loxxy
|
|
459
460
|
'<native fn>'
|
460
461
|
end
|
461
462
|
end
|
463
|
+
# rubocop: enable Lint/UselessConstantScoping
|
462
464
|
|
463
465
|
def add_native_fun(aName, aProc)
|
464
466
|
native_fun = Variable.new(aName, NativeFunction.new(aProc, self))
|
@@ -178,7 +178,6 @@ module Loxxy
|
|
178
178
|
resolve_local(aThisExpr, aVisitor)
|
179
179
|
end
|
180
180
|
|
181
|
-
# rubocop: disable Style/CaseLikeIf
|
182
181
|
# rubocop: disable Style/StringConcatenation
|
183
182
|
def after_super_expr(aSuperExpr, aVisitor)
|
184
183
|
msg_prefix = "Error at 'super': Can't use 'super' "
|
@@ -195,7 +194,6 @@ module Loxxy
|
|
195
194
|
resolve_local(aSuperExpr, aVisitor)
|
196
195
|
end
|
197
196
|
# rubocop: enable Style/StringConcatenation
|
198
|
-
# rubocop: enable Style/CaseLikeIf
|
199
197
|
|
200
198
|
# function declaration creates a new scope for its body & binds its parameters for that scope
|
201
199
|
def before_fun_stmt(aFunStmt, aVisitor)
|
@@ -63,7 +63,6 @@ module Loxxy
|
|
63
63
|
# one Lox number and a Ruby Numeric
|
64
64
|
# @param other [Loxxy::Datatype::Number, Numeric]
|
65
65
|
# @return [Loxxy::Datatype::Number]
|
66
|
-
# rubocop: disable Lint/BinaryOperatorWithIdenticalOperands
|
67
66
|
def /(other)
|
68
67
|
case other
|
69
68
|
when Number, Numeric
|
@@ -84,7 +83,6 @@ module Loxxy
|
|
84
83
|
raise TypeError, err_msg
|
85
84
|
end
|
86
85
|
end
|
87
|
-
# rubocop: enable Lint/BinaryOperatorWithIdenticalOperands
|
88
86
|
|
89
87
|
# Unary minus (return value with changed sign)
|
90
88
|
# @return [Loxxy::Datatype::Number]
|
@@ -20,14 +20,14 @@ module Loxxy
|
|
20
20
|
# Delimiters: e.g. parentheses '(', ')'
|
21
21
|
# Separators: e.g. comma
|
22
22
|
class Scanner
|
23
|
-
PATT_BLOCK_COMMENT_BEGIN =
|
24
|
-
PATT_BLOCK_COMMENT_END =
|
25
|
-
PATT_COMPARISON = /[!=><]
|
26
|
-
PATT_IDENTIFIER = /[a-zA-Z_][a-zA-Z_0-9]
|
27
|
-
PATT_LINE_COMMENT = /\/\/[^\r\n]
|
28
|
-
PATT_NEWLINE = /(?:\r\n)|\r|\n
|
29
|
-
PATT_NUMBER = /\d+(?:\.\d+)
|
30
|
-
PATT_WHITESPACE = /[ \t\f]
|
23
|
+
PATT_BLOCK_COMMENT_BEGIN = /\/\*/
|
24
|
+
PATT_BLOCK_COMMENT_END = /\*\//
|
25
|
+
PATT_COMPARISON = /[!=><]=?/
|
26
|
+
PATT_IDENTIFIER = /[a-zA-Z_][a-zA-Z_0-9]*/
|
27
|
+
PATT_LINE_COMMENT = /\/\/[^\r\n]*/
|
28
|
+
PATT_NEWLINE = /(?:\r\n)|\r|\n/
|
29
|
+
PATT_NUMBER = /\d+(?:\.\d+)?/
|
30
|
+
PATT_WHITESPACE = /[ \t\f]+/
|
31
31
|
|
32
32
|
# @return [StringScanner] Low-level input scanner
|
33
33
|
attr_reader(:scanner)
|
@@ -67,7 +67,7 @@ module Loxxy
|
|
67
67
|
@@keywords = %w[
|
68
68
|
and class else false fun for if nil or
|
69
69
|
print return super this true var while
|
70
|
-
].
|
70
|
+
].to_h { |x| [x, x] }
|
71
71
|
|
72
72
|
# Single character that have a special meaning when escaped
|
73
73
|
# @return [{Char => String}]
|
@@ -148,7 +148,7 @@ module Loxxy
|
|
148
148
|
elsif (lexeme = scanner.scan(PATT_COMPARISON))
|
149
149
|
# One or two special character tokens
|
150
150
|
build_token(Lexeme2name[lexeme], lexeme)
|
151
|
-
elsif scanner.scan(
|
151
|
+
elsif scanner.scan('"') # Start of string detected...
|
152
152
|
build_string_token
|
153
153
|
elsif (lexeme = scanner.scan(PATT_NUMBER))
|
154
154
|
build_token('NUMBER', lexeme)
|
data/lib/loxxy/interpreter.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative '
|
4
|
-
require_relative '
|
5
|
-
require_relative '
|
3
|
+
require_relative 'front_end/parser'
|
4
|
+
require_relative 'ast/ast_visitor'
|
5
|
+
require_relative 'back_end/engine'
|
6
6
|
|
7
7
|
module Loxxy
|
8
8
|
# A Lox tree-walking interpreter.
|
data/lib/loxxy/version.rb
CHANGED
data/loxxy.gemspec
CHANGED
@@ -10,12 +10,10 @@ module PkgExtending
|
|
10
10
|
file_list = Dir[
|
11
11
|
'.rubocop.yml',
|
12
12
|
'.rspec',
|
13
|
-
'.travis.yml',
|
14
13
|
'.yardopts',
|
15
14
|
'Gemfile',
|
16
15
|
'Rakefile',
|
17
16
|
'CHANGELOG.md',
|
18
|
-
'CODE_OF_CONDUCT.md',
|
19
17
|
'LICENSE.txt',
|
20
18
|
'README.md',
|
21
19
|
'loxxy.gemspec',
|
@@ -44,11 +42,13 @@ Gem::Specification.new do |spec|
|
|
44
42
|
spec.description = <<-DESCR_END
|
45
43
|
A Ruby implementation of the Lox programming language. Lox is a dynamically typed,
|
46
44
|
object-oriented programming language that features first-class functions, closures,
|
47
|
-
classes, and inheritance.
|
45
|
+
classes, and inheritance. The interpreter passes all unit tests from the original Java implementation.
|
46
|
+
It is also able to run `LoxLox` a Lox interpreter written in Lox itself.
|
48
47
|
DESCR_END
|
49
48
|
spec.homepage = 'https://github.com/famished-tiger/loxxy'
|
50
49
|
spec.license = 'MIT'
|
51
|
-
spec.required_ruby_version = '>=
|
50
|
+
spec.required_ruby_version = '>= 3.1'
|
51
|
+
spec.metadata = { 'rubygems_mfa_required' => 'true' }
|
52
52
|
|
53
53
|
spec.bindir = 'bin'
|
54
54
|
spec.executables = ['loxxy']
|
@@ -58,10 +58,10 @@ Gem::Specification.new do |spec|
|
|
58
58
|
PkgExtending.pkg_documentation(spec)
|
59
59
|
|
60
60
|
# Runtime dependencies
|
61
|
-
spec.add_dependency 'rley', '~> 0.
|
61
|
+
spec.add_dependency 'rley', '~> 0.9', '>= 0.9.02'
|
62
62
|
|
63
63
|
# Development dependencies
|
64
|
-
spec.add_development_dependency 'bundler', '~> 2.
|
65
|
-
spec.add_development_dependency 'rake', '~>
|
66
|
-
spec.add_development_dependency 'rspec', '~> 3.0'
|
64
|
+
spec.add_development_dependency 'bundler', '~> 2.4', '>= 2.4.1'
|
65
|
+
spec.add_development_dependency 'rake', '~> 13'
|
66
|
+
spec.add_development_dependency 'rspec', '~> 3', '>= 3.10.0'
|
67
67
|
end
|