kumi-parser 0.0.20 → 0.0.21

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ea2c2266d25647fdc1bfe6a5a773655a4e78baf79062507589209ed3243b6870
4
- data.tar.gz: 25bf84670d568126b14cdcd181bcb89f373b394d4afbd1a3dbf55042e0283c44
3
+ metadata.gz: 219a0ee4cbe1b140e1adb5f885b95764258bad4ac416ad361167dcdf5464e64b
4
+ data.tar.gz: db323360955a244c7f6ddbf6cdcd1ae333fc21aa039ce0364ac143789d17f5c5
5
5
  SHA512:
6
- metadata.gz: 2e5ab415f4e8ab3dacf941dabc87e7b782d628ef20e49be2ecd7a570a32722b4b65ef3f73805681ebf80229eba2b1903a487863f06f8ab98a9bf8982a8d77db5
7
- data.tar.gz: f9f86ebad3792de667271f64dc3ecd7c28c53c26fb50a15f23cc876be1918581258d0df738c23aa8ee19fee6410f30eb6683b67e658d477a48686d6d093e4017
6
+ metadata.gz: c937eee31a97be97fa71e4830db4f40122acb1aae720fb1dba78a67b1039cc21cd9042d3ae0884d67cda3dbddcf47e6e193a805218d2f68f93946f90649060a2
7
+ data.tar.gz: 21b2ae87d652bc2ffb66489ea0a504033baaa65c6d74ee9168a7a8420d38de3d04c005b1ae21acc10c49656a3c8dee242a2e47425e007cdb3058b389c40de5f1
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 3.3.8
@@ -114,11 +114,15 @@ module Kumi
114
114
 
115
115
  # element :type, :name (syntactic sugar: the child was declared via `element`)
116
116
  declared_with_element = (type_token.metadata[:type_name] == :element)
117
+ declared_with_index = (type_token.metadata[:type_name] == :index)
117
118
  if declared_with_element
118
119
  element_type_token = expect_token(:symbol)
119
120
  expect_token(:comma)
120
121
  name_token = expect_token(:symbol)
121
122
  actual_type = element_type_token.value
123
+ elsif declared_with_index
124
+ name_token = expect_token(:symbol)
125
+ actual_type = :index
122
126
  else
123
127
  name_token = expect_token(:symbol)
124
128
  actual_type = type_token.metadata[:type_name]
@@ -151,8 +155,9 @@ module Kumi
151
155
 
152
156
  # Syntactic decision (NO counting): is this child introduced by `element`?
153
157
  child_is_element_keyword = (current_token.metadata[:type_name] == :element)
158
+ child_is_index_keyword = (current_token.metadata[:type_name] == :index)
154
159
  any_element_children ||= child_is_element_keyword
155
- any_field_children ||= !child_is_element_keyword
160
+ any_field_children ||= !child_is_element_keyword && !child_is_index_keyword
156
161
 
157
162
  children << parse_input_declaration
158
163
  skip_comments_and_newlines
@@ -247,8 +252,12 @@ module Kumi
247
252
 
248
253
  # Value declaration: 'value :name, expression' or 'value :name do ... end'
249
254
  def parse_value_declaration
255
+ begin
250
256
  value_token = expect_token(:value)
251
257
  name_token = expect_token(:symbol)
258
+ rescue => e
259
+ binding.pry
260
+ end
252
261
 
253
262
  if current_token.type == :do
254
263
  expression = parse_cascade_expression
@@ -470,44 +479,89 @@ module Kumi
470
479
  end
471
480
 
472
481
  def parse_function_sugar
473
- sugar_token = current_token
474
- advance
475
- args = parse_argument_list
476
- Kumi::Syntax::CallExpression.new(sugar_token.value.to_sym, args, loc: sugar_token.location)
482
+ sugar = current_token
483
+ advance # e.g. shift(...)
484
+ expect_token(:lparen)
485
+ args, opts = parse_args_and_opts_inside_parens
486
+ Kumi::Syntax::CallExpression.new(sugar.value.to_sym, args, opts, loc: sugar.location)
477
487
  end
478
488
 
479
489
  def parse_function_call
480
- advance
481
- if current_token.type == :lparen
490
+ advance # saw :fn
491
+ expect_token(:lparen)
492
+ fn_name_token = expect_token(:symbol) # :shift, :roll, etc.
493
+ args = []
494
+ opts = {}
495
+ if current_token.type == :comma
482
496
  advance
483
- fn_name_token = expect_token(:symbol)
484
- fn_name = fn_name_token.value
485
- args = []
486
- while current_token.type == :comma
487
- advance
488
- args << parse_expression
489
- end
490
- expect_token(:rparen)
491
- Kumi::Syntax::CallExpression.new(fn_name, args, loc: fn_name_token.location)
497
+ args, opts = parse_args_and_opts_inside_parens
498
+ end
499
+ # expect_token(:rparen)
500
+ Kumi::Syntax::CallExpression.new(fn_name_token.value, args, loc: fn_name_token.location, opts: opts)
501
+ end
502
+
503
+ def parse_kw_literal_value
504
+ t = current_token
505
+ case t.type
506
+ when :integer then advance
507
+ t.value.delete('_').to_i
508
+ when :float then advance
509
+ t.value.delete('_').to_f
510
+ when :string, :symbol then advance
511
+ t.value
512
+ when :boolean then advance
513
+ t.value == 'true'
514
+ when :label then advance
515
+ t.value.to_sym # :wrap, :clamp, etc.
516
+ when :subtract # allow negatives like -1
517
+ advance
518
+ v = parse_kw_literal_value
519
+ raise_parse_error("numeric after unary '-'") unless v.is_a?(Numeric)
520
+ -v
492
521
  else
