kumi-parser 0.0.8 → 0.0.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/lib/kumi/parser/direct_parser.rb +19 -1
- data/lib/kumi/parser/smart_tokenizer.rb +24 -0
- data/lib/kumi/parser/token_metadata.rb +6 -0
- data/lib/kumi/parser/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2cb46dec6261ef8c66346abb17f188c36a21c97322415ac6315adc3347214c3
|
4
|
+
data.tar.gz: 4cad59a51d06aaca85b1343ac520cdf28e5a82255df891fbb0086d4b11e35d98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0505e71430dd3593356318dc4262e3b79487d9eea3aceb7fd19fbd189d9c5c0593d937eebd9727206d6640d0d280eede4a8378058de11858e83f05467d46aaa
|
7
|
+
data.tar.gz: 904e451757c5beeaa13f0a27c53477dcd5729abd678e08713f150e7d03a9a7fb3e5b948f7a62d8deed1ef38905214bebfe99881758bb92a2d8faf68ece50364e
|
@@ -335,7 +335,7 @@ module Kumi
|
|
335
335
|
token = current_token
|
336
336
|
|
337
337
|
case token.type
|
338
|
-
when :integer, :float, :string, :boolean
|
338
|
+
when :integer, :float, :string, :boolean, :constant
|
339
339
|
# Direct AST construction using token metadata
|
340
340
|
value = convert_literal_value(token)
|
341
341
|
advance
|
@@ -373,6 +373,18 @@ module Kumi
|
|
373
373
|
when :fn
|
374
374
|
parse_function_call_from_fn_token
|
375
375
|
|
376
|
+
when :subtract
|
377
|
+
# Handle unary minus operator: -expression
|
378
|
+
advance # consume '-'
|
379
|
+
skip_comments_and_newlines
|
380
|
+
operand = parse_primary_expression
|
381
|
+
# Convert to subtraction from zero: (subtract 0 operand)
|
382
|
+
Kumi::Syntax::CallExpression.new(
|
383
|
+
:subtract,
|
384
|
+
[Kumi::Syntax::Literal.new(0, loc: token.location), operand],
|
385
|
+
loc: token.location
|
386
|
+
)
|
387
|
+
|
376
388
|
when :newline, :comment
|
377
389
|
# Skip newlines and comments in expressions
|
378
390
|
skip_comments_and_newlines
|
@@ -517,6 +529,12 @@ module Kumi
|
|
517
529
|
when :float then token.value.gsub('_', '').to_f
|
518
530
|
when :string then token.value
|
519
531
|
when :boolean then token.value == 'true'
|
532
|
+
when :constant
|
533
|
+
case token.value
|
534
|
+
when 'Float::INFINITY' then Float::INFINITY
|
535
|
+
else
|
536
|
+
raise_parse_error("Unknown constant: #{token.value}")
|
537
|
+
end
|
520
538
|
end
|
521
539
|
end
|
522
540
|
|
@@ -28,6 +28,12 @@ module Kumi
|
|
28
28
|
when '#' then consume_comment
|
29
29
|
when '"' then consume_string
|
30
30
|
when /\d/ then consume_number
|
31
|
+
when '-'
|
32
|
+
if peek_char && peek_char.match?(/\d/)
|
33
|
+
consume_number
|
34
|
+
else
|
35
|
+
consume_operator_or_punctuation
|
36
|
+
end
|
31
37
|
when /[a-zA-Z_]/ then consume_identifier_or_keyword
|
32
38
|
when ':' then consume_symbol_or_colon
|
33
39
|
else
|
@@ -124,6 +130,12 @@ module Kumi
|
|
124
130
|
number_str = ''
|
125
131
|
has_dot = false
|
126
132
|
|
133
|
+
# Handle negative sign if present
|
134
|
+
if current_char == '-'
|
135
|
+
number_str += current_char
|
136
|
+
advance
|
137
|
+
end
|
138
|
+
|
127
139
|
# Consume digits and underscores, and optionally a decimal point
|
128
140
|
while current_char && (current_char.match?(/[0-9_]/) || (!has_dot && current_char == '.'))
|
129
141
|
if current_char == '.'
|
@@ -148,6 +160,18 @@ module Kumi
|
|
148
160
|
start_column = @column
|
149
161
|
identifier = consume_while { |c| c.match?(/[a-zA-Z0-9_]/) }
|
150
162
|
|
163
|
+
# Check if it's a constant (e.g., Float::INFINITY)
|
164
|
+
if identifier == 'Float' && current_char == ':' && peek_char == ':'
|
165
|
+
advance # consume first :
|
166
|
+
advance # consume second :
|
167
|
+
constant_name = consume_while { |c| c.match?(/[a-zA-Z0-9_]/) }
|
168
|
+
full_constant = "#{identifier}::#{constant_name}"
|
169
|
+
|
170
|
+
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
171
|
+
@tokens << Token.new(:constant, full_constant, location, Kumi::Parser::TOKEN_METADATA[:constant])
|
172
|
+
return
|
173
|
+
end
|
174
|
+
|
151
175
|
# Check if it's a keyword
|
152
176
|
if keyword_type = Kumi::Parser::KEYWORDS[identifier]
|
153
177
|
metadata = Kumi::Parser::TOKEN_METADATA[keyword_type].dup
|
@@ -13,6 +13,7 @@ module Kumi
|
|
13
13
|
# Identifiers and symbols
|
14
14
|
IDENTIFIER = :identifier
|
15
15
|
SYMBOL = :symbol # :name
|
16
|
+
CONSTANT = :constant # Float::INFINITY
|
16
17
|
|
17
18
|
# Keywords
|
18
19
|
SCHEMA = :schema
|
@@ -278,6 +279,11 @@ module Kumi
|
|
278
279
|
starts_expression: true,
|
279
280
|
is_declaration_name: true
|
280
281
|
},
|
282
|
+
constant: {
|
283
|
+
category: :literal,
|
284
|
+
starts_expression: true,
|
285
|
+
ast_class: 'Kumi::Syntax::Literal'
|
286
|
+
},
|
281
287
|
|
282
288
|
# Punctuation with parser hints
|
283
289
|
dot: {
|
data/lib/kumi/parser/version.rb
CHANGED