kumi-parser 0.0.14 → 0.0.15

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: 83ae18a38c78f9513121f579f024309c162ebbc1fdf909aecbe8aceff04e100a
4
- data.tar.gz: 8bfab6fb7250f7e39289ceb07b84ae556958a77be19b66fe253b19c7284359ba
3
+ metadata.gz: 1d86288cacf8d5e80d38541472d08b58ff202a7ec04efd0689c3b2698480fde1
4
+ data.tar.gz: 86088f162d87519650cb0e6473176962967f292479bafb71973294bf723a4752
5
5
  SHA512:
6
- metadata.gz: 39f5759930377f813b10d8ce148dc5f26bd9a6b4a21a577b91bbb24fe7d47d923cf3967f25454666bb9c8c23f0190909f6283fe629a7bd935d51ca9033c25047
7
- data.tar.gz: d06bd58249f51ef7edafb51f291c2b18720ea259b3a375b9624ac593631f7786aa2c920da92bea99ec1ad27fc517c71c9b7bbd41e7626faa814949e317b56f29
6
+ metadata.gz: 5ab143e2e5a1f3e2e84c3ebb1a23283d4c24ce727dd4a4145d0beac7415e823bb0a0ce29711a8354010c662402f0ecaea7da0a254b8a352f200dee3bcae7fa61
7
+ data.tar.gz: 76abe4b2565162a1b49421de36355bf011aa444ca3372bfb3b42ff4361e50959079103b2f85b704c17ffe06ee689c3dc39f45359fe84cd165590a82c9e74982c
data/README.md CHANGED
@@ -57,7 +57,7 @@ end
57
57
  ```
58
58
 
59
59
  **Function calls**: `fn(:name, arg1, arg2, ...)`
60
- **Operators**: `+` `-` `*` `/` `%` `>` `<` `>=` `<=` `==` `!=` `&` `|`
60
+ **Operators**: `+` `-` `*` `**` `` `/` `%` `>` `<` `>=` `<=` `==` `!=` `&` `|`
61
61
  **References**: `input.field`, `value_name`, `array[index]`
62
62
  **Strings**: Both `"double"` and `'single'` quotes supported
63
63
  **Element syntax**: `element :type, :name` for array element specifications
@@ -25,6 +25,7 @@ module Kumi
25
25
  def peek_token(offset = 1)
26
26
  peek_pos = @pos + offset
27
27
  return @tokens.last if peek_pos >= @tokens.length # Return EOF
28
+
28
29
  @tokens[peek_pos]
29
30
  end
30
31
 
@@ -89,6 +90,7 @@ module Kumi
89
90
 
90
91
  until %i[end eof].include?(current_token.type)
91
92
  break unless current_token.metadata[:category] == :type_keyword
93
+
92
94
  declarations << parse_input_declaration
93
95
  skip_comments_and_newlines
94
96
  end
@@ -232,6 +234,7 @@ module Kumi
232
234
 
233
235
  def convert_array_expression_to_ruby_array(array_expr)
234
236
  return nil unless array_expr.is_a?(Kumi::Syntax::ArrayExpression)
237
+
235
238
  array_expr.elements.map do |element|
236
239
  if element.is_a?(Kumi::Syntax::Literal)
237
240
  element.value
@@ -365,14 +368,15 @@ module Kumi
365
368
  value = convert_literal_value(token)
366
369
  advance
367
370
  Kumi::Syntax::Literal.new(value, loc: token.location)
371
+ when :function_sugar
372
+ parse_function_sugar
368
373
 
369
374
  when :identifier
375
+
370
376
  if token.value == 'input' && peek_token.type == :dot
371
377
  parse_input_reference
372
378
  elsif peek_token.type == :lbracket
373
379
  parse_array_access_reference
374
- elsif token.value == 'fn'
375
- parse_function_call
376
380
  else
377
381
  advance
378
382
  Kumi::Syntax::DeclarationReference.new(token.value.to_sym, loc: token.location)
@@ -395,7 +399,8 @@ module Kumi
395
399
  parse_array_literal
396
400
 
397
401
  when :fn
398
- parse_function_call_from_fn_token
402
+ # expect_token(:fn)
403
+ parse_function_call
399
404
 
400
405
  when :subtract
401
406
  advance
@@ -460,26 +465,15 @@ module Kumi
460
465
  Kumi::Syntax::CallExpression.new(:at, [base_ref, index_expr], loc: name_token.location)
461
466
  end
462
467
 
463
- def parse_function_call
464
- fn_token = expect_token(:identifier)
465
- if current_token.type == :lparen
466
- advance
467
- fn_name_token = expect_token(:symbol)
468
- fn_name = fn_name_token.value
469
- args = []
470
- while current_token.type == :comma
471
- advance
472
- args << parse_expression
473
- end
474
- expect_token(:rparen)
475
- Kumi::Syntax::CallExpression.new(fn_name, args, loc: fn_name_token.location)
476
- else
477
- raise_parse_error("Expected '(' after 'fn'")
478
- end
468
+ def parse_function_sugar
469
+ sugar_token = current_token
470
+ advance
471
+ args = parse_argument_list
472
+ Kumi::Syntax::CallExpression.new(sugar_token.value.to_sym, args, loc: sugar_token.location)
479
473
  end
480
474
 
481
- def parse_function_call_from_fn_token
482
- fn_token = expect_token(:fn)
475
+ def parse_function_call
476
+ advance
483
477
  if current_token.type == :lparen
484
478
  advance
485
479
  fn_name_token = expect_token(:symbol)
@@ -498,6 +492,8 @@ module Kumi
498
492
 
499
493
  def parse_argument_list
500
494
  args = []
495
+
496
+ expect_token(:lparen)
501
497
  unless current_token.type == :rparen
502
498
  args << parse_expression
503
499
  while current_token.type == :comma
@@ -505,6 +501,8 @@ module Kumi
505
501
  args << parse_expression
506
502
  end
507
503
  end
504
+ expect_token(:rparen)
505
+
508
506
  args
509
507
  end
510
508
 
@@ -168,12 +168,14 @@ module Kumi
168
168
  advance # consume second :
169
169
  constant_name = consume_while { |c| c.match?(/[a-zA-Z0-9_]/) }
170
170
  full_constant = "#{identifier}::#{constant_name}"
171
-
171
+
172
172
  location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
173
173
  @tokens << Token.new(:constant, full_constant, location, Kumi::Parser::TOKEN_METADATA[:constant])
174
174
  return
175
175
  end
176
176
 
177
+ location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
178
+
177
179
  # Check if it's a keyword
178
180
  if keyword_type = Kumi::Parser::KEYWORDS[identifier]
179
181
  metadata = Kumi::Parser::TOKEN_METADATA[keyword_type].dup
@@ -188,23 +190,29 @@ module Kumi
188
190
  metadata[:closes_context] = closed_context
189
191
  end
190
192
 
191
- location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
192
193
  @tokens << Token.new(keyword_type, identifier, location, metadata)
193
- else
194
- # It's an identifier - determine its role based on context
195
- metadata = Kumi::Parser::TOKEN_METADATA[:identifier].dup
196
-
197
- # Add context-specific metadata
198
- case current_context
199
- when :input
200
- metadata[:context] = :input_declaration
201
- when :schema
202
- metadata[:context] = :schema_body
203
- end
194
+ return
195
+ end
204
196
 
205
- location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
206
- @tokens << Token.new(:identifier, identifier, location, metadata)
197
+ # Check if its a function sugar
198
+ if Kumi::Parser::FUNCTION_SUGAR[identifier]
199
+ metadata = Kumi::Parser::TOKEN_METADATA[:function_sugar].dup
200
+ @tokens << Token.new(:function_sugar, identifier, location, metadata)
201
+ return
202
+ end
203
+
204
+ # Otherwise is an Idenfier
205
+ metadata = Kumi::Parser::TOKEN_METADATA[:identifier].dup
206
+
207
+ # Add context-specific metadata
208
+ case current_context
209
+ when :input
210
+ metadata[:context] = :input_declaration
211
+ when :schema
212
+ metadata[:context] = :schema_body
207
213
  end
214
+
215
+ @tokens << Token.new(:identifier, identifier, location, metadata)
208
216
  end
209
217
 
210
218
  def consume_symbol_or_colon
@@ -81,4 +81,4 @@ module Kumi
81
81
  end
82
82
  end
83
83
  end
84
- end
84
+ end
@@ -38,8 +38,8 @@ module Kumi
38
38
  FN = :fn
39
39
 
40
40
  # Operators (by precedence)
41
- EXPONENT = :exponent # **
42
- MULTIPLY = :multiply # *
41
+ EXPONENT = :exponent # **
42
+ MULTIPLY = :multiply # *
43
43
  DIVIDE = :divide # /
44
44
  MODULO = :modulo # %
45
45
  ADD = :add # +
@@ -67,7 +67,7 @@ module Kumi
67
67
  # Special
68
68
  NEWLINE = :newline
69
69
  EOF = :eof
70
- COMMENT = :comment # # comment
70
+ COMMENT = :comment # # comment
71
71
  end
72
72
 
73
73
  # Rich metadata for each token type
@@ -163,6 +163,11 @@ module Kumi
163
163
  starts_expression: true
164
164
  },
165
165
 
166
+ function_sugar: {
167
+ function_keyword: true,
168
+ starts_expression: true
169
+ },
170
+
166
171
  # Operators with precedence and associativity
167
172
  exponent: {
168
173
  category: :operator,
@@ -372,6 +377,10 @@ module Kumi
372
377
  '|' => :or
373
378
  }.freeze
374
379
 
380
+ FUNCTION_SUGAR = {
381
+ 'select' => '__select__'
382
+ }
383
+
375
384
  # Keywords mapping
376
385
  KEYWORDS = {
377
386
  'schema' => :schema,
@@ -401,4 +410,4 @@ module Kumi
401
410
  rbracket: :lbracket
402
411
  }.freeze
403
412
  end
404
- end
413
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Kumi
4
4
  module Parser
5
- VERSION = '0.0.14'
5
+ VERSION = '0.0.15'
6
6
  end
7
7
  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.14
4
+ version: 0.0.15
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-08-30 00:00:00.000000000 Z
11
+ date: 2025-09-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: kumi