loxxy 0.4.01 → 0.4.05
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 +27 -6
- data/CHANGELOG.md +44 -12
- data/lib/loxxy/ast/ast_builder.rb +5 -5
- 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 +2 -5
- 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: 36f3b49ca1158cd6922cb5ece2340f53efec793e5877a96f94aebc0eee34235d
|
|
4
|
+
data.tar.gz: ade953da452fbf9ad6552e8dbfb035161c79c2bffcd0d531c4e79cf6d785c51c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bc0ff7ac6da9846a5a70ead053ceeee2eb390f778a70932392fcbe10ce70c7e147f11983baee96dc5aed924de492d744c3b6b61c8d03f389a74432a56b3916a5
|
|
7
|
+
data.tar.gz: 40e36a53abc6ce121299952ff98f71175198271659f3a7dabf1cbd0f8e79bdc4c76242f47a4707c513f9ca63459bd4495d56de2287136cedb5cadac14ed4fca3
|
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,3 +1,35 @@
|
|
|
1
|
+
## [0.4.05] - 2021-10-10
|
|
2
|
+
- Removal of `Literal` class, code restyling to please Rubocop 1.22
|
|
3
|
+
|
|
4
|
+
### Changed
|
|
5
|
+
- Class `Scanner` remove all dependencies to `Frontend::Literal` class
|
|
6
|
+
- File `.rubocop.yml` added new cops from Rubocop 1.21 and 1.22
|
|
7
|
+
- File `parser_spec.rb` use of parentheses in ambiguous expressions
|
|
8
|
+
- File `raw_parser_spec.rb` use of parentheses in ambiguous expressions
|
|
9
|
+
- File `loxxy.gemspec` forced dependency to Rley 0.8.06
|
|
10
|
+
|
|
11
|
+
## [0.4.04] - 2021-09-11
|
|
12
|
+
- Grammar optimization (3 rules less, use of match_closest feature from `Rley`)
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Method `Ast::AstBuilder#reduce_arguments` code re-styling: use shorthand &:
|
|
16
|
+
- File `grammar.rb` use `match_closest` constraint from Rley to cope with dangling else statement
|
|
17
|
+
|
|
18
|
+
## [0.4.02] - 2021-09-10
|
|
19
|
+
- Fixes in`AST::AstBuilder` class to cope with changes in Rley 0.8.03
|
|
20
|
+
|
|
21
|
+
### Changed
|
|
22
|
+
- File `loxxy.gemspec` forced dependency to Rley 0.8.03
|
|
23
|
+
|
|
24
|
+
### Fixed
|
|
25
|
+
- Method `Ast::AstBuilder#reduce_class_naming` fixed access to `IDENTIFER` in (LESS IDENTIFER)?
|
|
26
|
+
- Method `Ast::AstBuilder#reduce_var_declaration` fixed access to `expression` in (EQUAL expression)?
|
|
27
|
+
- Method `Ast::AstBuilder#reduce_assign_expr`fixed access to `call` in (call DOT)?
|
|
28
|
+
- Method `Ast::AstBuilder#reduce_parameters`fixed access to `IDENTIFIER` in (COMMA IDENTIFIER)*
|
|
29
|
+
- Method `Ast::AstBuilder#reduce_arguments`fixed access to `expression` in (COMMA expression)*
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
1
33
|
## [0.4.01] - 2021-08-22
|
|
2
34
|
- Grammar and AST::AstBuilder adapted to take profit of extended grammar notiation in Rley 0.8.01
|
|
3
35
|
|
|
@@ -53,14 +85,14 @@
|
|
|
53
85
|
- Milestone: `Loxxy` passes all reference test suite.
|
|
54
86
|
|
|
55
87
|
### Fixed
|
|
56
|
-
- Method `BackEnd::Resolver#before_variable_expr`: Standard `Lox` allows re-declaration of a variable at top-level scope
|
|
88
|
+
- Method `BackEnd::Resolver#before_variable_expr`: Standard `Lox` allows re-declaration of a variable at top-level scope
|
|
89
|
+
|
|
57
90
|
|
|
58
|
-
|
|
59
91
|
## [0.2.06] - 2021-05-04
|
|
60
92
|
- Nearly passing the 'official' test suite, fixing non-compliant behavior, specialized exceptions for errors
|
|
61
93
|
|
|
62
94
|
### New
|
|
63
|
-
- Module `LoxFileTester` module that hosts methods that simplify the tests of `Lox` source file.
|
|
95
|
+
- Module `LoxFileTester` module that hosts methods that simplify the tests of `Lox` source file.
|
|
64
96
|
|
|
65
97
|
### Changed
|
|
66
98
|
- Folder `test_suite` vastly reorganized. Sub-folder `baseline` contains spec files testing the `Lox` files from official implementation
|
|
@@ -70,7 +102,7 @@
|
|
|
70
102
|
|
|
71
103
|
### Fixed
|
|
72
104
|
- `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`
|
|
73
|
-
- `FrontEnd::Scanner` now always treats expression like `-123` as the unary or binary minus operator applied to a positive number.
|
|
105
|
+
- `FrontEnd::Scanner` now always treats expression like `-123` as the unary or binary minus operator applied to a positive number.
|
|
74
106
|
|
|
75
107
|
## [0.2.05] - 2021-04-26
|
|
76
108
|
- `Loxxy` now transforms for loops into while loops (desugaring), fix in Scanner class
|
|
@@ -97,7 +129,7 @@
|
|
|
97
129
|
- Method `BackEnd::Resolver#after_for_stmt now accepts nil test expression
|
|
98
130
|
|
|
99
131
|
## [0.2.03] - 2021-04-24
|
|
100
|
-
- Fixes for the set (field) expressions, `accept` methods for AST nodes are meta-programmed
|
|
132
|
+
- Fixes for the set (field) expressions, `accept` methods for AST nodes are meta-programmed
|
|
101
133
|
|
|
102
134
|
### New
|
|
103
135
|
- Module `Ast::Visitee` provides the `define_accept` method that generate `accept` method with meta-programming
|
|
@@ -272,7 +304,7 @@
|
|
|
272
304
|
- Fix and test suite for return statements
|
|
273
305
|
|
|
274
306
|
### CHANGED
|
|
275
|
-
- `Loxxy` reports an error when a return statement occurs in top-level scope
|
|
307
|
+
- `Loxxy` reports an error when a return statement occurs in top-level scope
|
|
276
308
|
|
|
277
309
|
### Fixed
|
|
278
310
|
- A return without explicit value genrated an exception in some cases.
|
|
@@ -296,7 +328,7 @@
|
|
|
296
328
|
- Class `BackEnd::Environment`: added the attributes `predecessor` and `embedding` to support closures.
|
|
297
329
|
- Class `BackeEnd::LoxFunction`: added the attribute `closure` that is equal to the environment where the function is declared.
|
|
298
330
|
- Constructor `BackEnd::LoxFunction#new` now takes a `BackEnd::Engine`as its fourth parameter
|
|
299
|
-
- Methods `BackEnd::SymbolTable#enter_environment`, `BackEnd::SymbolTable#leave_environment` take into account closures.
|
|
331
|
+
- Methods `BackEnd::SymbolTable#enter_environment`, `BackEnd::SymbolTable#leave_environment` take into account closures.
|
|
300
332
|
|
|
301
333
|
### Fixed
|
|
302
334
|
- Method `Ast::AstBuilder#after_var_stmt` now takes into account the value from the top of stack
|
|
@@ -342,7 +374,7 @@
|
|
|
342
374
|
|
|
343
375
|
### Changed
|
|
344
376
|
- File `console` renamed to `loxxy`. Very basic command-line interface.
|
|
345
|
-
- Custom exception classes
|
|
377
|
+
- Custom exception classes
|
|
346
378
|
- File `README.md` updated list of supported `Lox` keywords.
|
|
347
379
|
|
|
348
380
|
|
|
@@ -373,8 +405,8 @@
|
|
|
373
405
|
- Method `Ast::ASTVisitor#visit_fun_stmt` for visiting an `Ast::LoxFunStmt` node
|
|
374
406
|
- Method `Ast::LoxBlockStmt#empty?` returns true if the code block is empty
|
|
375
407
|
- Method `BackEnd::Engine#after_fun_stmt`
|
|
376
|
-
- Method `BackEnd::NativeFunction#call`
|
|
377
|
-
- Method `BackEnd::NativeFunction#to_str`
|
|
408
|
+
- Method `BackEnd::NativeFunction#call`
|
|
409
|
+
- Method `BackEnd::NativeFunction#to_str`
|
|
378
410
|
- Method `BackEnd::LoxFunction` runtime representation of a Lox function.
|
|
379
411
|
|
|
380
412
|
### Changed
|
|
@@ -443,7 +475,7 @@
|
|
|
443
475
|
- Method `Ast::ASTBuilder#reduce_assign_expr` creates an `Ast::LoxAssignExpr` node
|
|
444
476
|
- Method `Ast::ASTVisitor#visit_assign_expr` for visiting an `Ast::LoxAssignExpr` node
|
|
445
477
|
- Method `BackEnd::Engine#after_assign_expr` implementation of the assignment
|
|
446
|
-
- Method `BackEnd::Variable#assign` to assign a value to a variable
|
|
478
|
+
- Method `BackEnd::Variable#assign` to assign a value to a variable
|
|
447
479
|
|
|
448
480
|
## [0.0.23] - 2021-01-20
|
|
449
481
|
- Fix for variables without explicit initialization.
|
|
@@ -713,4 +745,4 @@
|
|
|
713
745
|
|
|
714
746
|
## [0.0.1] - 2020-12-27
|
|
715
747
|
### Added
|
|
716
|
-
- Initial Github commit
|
|
748
|
+
- Initial Github commit
|
|
@@ -164,7 +164,7 @@ module Loxxy
|
|
|
164
164
|
if theChildren[1].nil?
|
|
165
165
|
super_var = nil
|
|
166
166
|
else
|
|
167
|
-
super_token = theChildren[1].
|
|
167
|
+
super_token = theChildren[1].last.token
|
|
168
168
|
super_var = LoxVariableExpr.new(super_token.position, super_token.lexeme)
|
|
169
169
|
end
|
|
170
170
|
[theChildren[0].token.lexeme, super_var]
|
|
@@ -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] ? theChildren[2].
|
|
191
|
+
init_val = theChildren[2] ? theChildren[2].last : nil
|
|
192
192
|
Ast::LoxVarStmt.new(tokens[1].position, var_name, init_val)
|
|
193
193
|
end
|
|
194
194
|
|
|
@@ -286,7 +286,7 @@ module Loxxy
|
|
|
286
286
|
def reduce_assign_expr(_production, _range, tokens, theChildren)
|
|
287
287
|
name_assignee = theChildren[1].token.lexeme.dup
|
|
288
288
|
if theChildren[0]
|
|
289
|
-
set_expr = Ast::LoxSetExpr.new(tokens[1].position, theChildren[0].
|
|
289
|
+
set_expr = Ast::LoxSetExpr.new(tokens[1].position, theChildren[0].first)
|
|
290
290
|
set_expr.property = name_assignee
|
|
291
291
|
set_expr.value = theChildren[3]
|
|
292
292
|
set_expr
|
|
@@ -393,7 +393,7 @@ module Loxxy
|
|
|
393
393
|
first_lexeme = theChildren[0].token.lexeme
|
|
394
394
|
return [first_lexeme] unless theChildren[1]
|
|
395
395
|
|
|
396
|
-
successors = theChildren[1].map { |seq_node| seq_node.
|
|
396
|
+
successors = theChildren[1].map { |seq_node| seq_node.last.token.lexeme }
|
|
397
397
|
successors.unshift(first_lexeme)
|
|
398
398
|
end
|
|
399
399
|
|
|
@@ -401,7 +401,7 @@ module Loxxy
|
|
|
401
401
|
def reduce_arguments(_production, _range, _tokens, theChildren)
|
|
402
402
|
return [theChildren[0]] unless theChildren[1]
|
|
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
|
|
@@ -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.06'
|
|
62
62
|
|
|
63
63
|
# Development dependencies
|
|
64
64
|
spec.add_development_dependency 'bundler', '~> 2.0'
|
|
@@ -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
|
|
|
@@ -81,10 +81,7 @@ LOX_END
|
|
|
81
81
|
expect(decls.subnodes[0].symbol.name).to eq('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.05
|
|
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-10-10 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.06
|
|
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.06
|
|
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
|