kumi-parser 0.0.7 → 0.0.9
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 +28 -5
- data/lib/kumi/parser/smart_tokenizer.rb +12 -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: 5c06089581b6028ed2459e0e96d9398cd973f02d6000fc707898c920bd1b24e1
|
4
|
+
data.tar.gz: efb8f1e76217b7b98cef5abe97e5189326e70f81b3fbf53c5324556dc38fbb79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 50b9b9d4bf2c6d250c83ee92022ed3d3d280a7329aefdb699fef1444e9611d91aacd69d0bf7693335bf81a3b81c88bff7ef7ebf991da5c97bc98b76bec2b901d
|
7
|
+
data.tar.gz: 11f5f0949efbdc961e963890ecae8cb114424f20c305107f01c53b120deced6bf96b2f78a7e28d1e57c0af025ae6749bdab8e49e3bdf59899949dc0a6d27accc
|
@@ -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
|
@@ -387,12 +399,12 @@ module Kumi
|
|
387
399
|
input_token = expect_token(:identifier) # 'input'
|
388
400
|
expect_token(:dot)
|
389
401
|
|
390
|
-
path = [
|
402
|
+
path = [expect_field_name_token.to_sym]
|
391
403
|
|
392
404
|
# Handle nested access: input.field.subfield
|
393
405
|
while current_token.type == :dot
|
394
406
|
advance # consume '.'
|
395
|
-
path <<
|
407
|
+
path << expect_field_name_token.to_sym
|
396
408
|
end
|
397
409
|
|
398
410
|
if path.length == 1
|
@@ -406,12 +418,12 @@ module Kumi
|
|
406
418
|
input_token = expect_token(:input) # 'input' keyword token
|
407
419
|
expect_token(:dot)
|
408
420
|
|
409
|
-
path = [
|
421
|
+
path = [expect_field_name_token.to_sym]
|
410
422
|
|
411
423
|
# Handle nested access: input.field.subfield
|
412
424
|
while current_token.type == :dot
|
413
425
|
advance # consume '.'
|
414
|
-
path <<
|
426
|
+
path << expect_field_name_token.to_sym
|
415
427
|
end
|
416
428
|
|
417
429
|
if path.length == 1
|
@@ -520,6 +532,17 @@ module Kumi
|
|
520
532
|
end
|
521
533
|
end
|
522
534
|
|
535
|
+
def expect_field_name_token
|
536
|
+
# Field names can be identifiers or keywords (like 'base', 'input', etc.)
|
537
|
+
token = current_token
|
538
|
+
if token.identifier? || token.keyword?
|
539
|
+
advance
|
540
|
+
token.value
|
541
|
+
else
|
542
|
+
raise_parse_error("Expected field name (identifier or keyword), got #{token.type}")
|
543
|
+
end
|
544
|
+
end
|
545
|
+
|
523
546
|
def raise_parse_error(message)
|
524
547
|
location = current_token.location
|
525
548
|
raise Errors::ParseError.new(message, token: current_token)
|
@@ -547,7 +570,7 @@ module Kumi
|
|
547
570
|
when :lte then :<=
|
548
571
|
when :and then :and
|
549
572
|
when :or then :or
|
550
|
-
when :exponent then
|
573
|
+
when :exponent then :power
|
551
574
|
else token_type
|
552
575
|
end
|
553
576
|
end
|
@@ -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 == '.'
|
data/lib/kumi/parser/version.rb
CHANGED