loxxy 0.4.02 → 0.4.06
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +27 -6
- data/CHANGELOG.md +47 -17
- data/lib/loxxy/ast/ast_builder.rb +12 -12
- data/lib/loxxy/ast/ast_visitor.rb +0 -1
- data/lib/loxxy/ast/lox_call_expr.rb +1 -1
- data/lib/loxxy/ast/lox_return_stmt.rb +1 -1
- data/lib/loxxy/front_end/grammar.rb +3 -7
- data/lib/loxxy/front_end/scanner.rb +2 -3
- data/lib/loxxy/version.rb +1 -1
- data/loxxy.gemspec +1 -1
- data/spec/front_end/parser_spec.rb +1 -1
- data/spec/front_end/raw_parser_spec.rb +5 -8
- data/spec/front_end/scanner_spec.rb +7 -7
- metadata +4 -5
- data/lib/loxxy/front_end/literal.rb +0 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c0b12b86ba7c949cf712d97fed6691b087f97284e3580124680b773df3be5347
|
4
|
+
data.tar.gz: f19231c3e1372525e418fd155f23f71ef84c5fbcb9283eeef11709d4a321408f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d0f0829b465d2ffb3cd7f287efb9a069ae0c94ddc95f89790f6e1f1d6519aed4dfccb5359d95130afff4cd69d70953983ef25f02f89529789f9bd2ca1bd18c9a
|
7
|
+
data.tar.gz: 908ca8e78dbf30ff582a545d542b58b4080a98feab8a035582ea3dd09a5e2533f255cbc7bc531b143d21bd2b0a23d8ea3b0eed0b6007cc35eea005cfc564de61
|
data/.rubocop.yml
CHANGED
@@ -84,6 +84,9 @@ Layout/TrailingWhitespace:
|
|
84
84
|
Lint/AmbiguousAssignment:
|
85
85
|
Enabled: true
|
86
86
|
|
87
|
+
Lint/AmbiguousOperatorPrecedence: # new in 1.21
|
88
|
+
Enabled: true
|
89
|
+
|
87
90
|
Lint/AmbiguousRange:
|
88
91
|
Enabled: true
|
89
92
|
|
@@ -105,6 +108,9 @@ Lint/EmptyClass:
|
|
105
108
|
Lint/EmptyInPattern:
|
106
109
|
Enabled: true
|
107
110
|
|
111
|
+
Lint/IncompatibleIoSelectWithFiberScheduler: # new in 1.21
|
112
|
+
Enabled: true
|
113
|
+
|
108
114
|
Lint/LambdaWithoutLiteralBlock:
|
109
115
|
Enabled: true
|
110
116
|
|
@@ -126,6 +132,9 @@ Lint/RaiseException:
|
|
126
132
|
Lint/RedundantDirGlobSort:
|
127
133
|
Enabled: true
|
128
134
|
|
135
|
+
Lint/RequireRelativeSelfPath: # new in 1.22
|
136
|
+
Enabled: true
|
137
|
+
|
129
138
|
Lint/RescueException:
|
130
139
|
Enabled: true
|
131
140
|
|
@@ -213,6 +222,9 @@ Naming/MethodName:
|
|
213
222
|
Naming/VariableName:
|
214
223
|
Enabled: false
|
215
224
|
|
225
|
+
Security/IoMethods: # new in 1.22
|
226
|
+
Enabled: true
|
227
|
+
|
216
228
|
Style/Alias:
|
217
229
|
Enabled: true
|
218
230
|
|
@@ -293,9 +305,9 @@ Style/InverseMethods:
|
|
293
305
|
|
294
306
|
Style/MissingRespondToMissing:
|
295
307
|
Enabled: false
|
296
|
-
|
308
|
+
|
297
309
|
Style/MultilineInPatternThen:
|
298
|
-
Enabled: true
|
310
|
+
Enabled: true
|
299
311
|
|
300
312
|
Style/NegatedIfElseCondition:
|
301
313
|
Enabled: true
|
@@ -306,11 +318,17 @@ Style/Next:
|
|
306
318
|
Style/NilLambda:
|
307
319
|
Enabled: true
|
308
320
|
|
321
|
+
Style/NumberedParameters: # new in 1.22
|
322
|
+
Enabled: true
|
323
|
+
|
324
|
+
Style/NumberedParametersLimit: # new in 1.22
|
325
|
+
Enabled: true
|
326
|
+
|
309
327
|
Style/NumericLiterals:
|
310
328
|
Enabled: false
|
311
|
-
|
329
|
+
|
312
330
|
Style/QuotedSymbols:
|
313
|
-
Enabled: true
|
331
|
+
Enabled: true
|
314
332
|
|
315
333
|
Style/RaiseArgs:
|
316
334
|
Enabled: true
|
@@ -323,9 +341,9 @@ Style/RedundantReturn:
|
|
323
341
|
|
324
342
|
Style/RedundantSelf:
|
325
343
|
Enabled: true
|
326
|
-
|
344
|
+
|
327
345
|
Style/RedundantSelfAssignmentBranch:
|
328
|
-
Enabled: true
|
346
|
+
Enabled: true
|
329
347
|
|
330
348
|
Style/RegexpLiteral:
|
331
349
|
Enabled: false
|
@@ -333,6 +351,9 @@ Style/RegexpLiteral:
|
|
333
351
|
Style/PercentLiteralDelimiters:
|
334
352
|
Enabled: false
|
335
353
|
|
354
|
+
Style/SelectByRegexp: # new in 1.22
|
355
|
+
Enabled: true
|
356
|
+
|
336
357
|
Style/StderrPuts:
|
337
358
|
Enabled: false
|
338
359
|
|
data/CHANGELOG.md
CHANGED
@@ -1,15 +1,45 @@
|
|
1
|
+
## [0.4.06] - 2021-11-01
|
2
|
+
- Code update to cope with `Rley` v.0.8.08 changes
|
3
|
+
|
4
|
+
### Changed
|
5
|
+
- File `AST::AstBuilder` some `reduce_` to cope implementation change of ? quantifier
|
6
|
+
- Method `AST::LoxCallExpr#initialize` call to `Array#flatten` with argList argument
|
7
|
+
- File `loxxy.gemspec` dependency towards `rely` minimal version number is now `0.8.08`
|
8
|
+
- Some spec files updated after `rley` changes of ?, *, + quantifiers
|
9
|
+
|
10
|
+
### Removed
|
11
|
+
- File `front_end/literal.rb`: obsolete
|
12
|
+
|
13
|
+
|
14
|
+
## [0.4.05] - 2021-10-10
|
15
|
+
- Removal of `Literal` class, code restyling to please Rubocop 1.22
|
16
|
+
|
17
|
+
### Changed
|
18
|
+
- Class `Scanner` remove all dependencies to `Frontend::Literal` class
|
19
|
+
- File `.rubocop.yml` added new cops from Rubocop 1.21 and 1.22
|
20
|
+
- File `parser_spec.rb` use of parentheses in ambiguous expressions
|
21
|
+
- File `raw_parser_spec.rb` use of parentheses in ambiguous expressions
|
22
|
+
- File `loxxy.gemspec` forced dependency to Rley 0.8.06
|
23
|
+
|
24
|
+
## [0.4.04] - 2021-09-11
|
25
|
+
- Grammar optimization (3 rules less, use of match_closest feature from `Rley`)
|
26
|
+
|
27
|
+
### Changed
|
28
|
+
- Method `Ast::AstBuilder#reduce_arguments` code re-styling: use shorthand &:
|
29
|
+
- File `grammar.rb` use `match_closest` constraint from Rley to cope with dangling else statement
|
30
|
+
|
1
31
|
## [0.4.02] - 2021-09-10
|
2
|
-
- Fixes in`AST::AstBuilder` class to
|
32
|
+
- Fixes in`AST::AstBuilder` class to cope with changes in Rley 0.8.03
|
3
33
|
|
4
34
|
### Changed
|
5
35
|
- File `loxxy.gemspec` forced dependency to Rley 0.8.03
|
6
36
|
|
7
37
|
### Fixed
|
8
38
|
- Method `Ast::AstBuilder#reduce_class_naming` fixed access to `IDENTIFER` in (LESS IDENTIFER)?
|
9
|
-
- Method `Ast::AstBuilder#reduce_var_declaration` fixed access to `expression` in (EQUAL expression)?
|
10
|
-
- Method `Ast::AstBuilder#reduce_assign_expr`fixed access to `call` in (call DOT)?
|
11
|
-
- Method `Ast::AstBuilder#reduce_parameters`fixed access to `IDENTIFIER` in (COMMA IDENTIFIER)*
|
12
|
-
- Method `Ast::AstBuilder#reduce_arguments`fixed access to `expression` in (COMMA expression)*
|
39
|
+
- Method `Ast::AstBuilder#reduce_var_declaration` fixed access to `expression` in (EQUAL expression)?
|
40
|
+
- Method `Ast::AstBuilder#reduce_assign_expr`fixed access to `call` in (call DOT)?
|
41
|
+
- Method `Ast::AstBuilder#reduce_parameters`fixed access to `IDENTIFIER` in (COMMA IDENTIFIER)*
|
42
|
+
- Method `Ast::AstBuilder#reduce_arguments`fixed access to `expression` in (COMMA expression)*
|
13
43
|
|
14
44
|
|
15
45
|
|
@@ -68,14 +98,14 @@
|
|
68
98
|
- Milestone: `Loxxy` passes all reference test suite.
|
69
99
|
|
70
100
|
### Fixed
|
71
|
-
- Method `BackEnd::Resolver#before_variable_expr`: Standard `Lox` allows re-declaration of a variable at top-level scope
|
101
|
+
- Method `BackEnd::Resolver#before_variable_expr`: Standard `Lox` allows re-declaration of a variable at top-level scope
|
102
|
+
|
72
103
|
|
73
|
-
|
74
104
|
## [0.2.06] - 2021-05-04
|
75
105
|
- Nearly passing the 'official' test suite, fixing non-compliant behavior, specialized exceptions for errors
|
76
106
|
|
77
107
|
### New
|
78
|
-
- Module `LoxFileTester` module that hosts methods that simplify the tests of `Lox` source file.
|
108
|
+
- Module `LoxFileTester` module that hosts methods that simplify the tests of `Lox` source file.
|
79
109
|
|
80
110
|
### Changed
|
81
111
|
- Folder `test_suite` vastly reorganized. Sub-folder `baseline` contains spec files testing the `Lox` files from official implementation
|
@@ -85,7 +115,7 @@
|
|
85
115
|
|
86
116
|
### Fixed
|
87
117
|
- `0/0` expression results in a ZeroDivisionError exception, in Lox this result to a NaN (Not a Number). Now, `Loxxy` is aligned to standard `Lox`
|
88
|
-
- `FrontEnd::Scanner` now always treats expression like `-123` as the unary or binary minus operator applied to a positive number.
|
118
|
+
- `FrontEnd::Scanner` now always treats expression like `-123` as the unary or binary minus operator applied to a positive number.
|
89
119
|
|
90
120
|
## [0.2.05] - 2021-04-26
|
91
121
|
- `Loxxy` now transforms for loops into while loops (desugaring), fix in Scanner class
|
@@ -112,7 +142,7 @@
|
|
112
142
|
- Method `BackEnd::Resolver#after_for_stmt now accepts nil test expression
|
113
143
|
|
114
144
|
## [0.2.03] - 2021-04-24
|
115
|
-
- Fixes for the set (field) expressions, `accept` methods for AST nodes are meta-programmed
|
145
|
+
- Fixes for the set (field) expressions, `accept` methods for AST nodes are meta-programmed
|
116
146
|
|
117
147
|
### New
|
118
148
|
- Module `Ast::Visitee` provides the `define_accept` method that generate `accept` method with meta-programming
|
@@ -287,7 +317,7 @@
|
|
287
317
|
- Fix and test suite for return statements
|
288
318
|
|
289
319
|
### CHANGED
|
290
|
-
- `Loxxy` reports an error when a return statement occurs in top-level scope
|
320
|
+
- `Loxxy` reports an error when a return statement occurs in top-level scope
|
291
321
|
|
292
322
|
### Fixed
|
293
323
|
- A return without explicit value genrated an exception in some cases.
|
@@ -311,7 +341,7 @@
|
|
311
341
|
- Class `BackEnd::Environment`: added the attributes `predecessor` and `embedding` to support closures.
|
312
342
|
- Class `BackeEnd::LoxFunction`: added the attribute `closure` that is equal to the environment where the function is declared.
|
313
343
|
- Constructor `BackEnd::LoxFunction#new` now takes a `BackEnd::Engine`as its fourth parameter
|
314
|
-
- Methods `BackEnd::SymbolTable#enter_environment`, `BackEnd::SymbolTable#leave_environment` take into account closures.
|
344
|
+
- Methods `BackEnd::SymbolTable#enter_environment`, `BackEnd::SymbolTable#leave_environment` take into account closures.
|
315
345
|
|
316
346
|
### Fixed
|
317
347
|
- Method `Ast::AstBuilder#after_var_stmt` now takes into account the value from the top of stack
|
@@ -357,7 +387,7 @@
|
|
357
387
|
|
358
388
|
### Changed
|
359
389
|
- File `console` renamed to `loxxy`. Very basic command-line interface.
|
360
|
-
- Custom exception classes
|
390
|
+
- Custom exception classes
|
361
391
|
- File `README.md` updated list of supported `Lox` keywords.
|
362
392
|
|
363
393
|
|
@@ -388,8 +418,8 @@
|
|
388
418
|
- Method `Ast::ASTVisitor#visit_fun_stmt` for visiting an `Ast::LoxFunStmt` node
|
389
419
|
- Method `Ast::LoxBlockStmt#empty?` returns true if the code block is empty
|
390
420
|
- Method `BackEnd::Engine#after_fun_stmt`
|
391
|
-
- Method `BackEnd::NativeFunction#call`
|
392
|
-
- Method `BackEnd::NativeFunction#to_str`
|
421
|
+
- Method `BackEnd::NativeFunction#call`
|
422
|
+
- Method `BackEnd::NativeFunction#to_str`
|
393
423
|
- Method `BackEnd::LoxFunction` runtime representation of a Lox function.
|
394
424
|
|
395
425
|
### Changed
|
@@ -458,7 +488,7 @@
|
|
458
488
|
- Method `Ast::ASTBuilder#reduce_assign_expr` creates an `Ast::LoxAssignExpr` node
|
459
489
|
- Method `Ast::ASTVisitor#visit_assign_expr` for visiting an `Ast::LoxAssignExpr` node
|
460
490
|
- Method `BackEnd::Engine#after_assign_expr` implementation of the assignment
|
461
|
-
- Method `BackEnd::Variable#assign` to assign a value to a variable
|
491
|
+
- Method `BackEnd::Variable#assign` to assign a value to a variable
|
462
492
|
|
463
493
|
## [0.0.23] - 2021-01-20
|
464
494
|
- Fix for variables without explicit initialization.
|
@@ -728,4 +758,4 @@
|
|
728
758
|
|
729
759
|
## [0.0.1] - 2020-12-27
|
730
760
|
### Added
|
731
|
-
- Initial Github commit
|
761
|
+
- Initial Github commit
|
@@ -222,10 +222,8 @@ module Loxxy
|
|
222
222
|
if test.nil? && update
|
223
223
|
# when test expr is nil but update expr is not, then force test to be true
|
224
224
|
test = LoxLiteralExpr.new(tokens[0].position, Datatype::True.instance)
|
225
|
-
[init, test, update]
|
226
|
-
else
|
227
|
-
theChildren
|
228
225
|
end
|
226
|
+
[init, test, update&.first]
|
229
227
|
end
|
230
228
|
|
231
229
|
# rule('forInitialization' => 'SEMICOLON')
|
@@ -234,8 +232,8 @@ module Loxxy
|
|
234
232
|
end
|
235
233
|
|
236
234
|
# rule('forTest' => 'expression? SEMICOLON')
|
237
|
-
def reduce_for_test(_production,
|
238
|
-
|
235
|
+
def reduce_for_test(_production, _range, _tokens, theChildren)
|
236
|
+
theChildren[0]&.first
|
239
237
|
end
|
240
238
|
|
241
239
|
# rule('ifStmt' => 'IF ifCondition statement ELSE statement')
|
@@ -262,7 +260,8 @@ module Loxxy
|
|
262
260
|
|
263
261
|
# rule('returnStmt' => 'RETURN expression? SEMICOLON')
|
264
262
|
def reduce_return_stmt(_production, _range, tokens, theChildren)
|
265
|
-
|
263
|
+
ret_expr = theChildren[1].nil? ? nil : theChildren[1].first
|
264
|
+
Ast::LoxReturnStmt.new(tokens[1].position, ret_expr)
|
266
265
|
end
|
267
266
|
|
268
267
|
# rule('whileStmt' => 'WHILE LEFT_PAREN expression RIGHT_PAREN statement').as ''
|
@@ -275,7 +274,7 @@ module Loxxy
|
|
275
274
|
decls = nil
|
276
275
|
if theChildren[1]
|
277
276
|
pos = tokens[1].position
|
278
|
-
decls = LoxSeqDecl.new(
|
277
|
+
decls = LoxSeqDecl.new(pos, theChildren[1].flatten)
|
279
278
|
else
|
280
279
|
pos = tokens[0].position
|
281
280
|
end
|
@@ -377,15 +376,16 @@ module Loxxy
|
|
377
376
|
LoxSuperExpr.new(theChildren[0].token.position, theChildren[2].token.lexeme)
|
378
377
|
end
|
379
378
|
|
380
|
-
# rule('function' => 'IDENTIFIER LEFT_PAREN
|
379
|
+
# rule('function' => 'IDENTIFIER LEFT_PAREN parameters? RIGHT_PAREN block').as 'function'
|
381
380
|
def reduce_function(_production, _range, _tokens, theChildren)
|
382
381
|
first_child = theChildren.first
|
383
382
|
pos = first_child.token.position
|
384
|
-
|
383
|
+
params = theChildren[2] ? theChildren[2].flatten : []
|
384
|
+
if params.size > 255
|
385
385
|
msg = "Can't have more than 255 parameters."
|
386
386
|
raise Loxxy::SyntaxError, msg
|
387
387
|
end
|
388
|
-
LoxFunStmt.new(pos, first_child.token.lexeme,
|
388
|
+
LoxFunStmt.new(pos, first_child.token.lexeme, params, theChildren[4])
|
389
389
|
end
|
390
390
|
|
391
391
|
# rule('parameters' => 'IDENTIFIER (COMMA IDENTIFIER)*').as 'parameters'
|
@@ -399,9 +399,9 @@ module Loxxy
|
|
399
399
|
|
400
400
|
# rule('arguments' => 'expression (COMMA expression)*')
|
401
401
|
def reduce_arguments(_production, _range, _tokens, theChildren)
|
402
|
-
return [theChildren[0]]
|
402
|
+
return [theChildren[0]] if theChildren[1].empty?
|
403
403
|
|
404
|
-
successors = theChildren[1].map
|
404
|
+
successors = theChildren[1].map(&:last)
|
405
405
|
successors.unshift(theChildren[0])
|
406
406
|
end
|
407
407
|
end # class
|
@@ -12,7 +12,7 @@ module Loxxy
|
|
12
12
|
# @param argList [Array<Loxxy::Ast::LoxNode>]
|
13
13
|
def initialize(aPosition, argList)
|
14
14
|
super(aPosition, [])
|
15
|
-
@arguments = argList
|
15
|
+
@arguments = argList.flatten
|
16
16
|
end
|
17
17
|
|
18
18
|
define_accept # Add `accept` method as found in Visitor design pattern
|
@@ -6,7 +6,7 @@ module Loxxy
|
|
6
6
|
module Ast
|
7
7
|
class LoxReturnStmt < LoxCompoundExpr
|
8
8
|
# @param aPosition [Rley::Lexical::Position] Position of the entry in the input stream.
|
9
|
-
# @param anExpression [Ast::LoxNode] expression to return
|
9
|
+
# @param anExpression [Ast::LoxNode, NilClass] expression to return
|
10
10
|
def initialize(aPosition, anExpression)
|
11
11
|
expr = anExpression || Datatype::Nil.instance
|
12
12
|
super(aPosition, [expr])
|
@@ -1,6 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
3
|
require 'rley' # Load the gem
|
5
4
|
|
6
5
|
module Loxxy
|
@@ -32,7 +31,7 @@ module Loxxy
|
|
32
31
|
rule('declaration' => 'classDecl')
|
33
32
|
rule('declaration' => 'funDecl')
|
34
33
|
rule('declaration' => 'varDecl')
|
35
|
-
rule('declaration' => '
|
34
|
+
rule('declaration' => 'statement')
|
36
35
|
|
37
36
|
rule('classDecl' => 'CLASS classNaming class_body').as 'class_decl'
|
38
37
|
rule('classNaming' => 'IDENTIFIER (LESS IDENTIFIER)?').as 'class_naming'
|
@@ -43,8 +42,6 @@ module Loxxy
|
|
43
42
|
rule('varDecl' => 'VAR IDENTIFIER (EQUAL expression)? SEMICOLON').as 'var_declaration'
|
44
43
|
|
45
44
|
# Statements: produce side effects, but don't introduce bindings
|
46
|
-
rule('stmt' => 'statement')
|
47
|
-
rule('stmt' => 'unbalancedStmt') # Tweak to cope with "dangling else" problem
|
48
45
|
rule('statement' => 'exprStmt')
|
49
46
|
rule('statement' => 'forStmt')
|
50
47
|
rule('statement' => 'ifStmt')
|
@@ -62,9 +59,8 @@ module Loxxy
|
|
62
59
|
rule('forInitialization' => 'SEMICOLON').as 'empty_for_initialization'
|
63
60
|
rule('forTest' => 'expression? SEMICOLON').as 'for_test'
|
64
61
|
|
65
|
-
rule('ifStmt' => 'IF ifCondition statement ELSE statement').as 'if_else_stmt'
|
66
|
-
rule('
|
67
|
-
rule('unbalancedStmt' => 'IF ifCondition statement ELSE unbalancedStmt').as 'if_else_stmt'
|
62
|
+
rule('ifStmt' => 'IF ifCondition statement ELSE {match_closest: "IF"} statement').as 'if_else_stmt'
|
63
|
+
rule('ifStmt' => 'IF ifCondition statement').as 'if_stmt'
|
68
64
|
rule('ifCondition' => 'LEFT_PAREN expression RIGHT_PAREN').as 'keep_symbol2'
|
69
65
|
|
70
66
|
rule('printStmt' => 'PRINT expression SEMICOLON').as 'print_stmt'
|
@@ -4,7 +4,6 @@ require 'strscan'
|
|
4
4
|
require 'rley'
|
5
5
|
require_relative '../error'
|
6
6
|
require_relative '../datatype/all_datatypes'
|
7
|
-
require_relative 'literal'
|
8
7
|
|
9
8
|
module Loxxy
|
10
9
|
module FrontEnd
|
@@ -142,7 +141,7 @@ module Loxxy
|
|
142
141
|
col = scanner.pos - lex_length - @line_start + 1
|
143
142
|
pos = Rley::Lexical::Position.new(@lineno, col)
|
144
143
|
if value
|
145
|
-
token = Literal.new(value, aLexeme.dup, symb, pos)
|
144
|
+
token = Rley::Lexical::Literal.new(value, aLexeme.dup, symb, pos)
|
146
145
|
else
|
147
146
|
token = Rley::Lexical::Token.new(aLexeme.dup, symb, pos)
|
148
147
|
end
|
@@ -212,7 +211,7 @@ module Loxxy
|
|
212
211
|
pos = Rley::Lexical::Position.new(line, column_start)
|
213
212
|
lox_string = Datatype::LXString.new(literal)
|
214
213
|
lexeme = scanner.string[scan_pos - 1..scanner.pos - 1]
|
215
|
-
Literal.new(lox_string, lexeme, 'STRING', pos)
|
214
|
+
Rley::Lexical::Literal.new(lox_string, lexeme, 'STRING', pos)
|
216
215
|
end
|
217
216
|
|
218
217
|
# Skip non-significant whitespaces and comments.
|
data/lib/loxxy/version.rb
CHANGED
data/loxxy.gemspec
CHANGED
@@ -58,7 +58,7 @@ Gem::Specification.new do |spec|
|
|
58
58
|
PkgExtending.pkg_documentation(spec)
|
59
59
|
|
60
60
|
# Runtime dependencies
|
61
|
-
spec.add_dependency 'rley', '~> 0.8.
|
61
|
+
spec.add_dependency 'rley', '~> 0.8.08'
|
62
62
|
|
63
63
|
# Development dependencies
|
64
64
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
@@ -28,7 +28,7 @@ module Loxxy
|
|
28
28
|
expect(aParseTree.root.symbol.name).to eq('program')
|
29
29
|
(decls, eof) = aParseTree.root.subnodes
|
30
30
|
expect(decls).to be_kind_of(Rley::PTree::NonTerminalNode)
|
31
|
-
expect(decls.symbol.name).to eq('
|
31
|
+
expect(decls.symbol.name).to eq('rep_declaration_star')
|
32
32
|
expect(decls.subnodes).to be_empty
|
33
33
|
expect(eof).to be_kind_of(Rley::PTree::TerminalNode)
|
34
34
|
expect(eof.symbol.name).to eq('EOF')
|
@@ -40,7 +40,7 @@ module Loxxy
|
|
40
40
|
end
|
41
41
|
|
42
42
|
it 'should cope with whitespaces only input' do
|
43
|
-
ptree = subject.parse(' ' * 80 + "\n" * 20)
|
43
|
+
ptree = subject.parse((' ' * 80) + ("\n" * 20))
|
44
44
|
check_empty_input_result(ptree)
|
45
45
|
end
|
46
46
|
|
@@ -76,15 +76,12 @@ LOX_END
|
|
76
76
|
expect(root.symbol.name).to eq('program')
|
77
77
|
(decls, eof) = root.subnodes
|
78
78
|
expect(decls).to be_kind_of(Rley::PTree::NonTerminalNode)
|
79
|
-
expect(decls.symbol.name).to eq('
|
79
|
+
expect(decls.symbol.name).to eq('rep_declaration_star')
|
80
80
|
expect(decls.subnodes[0]).to be_kind_of(Rley::PTree::NonTerminalNode)
|
81
|
-
expect(decls.subnodes[0].symbol.name).to eq('
|
81
|
+
expect(decls.subnodes[0].symbol.name).to eq('rep_declaration_star')
|
82
82
|
expect(decls.subnodes[1]).to be_kind_of(Rley::PTree::NonTerminalNode)
|
83
83
|
expect(decls.subnodes[1].symbol.name).to eq('declaration')
|
84
|
-
|
85
|
-
expect(stmt).to be_kind_of(Rley::PTree::NonTerminalNode)
|
86
|
-
expect(stmt.symbol.name).to eq('stmt')
|
87
|
-
statement = stmt.subnodes[0]
|
84
|
+
statement = decls.subnodes[1].subnodes[0]
|
88
85
|
expect(statement).to be_kind_of(Rley::PTree::NonTerminalNode)
|
89
86
|
expect(statement.symbol.name).to eq('statement')
|
90
87
|
prnt_stmt = statement.subnodes[0]
|
@@ -105,7 +105,7 @@ LOX_END
|
|
105
105
|
it 'should recognize a false boolean token' do
|
106
106
|
subject.start_with('false')
|
107
107
|
token_false = subject.tokens[0]
|
108
|
-
expect(token_false).to be_kind_of(Literal)
|
108
|
+
expect(token_false).to be_kind_of(Rley::Lexical::Literal)
|
109
109
|
expect(token_false.terminal).to eq('FALSE')
|
110
110
|
expect(token_false.lexeme).to eq('false')
|
111
111
|
expect(token_false.value).to be_kind_of(Datatype::False)
|
@@ -115,7 +115,7 @@ LOX_END
|
|
115
115
|
it 'should recognize a true boolean token' do
|
116
116
|
subject.start_with('true')
|
117
117
|
token_true = subject.tokens[0]
|
118
|
-
expect(token_true).to be_kind_of(Literal)
|
118
|
+
expect(token_true).to be_kind_of(Rley::Lexical::Literal)
|
119
119
|
expect(token_true.terminal).to eq('TRUE')
|
120
120
|
expect(token_true.lexeme).to eq('true')
|
121
121
|
expect(token_true.value).to be_kind_of(Datatype::True)
|
@@ -137,7 +137,7 @@ LOX_END
|
|
137
137
|
|
138
138
|
subject.start_with(input)
|
139
139
|
subject.tokens[0..-2].each_with_index do |tok, i|
|
140
|
-
expect(tok).to be_kind_of(Literal)
|
140
|
+
expect(tok).to be_kind_of(Rley::Lexical::Literal)
|
141
141
|
expect(tok.terminal).to eq('NUMBER')
|
142
142
|
(lexeme, val) = expectations[i]
|
143
143
|
expect(tok.lexeme).to eq(lexeme)
|
@@ -177,10 +177,10 @@ LOX_END
|
|
177
177
|
tokens = subject.tokens[0..-2]
|
178
178
|
expect(tokens[0]).to be_kind_of(Rley::Lexical::Token)
|
179
179
|
expect(tokens[0].terminal).to eq('DOT')
|
180
|
-
expect(tokens[1]).to be_kind_of(Literal)
|
180
|
+
expect(tokens[1]).to be_kind_of(Rley::Lexical::Literal)
|
181
181
|
expect(tokens[1].terminal).to eq('NUMBER')
|
182
182
|
expect(tokens[1].value.value).to eq(456)
|
183
|
-
expect(tokens[2]).to be_kind_of(Literal)
|
183
|
+
expect(tokens[2]).to be_kind_of(Rley::Lexical::Literal)
|
184
184
|
expect(tokens[2].terminal).to eq('NUMBER')
|
185
185
|
expect(tokens[2].value.value).to eq(123)
|
186
186
|
expect(tokens[3]).to be_kind_of(Rley::Lexical::Token)
|
@@ -202,7 +202,7 @@ LOX_END
|
|
202
202
|
|
203
203
|
subject.start_with(input)
|
204
204
|
subject.tokens[0..-2].each_with_index do |str, i|
|
205
|
-
expect(str).to be_kind_of(Literal)
|
205
|
+
expect(str).to be_kind_of(Rley::Lexical::Literal)
|
206
206
|
expect(str.terminal).to eq('STRING')
|
207
207
|
val = expectations[i]
|
208
208
|
expect(str.value).to be_kind_of(Datatype::LXString)
|
@@ -236,7 +236,7 @@ LOX_END
|
|
236
236
|
it 'should recognize a nil token' do
|
237
237
|
subject.start_with('nil')
|
238
238
|
token_nil = subject.tokens[0]
|
239
|
-
expect(token_nil).to be_kind_of(Literal)
|
239
|
+
expect(token_nil).to be_kind_of(Rley::Lexical::Literal)
|
240
240
|
expect(token_nil.terminal).to eq('NIL')
|
241
241
|
expect(token_nil.lexeme).to eq('nil')
|
242
242
|
expect(token_nil.value).to be_kind_of(Datatype::Nil)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loxxy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.06
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dimitri Geshef
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rley
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.8.
|
19
|
+
version: 0.8.08
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.8.
|
26
|
+
version: 0.8.08
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -139,7 +139,6 @@ files:
|
|
139
139
|
- lib/loxxy/datatype/true.rb
|
140
140
|
- lib/loxxy/error.rb
|
141
141
|
- lib/loxxy/front_end/grammar.rb
|
142
|
-
- lib/loxxy/front_end/literal.rb
|
143
142
|
- lib/loxxy/front_end/parser.rb
|
144
143
|
- lib/loxxy/front_end/raw_parser.rb
|
145
144
|
- lib/loxxy/front_end/scanner.rb
|
@@ -1,25 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rley'
|
4
|
-
|
5
|
-
module Loxxy
|
6
|
-
module FrontEnd
|
7
|
-
# The superclass for all tokens that have a data value.
|
8
|
-
class Literal < Rley::Lexical::Token
|
9
|
-
# @return [Datatype] The value expressed in one of the Lox datatype.
|
10
|
-
attr_reader :value
|
11
|
-
|
12
|
-
# Constructor.
|
13
|
-
# @param aValue [Datatype::BuiltinDatatype] the Lox data value
|
14
|
-
# @param aLexeme [String] the lexeme (= piece of text from input)
|
15
|
-
# @param aTerminal [Rley::Syntax::Terminal, String]
|
16
|
-
# The terminal symbol corresponding to the lexeme.
|
17
|
-
# @param aPosition [Rley::Lexical::Position] The position of lexeme
|
18
|
-
# in input text.
|
19
|
-
def initialize(aValue, aLexeme, aTerminal, aPosition)
|
20
|
-
super(aLexeme, aTerminal, aPosition)
|
21
|
-
@value = aValue
|
22
|
-
end
|
23
|
-
end # class
|
24
|
-
end # module
|
25
|
-
end # module
|