493
- raise_parse_error("Expected '(' after 'fn'")
522
+ raise_parse_error('keyword value must be literal/label')
494
523
  end
495
524
  end
496
525
 
497
- def parse_argument_list
526
+ def parse_args_and_opts_inside_parens
498
527
  args = []
528
+ opts = {}
529
+
530
+ # expect_token(:lparen)
499
531
 
500
- expect_token(:lparen)
501
532
  unless current_token.type == :rparen
502
- args << parse_expression
503
- while current_token.type == :comma
504
- advance
533
+ # --- positional args ---
534
+ unless next_is_kwarg_after_comma?
505
535
  args << parse_expression
536
+ while current_token.type == :comma && !next_is_kwarg_after_comma?
537
+ advance
538
+ args << parse_expression
539
+ end
540
+ end
541
+ # --- kwargs (labels like `policy:`) ---
542
+ if next_is_kwarg_after_comma?
543
+ # subsequent pairs: `, label value`
544
+ while current_token.type == :comma
545
+ # stop if next token is not a kw key
546
+ advance
547
+
548
+ if current_token.type == :label
549
+ key = current_token.value.to_sym
550
+ advance
551
+ end
552
+ opts[key] = parse_kw_literal_value
553
+
554
+ break unless next_is_kwarg_after_comma?
555
+ end
506
556
  end
507
557
  end
558
+
508
559
  expect_token(:rparen)
560
+ [args, opts]
561
+ end
509
562
 
510
- args
563
+ def next_is_kwarg_after_comma?
564
+ current_token.type == :comma && peek_token.type == :label
511
565
  end
512
566
 
513
567
  def parse_array_literal
@@ -581,6 +635,7 @@ module Kumi
581
635
  when :float then token.value.gsub('_', '').to_f
582
636
  when :string then token.value
583
637
  when :boolean then token.value == 'true'
638
+ when :symbol then token.value.to_sym
584
639
  when :constant
585
640
  case token.value
586
641
  when 'Float::INFINITY' then Float::INFINITY
@@ -33,6 +33,7 @@ module Kumi
33
33
  ANY_TYPE = :any_type # any
34
34
  ARRAY_TYPE = :array_type # array
35
35
  ELEMENT_TYPE = :element_type # element
36
+ INDEX_TYPE = :index_type # index
36
37
 
37
38
  # Function keywords
38
39
  FN = :fn
@@ -155,6 +156,11 @@ module Kumi
155
156
  starts_declaration: true,
156
157
  type_name: :element
157
158
  },
159
+ index_type: {
160
+ category: :type_keyword,
161
+ starts_declaration: true,
162
+ type_name: :index
163
+ },
158
164
 
159
165
  # Function keyword
160
166
  fn: {
@@ -388,7 +394,9 @@ module Kumi
388
394
  }.freeze
389
395
 
390
396
  FUNCTION_SUGAR = {
391
- 'select' => '__select__'
397
+ 'select' => '__select__',
398
+ 'shift' => 'shift',
399
+ 'roll' => 'roll'
392
400
  }
393
401
 
394
402
  # Keywords mapping
@@ -411,7 +419,8 @@ module Kumi
411
419
  'any' => :any_type,
412
420
  'array' => :array_type,
413
421
  'hash' => :hash_type,
414
- 'element' => :element_type
422
+ 'element' => :element_type,
423
+ 'index' => :index_type
415
424
  }.freeze
416
425
 
417
426
  # Opener to closer mappings for error recovery
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kumi
4
4
  module Parser
5
- VERSION = '0.0.20'
5
+ VERSION = '0.0.21'
6
6
  end
7
7
  end
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.20
4
+ version: 0.0.21
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kumi Team
8
+ autorequire:
8
9
  bindir: exe
9
10
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
11
+ date: 2025-10-02 00:00:00.000000000 Z
11
12
  dependencies:
12
13
  - !ruby/object:Gem::Dependency
13
14
  name: parslet
@@ -116,6 +117,7 @@ extensions: []
116
117
  extra_rdoc_files: []
117
118
  files:
118
119
  - ".rspec"
120
+ - ".ruby-version"
119
121
  - CLAUDE.md
120
122
  - LICENSE
121
123
  - README.md
@@ -147,6 +149,7 @@ metadata:
147
149
  homepage_uri: https://github.com/amuta/kumi-parser
148
150
  source_code_uri: https://github.com/amuta/kumi-parser
149
151
  changelog_uri: https://github.com/amuta/kumi-parser/blob/main/CHANGELOG.md
152
+ post_install_message:
150
153
  rdoc_options: []
151
154
  require_paths:
152
155
  - lib
@@ -161,7 +164,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
161
164
  - !ruby/object:Gem::Version
162
165
  version: '0'
163
166
  requirements: []
164
- rubygems_version: 3.6.9
167
+ rubygems_version: 3.5.22
168
+ signing_key:
165
169
  specification_version: 4
166
170
  summary: Text parser for Kumi
167
171
  test_files: []