kumi-parser 0.0.10 → 0.0.12
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 +2 -2
- data/examples/debug_text_parser.rb +1 -1
- data/examples/text_parser_comprehensive_test.rb +1 -1
- data/examples/text_parser_test_with_comments.rb +2 -2
- data/kumi-parser.gemspec +1 -1
- data/lib/kumi/parser/direct_parser.rb +50 -22
- data/lib/kumi/parser/token_metadata.rb +7 -1
- data/lib/kumi/parser/version.rb +1 -1
- metadata +8 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 935f50c0ecadd127eddc6ddef78aa2cd2b4cc25c26ef33202260895719224527
|
4
|
+
data.tar.gz: ecebfbe0f95c5304d5a188eeaf8b6c22eff42357913064aa6f1ea380b4145f69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81fe15f8482f0a2e123c14136e10bf47d2b90f5957f8c90e6ca4a416e811deee838510d22d3eb266dc8ef64b13dc1f4d2769eeacb06e7f1cac2a82e79fe1aa3b
|
7
|
+
data.tar.gz: ad2e56299872ac29522b5d63eca7e2c67ad74c07b702bf8cb0aa3a4da870bc11781e8e7a9c1df0232a75712c9eec7d8b29ebfedf4b387094790d2dfa48e3ecbf
|
data/CLAUDE.md
CHANGED
@@ -25,7 +25,7 @@
|
|
25
25
|
## AST Structure & Compatibility
|
26
26
|
|
27
27
|
All nodes from `Kumi::Syntax::*` (defined in main kumi gem):
|
28
|
-
- `Root(inputs,
|
28
|
+
- `Root(inputs, values, traits)`
|
29
29
|
- `InputDeclaration(name, domain, type, children)`
|
30
30
|
- `ValueDeclaration(name, expression)`
|
31
31
|
- `TraitDeclaration(name, expression)`
|
@@ -50,7 +50,7 @@ ast = Kumi::Parser::TextParser.parse(schema)
|
|
50
50
|
puts Kumi::Support::SExpressionPrinter.print(ast)
|
51
51
|
# => (Root
|
52
52
|
# inputs: [(InputDeclaration :income :float)]
|
53
|
-
#
|
53
|
+
# values: [(ValueDeclaration :tax (CallExpression :+ ...))]
|
54
54
|
# traits: [(TraitDeclaration :adult (CallExpression :>= ...))])
|
55
55
|
```
|
56
56
|
|
@@ -33,7 +33,7 @@ begin
|
|
33
33
|
puts
|
34
34
|
|
35
35
|
puts 'AST structure:'
|
36
|
-
puts "- Values: #{ast.
|
36
|
+
puts "- Values: #{ast.values.count} - #{ast.values.map(&:name)}"
|
37
37
|
puts "- Traits: #{ast.traits.count} - #{ast.traits.map(&:name)}"
|
38
38
|
rescue StandardError => e
|
39
39
|
puts "Error: #{e.message}"
|
@@ -318,7 +318,7 @@ if __FILE__ == $0
|
|
318
318
|
ast = Kumi::TextParser.parse(schema_text)
|
319
319
|
puts "\nParsed successfully!"
|
320
320
|
puts "- Input fields: #{ast.inputs.map(&:name).join(', ')}"
|
321
|
-
puts "- Values: #{ast.
|
321
|
+
puts "- Values: #{ast.values.count}"
|
322
322
|
puts "- Traits: #{ast.traits.count}"
|
323
323
|
else
|
324
324
|
puts '❌ Schema has errors:'
|
@@ -70,8 +70,8 @@ begin
|
|
70
70
|
end
|
71
71
|
end
|
72
72
|
|
73
|
-
puts "- Value declarations: #{ast.
|
74
|
-
ast.
|
73
|
+
puts "- Value declarations: #{ast.values.count}"
|
74
|
+
ast.values.each_with_index do |value, i|
|
75
75
|
puts " #{i + 1}. #{value.name}"
|
76
76
|
end
|
77
77
|
|
data/kumi-parser.gemspec
CHANGED
@@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
|
|
32
32
|
spec.require_paths = ['lib']
|
33
33
|
|
34
34
|
# Dependencies
|
35
|
-
spec.add_dependency 'kumi', '~> 0.0.
|
35
|
+
spec.add_dependency 'kumi', '~> 0.0.13'
|
36
36
|
spec.add_dependency 'parslet', '~> 2.0'
|
37
37
|
spec.add_dependency 'zeitwerk', '~> 2.6'
|
38
38
|
|
@@ -75,7 +75,7 @@ module Kumi
|
|
75
75
|
# Construct Root with exact AST.md structure
|
76
76
|
Kumi::Syntax::Root.new(
|
77
77
|
input_declarations,
|
78
|
-
value_declarations, #
|
78
|
+
value_declarations, # values
|
79
79
|
trait_declarations,
|
80
80
|
loc: schema_token.location
|
81
81
|
)
|
@@ -126,9 +126,9 @@ module Kumi
|
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
|
-
# Handle nested array declarations
|
129
|
+
# Handle nested array and hash declarations
|
130
130
|
children = []
|
131
|
-
if type_token.metadata[:type_name]
|
131
|
+
if %i[array hash].include?(type_token.metadata[:type_name]) && current_token.type == :do
|
132
132
|
advance # consume 'do'
|
133
133
|
skip_comments_and_newlines
|
134
134
|
|
@@ -143,13 +143,24 @@ module Kumi
|
|
143
143
|
expect_token(:end)
|
144
144
|
end
|
145
145
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
146
|
+
if children.empty?
|
147
|
+
Kumi::Syntax::InputDeclaration.new(
|
148
|
+
name_token.value,
|
149
|
+
domain,
|
150
|
+
type_token.metadata[:type_name],
|
151
|
+
children,
|
152
|
+
loc: type_token.location
|
153
|
+
)
|
154
|
+
else
|
155
|
+
Kumi::Syntax::InputDeclaration.new(
|
156
|
+
name_token.value,
|
157
|
+
domain,
|
158
|
+
type_token.metadata[:type_name],
|
159
|
+
children,
|
160
|
+
:field,
|
161
|
+
loc: type_token.location
|
162
|
+
)
|
163
|
+
end
|
153
164
|
end
|
154
165
|
|
155
166
|
def parse_domain_specification
|
@@ -175,7 +186,7 @@ module Kumi
|
|
175
186
|
start_token = current_token
|
176
187
|
start_value = start_token.type == :integer ? start_token.value.to_i : start_token.value.to_f
|
177
188
|
advance
|
178
|
-
|
189
|
+
|
179
190
|
case current_token.type
|
180
191
|
when :dot_dot
|
181
192
|
# Inclusive range: start..end
|
@@ -199,14 +210,14 @@ module Kumi
|
|
199
210
|
|
200
211
|
def convert_array_expression_to_ruby_array(array_expr)
|
201
212
|
return nil unless array_expr.is_a?(Kumi::Syntax::ArrayExpression)
|
202
|
-
|
213
|
+
|
203
214
|
array_expr.elements.map do |element|
|
204
215
|
if element.is_a?(Kumi::Syntax::Literal)
|
205
216
|
element.value
|
206
217
|
else
|
207
218
|
# For non-literal elements, we'd need more complex evaluation
|
208
219
|
# For now, just return the element as-is
|
209
|
-
element
|
220
|
+
element
|
210
221
|
end
|
211
222
|
end
|
212
223
|
end
|
@@ -262,18 +273,35 @@ module Kumi
|
|
262
273
|
Kumi::Syntax::CascadeExpression.new(cases, loc: start_token.location)
|
263
274
|
end
|
264
275
|
|
265
|
-
# Case expression: 'on
|
276
|
+
# Case expression: 'on condition1, condition2, ..., result' or 'base result'
|
266
277
|
def parse_case_expression
|
267
278
|
case current_token.type
|
268
279
|
when :on
|
269
280
|
on_token = advance_and_return_token
|
270
|
-
condition = parse_expression
|
271
281
|
|
272
|
-
#
|
273
|
-
|
282
|
+
# Parse all comma-separated expressions
|
283
|
+
expressions = []
|
284
|
+
expressions << parse_expression
|
274
285
|
|
275
|
-
|
276
|
-
|
286
|
+
# Continue parsing comma-separated expressions until end of case
|
287
|
+
while current_token.type == :comma
|
288
|
+
advance # consume comma
|
289
|
+
expressions << parse_expression
|
290
|
+
end
|
291
|
+
|
292
|
+
# Last expression is the result, all others are conditions
|
293
|
+
result = expressions.pop
|
294
|
+
conditions = expressions
|
295
|
+
|
296
|
+
# Combine conditions appropriately
|
297
|
+
if conditions.length == 1
|
298
|
+
condition = conditions[0]
|
299
|
+
# Wrap simple trait references in cascade_and to match Ruby DSL behavior
|
300
|
+
condition = wrap_condition_in_all(condition) if simple_trait_reference?(condition)
|
301
|
+
else
|
302
|
+
# Multiple conditions: combine with cascade_and
|
303
|
+
condition = Kumi::Syntax::CallExpression.new(:cascade_and, conditions, loc: on_token.location)
|
304
|
+
end
|
277
305
|
|
278
306
|
Kumi::Syntax::CaseExpression.new(condition, result, loc: on_token.location)
|
279
307
|
|
@@ -559,10 +587,10 @@ module Kumi
|
|
559
587
|
condition.is_a?(Kumi::Syntax::DeclarationReference)
|
560
588
|
end
|
561
589
|
|
562
|
-
|
590
|
+
|
591
|
+
# Helper method to wrap condition in cascade_and function call
|
563
592
|
def wrap_condition_in_all(condition)
|
564
|
-
|
565
|
-
Kumi::Syntax::CallExpression.new(:all?, [array_expr], loc: condition.loc)
|
593
|
+
Kumi::Syntax::CallExpression.new(:cascade_and, [condition], loc: condition.loc)
|
566
594
|
end
|
567
595
|
|
568
596
|
# Map operator token types to function names for Ruby DSL compatibility
|
@@ -144,6 +144,11 @@ module Kumi
|
|
144
144
|
starts_declaration: true,
|
145
145
|
type_name: :array
|
146
146
|
},
|
147
|
+
hash_type: {
|
148
|
+
category: :type_keyword,
|
149
|
+
starts_declaration: true,
|
150
|
+
type_name: :hash
|
151
|
+
},
|
147
152
|
|
148
153
|
# Function keyword
|
149
154
|
fn: {
|
@@ -379,7 +384,8 @@ module Kumi
|
|
379
384
|
'string' => :string_type,
|
380
385
|
'boolean' => :boolean_type,
|
381
386
|
'any' => :any_type,
|
382
|
-
'array' => :array_type
|
387
|
+
'array' => :array_type,
|
388
|
+
'hash' => :hash_type
|
383
389
|
}.freeze
|
384
390
|
|
385
391
|
# Opener to closer mappings for error recovery
|
data/lib/kumi/parser/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +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.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kumi Team
|
8
|
+
autorequire:
|
8
9
|
bindir: exe
|
9
10
|
cert_chain: []
|
10
|
-
date:
|
11
|
+
date: 2025-08-25 00:00:00.000000000 Z
|
11
12
|
dependencies:
|
12
13
|
- !ruby/object:Gem::Dependency
|
13
14
|
name: kumi
|
@@ -15,14 +16,14 @@ dependencies:
|
|
15
16
|
requirements:
|
16
17
|
- - "~>"
|
17
18
|
- !ruby/object:Gem::Version
|
18
|
-
version: 0.0.
|
19
|
+
version: 0.0.13
|
19
20
|
type: :runtime
|
20
21
|
prerelease: false
|
21
22
|
version_requirements: !ruby/object:Gem::Requirement
|
22
23
|
requirements:
|
23
24
|
- - "~>"
|
24
25
|
- !ruby/object:Gem::Version
|
25
|
-
version: 0.0.
|
26
|
+
version: 0.0.13
|
26
27
|
- !ruby/object:Gem::Dependency
|
27
28
|
name: parslet
|
28
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -161,6 +162,7 @@ metadata:
|
|
161
162
|
homepage_uri: https://github.com/amuta/kumi-parser
|
162
163
|
source_code_uri: https://github.com/amuta/kumi-parser
|
163
164
|
changelog_uri: https://github.com/amuta/kumi-parser/blob/main/CHANGELOG.md
|
165
|
+
post_install_message:
|
164
166
|
rdoc_options: []
|
165
167
|
require_paths:
|
166
168
|
- lib
|
@@ -175,7 +177,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
175
177
|
- !ruby/object:Gem::Version
|
176
178
|
version: '0'
|
177
179
|
requirements: []
|
178
|
-
rubygems_version: 3.
|
180
|
+
rubygems_version: 3.5.22
|
181
|
+
signing_key:
|
179
182
|
specification_version: 4
|
180
183
|
summary: Text parser for Kumi
|
181
184
|
test_files: []
|