kumi-parser 0.0.22 → 0.0.24
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/CLAUDE.md +1 -1
- data/lib/kumi/parser/direct_parser.rb +39 -21
- data/lib/kumi/parser/token_metadata.rb +5 -0
- data/lib/kumi/parser/version.rb +1 -1
- data/lib/kumi/text_schema.rb +8 -8
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb3b86394edb12c3c7033ca85d91f84e0945289c384f7a9717ca8c1ce3965432
|
4
|
+
data.tar.gz: b06faae267e651a8440e0218cc587be32c0f9de2a81aef27661198976dfebec1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d89bc307ef6d89c11adce650bc9500cddea0a0fa3e487212d9d483ca921c23839a6c5f2fcd9cae396d497e1e22119a414802624c35de8898db4b5d3247186dbc
|
7
|
+
data.tar.gz: d601d7b9aa7622552dd7bea123ded066bbc7ce57b3bb967a5355ce66d55ead08d0e3fe5553151198469fec7d4a7fd11d1fe6389b787df067b06ee559da9f8313
|
data/CLAUDE.md
CHANGED
@@ -61,10 +61,12 @@ module Kumi
|
|
61
61
|
trait_declarations = []
|
62
62
|
|
63
63
|
skip_comments_and_newlines
|
64
|
-
while %i[value trait].include?(current_token.type)
|
64
|
+
while %i[value trait let].include?(current_token.type)
|
65
65
|
case current_token.type
|
66
66
|
when :value
|
67
67
|
value_declarations << parse_value_declaration
|
68
|
+
when :let
|
69
|
+
value_declarations << parse_let_value_declaration
|
68
70
|
when :trait
|
69
71
|
trait_declarations << parse_trait_declaration
|
70
72
|
end
|
@@ -252,12 +254,8 @@ module Kumi
|
|
252
254
|
|
253
255
|
# Value declaration: 'value :name, expression' or 'value :name do ... end'
|
254
256
|
def parse_value_declaration
|
255
|
-
|
256
|
-
|
257
|
-
name_token = expect_token(:symbol)
|
258
|
-
rescue StandardError => e
|
259
|
-
binding.pry
|
260
|
-
end
|
257
|
+
value_token = expect_token(:value)
|
258
|
+
name_token = expect_token(:symbol)
|
261
259
|
|
262
260
|
if current_token.type == :do
|
263
261
|
expression = parse_cascade_expression
|
@@ -273,6 +271,25 @@ module Kumi
|
|
273
271
|
)
|
274
272
|
end
|
275
273
|
|
274
|
+
def parse_let_value_declaration
|
275
|
+
let_token = expect_token(:let)
|
276
|
+
name_token = expect_token(:symbol)
|
277
|
+
|
278
|
+
if current_token.type == :do
|
279
|
+
expression = parse_cascade_expression
|
280
|
+
else
|
281
|
+
expect_token(:comma)
|
282
|
+
expression = parse_expression
|
283
|
+
end
|
284
|
+
|
285
|
+
Kumi::Syntax::ValueDeclaration.new(
|
286
|
+
name_token.value,
|
287
|
+
expression,
|
288
|
+
hints: { inline: true },
|
289
|
+
loc: let_token.location
|
290
|
+
)
|
291
|
+
end
|
292
|
+
|
276
293
|
# Trait declaration: 'trait :name, expression'
|
277
294
|
def parse_trait_declaration
|
278
295
|
trait_token = expect_token(:trait)
|
@@ -344,6 +361,7 @@ module Kumi
|
|
344
361
|
# Pratt parser for expressions
|
345
362
|
def parse_expression(min_precedence = 0)
|
346
363
|
left = parse_primary_expression
|
364
|
+
left = parse_postfix_chain(left)
|
347
365
|
skip_comments_and_newlines
|
348
366
|
|
349
367
|
while current_token.operator? && current_token.precedence >= min_precedence
|
@@ -364,12 +382,25 @@ module Kumi
|
|
364
382
|
[left, right],
|
365
383
|
loc: operator_token.location
|
366
384
|
)
|
385
|
+
left = parse_postfix_chain(left)
|
367
386
|
skip_comments_and_newlines
|
368
387
|
end
|
369
388
|
|
370
389
|
left
|
371
390
|
end
|
372
391
|
|
392
|
+
def parse_postfix_chain(base)
|
393
|
+
skip_comments_and_newlines
|
394
|
+
while current_token.type == :lbracket
|
395
|
+
expect_token(:lbracket)
|
396
|
+
index_expr = parse_expression
|
397
|
+
expect_token(:rbracket)
|
398
|
+
base = Kumi::Syntax::CallExpression.new(:at, [base, index_expr], loc: base.loc)
|
399
|
+
skip_comments_and_newlines
|
400
|
+
end
|
401
|
+
base
|
402
|
+
end
|
403
|
+
|
373
404
|
def parse_primary_expression
|
374
405
|
token = current_token
|
375
406
|
|
@@ -382,11 +413,8 @@ module Kumi
|
|
382
413
|
parse_function_sugar
|
383
414
|
|
384
415
|
when :identifier
|
385
|
-
|
386
416
|
if token.value == 'input' && peek_token.type == :dot
|
387
417
|
parse_input_reference
|
388
|
-
elsif peek_token.type == :lbracket
|
389
|
-
parse_array_access_reference
|
390
418
|
else
|
391
419
|
advance
|
392
420
|
Kumi::Syntax::DeclarationReference.new(token.value.to_sym, loc: token.location)
|
@@ -468,16 +496,6 @@ module Kumi
|
|
468
496
|
end
|
469
497
|
end
|
470
498
|
|
471
|
-
def parse_array_access_reference
|
472
|
-
name_token = expect_token(:identifier)
|
473
|
-
expect_token(:lbracket)
|
474
|
-
index_expr = parse_expression
|
475
|
-
expect_token(:rbracket)
|
476
|
-
|
477
|
-
base_ref = Kumi::Syntax::DeclarationReference.new(name_token.value.to_sym, loc: name_token.location)
|
478
|
-
Kumi::Syntax::CallExpression.new(:at, [base_ref, index_expr], loc: name_token.location)
|
479
|
-
end
|
480
|
-
|
481
499
|
def parse_function_sugar
|
482
500
|
sugar = current_token
|
483
501
|
advance # e.g. shift(...)
|
@@ -497,7 +515,7 @@ module Kumi
|
|
497
515
|
args, opts = parse_args_and_opts_inside_parens
|
498
516
|
end
|
499
517
|
# expect_token(:rparen)
|
500
|
-
Kumi::Syntax::CallExpression.new(fn_name_token.value, args, loc: fn_name_token.location
|
518
|
+
Kumi::Syntax::CallExpression.new(fn_name_token.value, args, opts, loc: fn_name_token.location)
|
501
519
|
end
|
502
520
|
|
503
521
|
def parse_kw_literal_value
|
@@ -90,6 +90,10 @@ module Kumi
|
|
90
90
|
expects_expression: true,
|
91
91
|
declaration_type: :value
|
92
92
|
},
|
93
|
+
let: {
|
94
|
+
category: :keyword,
|
95
|
+
expects_expression: true
|
96
|
+
},
|
93
97
|
trait: {
|
94
98
|
category: :keyword,
|
95
99
|
expects_expression: true,
|
@@ -404,6 +408,7 @@ module Kumi
|
|
404
408
|
'schema' => :schema,
|
405
409
|
'input' => :input,
|
406
410
|
'value' => :value,
|
411
|
+
'let' => :let,
|
407
412
|
'trait' => :trait,
|
408
413
|
'do' => :do,
|
409
414
|
'end' => :end,
|
data/lib/kumi/parser/version.rb
CHANGED
data/lib/kumi/text_schema.rb
CHANGED
@@ -7,25 +7,25 @@ module Kumi
|
|
7
7
|
# Text-based schema that extends Kumi::Schema with text parsing capabilities
|
8
8
|
class TextSchema
|
9
9
|
extend Kumi::Schema
|
10
|
-
|
10
|
+
|
11
11
|
# Create a schema from text using the same pipeline as Ruby DSL
|
12
12
|
def self.from_text(text, source_file: '<input>')
|
13
13
|
# Parse text to AST (same as RubyParser::Dsl.build_syntax_tree)
|
14
|
-
@
|
15
|
-
@__analyzer_result__ = Analyzer.analyze!(@
|
16
|
-
@__compiled_schema__ = Compiler.compile(@
|
14
|
+
@__kumi_syntax_tree__ = Kumi::TextParser.parse(text, source_file: source_file).freeze
|
15
|
+
@__analyzer_result__ = Analyzer.analyze!(@__kumi_syntax_tree__).freeze
|
16
|
+
@__compiled_schema__ = Compiler.compile(@__kumi_syntax_tree__, analyzer: @__analyzer_result__).freeze
|
17
17
|
|
18
|
-
Inspector.new(@
|
18
|
+
Inspector.new(@__kumi_syntax_tree__, @__analyzer_result__, @__compiled_schema__)
|
19
19
|
end
|
20
|
-
|
20
|
+
|
21
21
|
# Validate text schema
|
22
22
|
def self.valid?(text, source_file: '<input>')
|
23
23
|
Kumi::TextParser.valid?(text, source_file: source_file)
|
24
24
|
end
|
25
|
-
|
25
|
+
|
26
26
|
# Get validation diagnostics
|
27
27
|
def self.validate(text, source_file: '<input>')
|
28
28
|
Kumi::TextParser.validate(text, source_file: source_file)
|
29
29
|
end
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kumi-parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.24
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kumi Team
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-10-
|
11
|
+
date: 2025-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: parslet
|