kumi-parser 0.0.5 → 0.0.7
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 +59 -5
- data/lib/kumi/parser/smart_tokenizer.rb +39 -0
- data/lib/kumi/parser/text_parser.rb +1 -0
- data/lib/kumi/parser/token_metadata.rb +15 -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: 119563dd70c4e400274c70034d942036f1c07e8525d94dbb1a78fcd9f850be9b
|
4
|
+
data.tar.gz: 77e331ee47ac3428e2a13e58b461367d2a7d44756515e976cfc54a12a4749a90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d5a7802b011dc8e21c890e9fb3f0c981c856bd03a39c277479fc1e2736de08c345e72085407fb07c5d339b3cd948bfc81e40d19257572f6b415d16a14f68d466
|
7
|
+
data.tar.gz: a08624024f172abc6602e238c09c6250f23c082b7d7580e8289ad318aec7c41787d039ddf154cdbf8ec60929b4095e23d2585307612717117c8d6befc878cf94
|
@@ -153,17 +153,64 @@ module Kumi
|
|
153
153
|
end
|
154
154
|
|
155
155
|
def parse_domain_specification
|
156
|
-
#
|
157
|
-
|
158
|
-
|
159
|
-
|
156
|
+
# Parse domain specifications: domain: ["x", "y"], domain: [1, 2, 3], domain: 1..10, domain: 1...10
|
157
|
+
case current_token.type
|
158
|
+
when :lbracket
|
159
|
+
# Array domain: ["a", "b", "c"] or [1, 2, 3]
|
160
|
+
array_expr = parse_array_literal
|
161
|
+
# Convert ArrayExpression to Ruby Array for analyzer compatibility
|
162
|
+
convert_array_expression_to_ruby_array(array_expr)
|
163
|
+
when :integer, :float
|
164
|
+
# Range domain: 1..10 or 1...10
|
165
|
+
parse_range_domain
|
160
166
|
else
|
161
|
-
# Skip
|
167
|
+
# Skip unknown domain specs for now
|
162
168
|
advance until %i[comma newline eof end].include?(current_token.type)
|
163
169
|
nil
|
164
170
|
end
|
165
171
|
end
|
166
172
|
|
173
|
+
def parse_range_domain
|
174
|
+
# Parse numeric ranges like 1..10 or 0.0...100.0
|
175
|
+
start_token = current_token
|
176
|
+
start_value = start_token.type == :integer ? start_token.value.to_i : start_token.value.to_f
|
177
|
+
advance
|
178
|
+
|
179
|
+
case current_token.type
|
180
|
+
when :dot_dot
|
181
|
+
# Inclusive range: start..end
|
182
|
+
advance # consume ..
|
183
|
+
end_token = current_token
|
184
|
+
end_value = end_token.type == :integer ? end_token.value.to_i : end_token.value.to_f
|
185
|
+
advance
|
186
|
+
(start_value..end_value)
|
187
|
+
when :dot_dot_dot
|
188
|
+
# Exclusive range: start...end
|
189
|
+
advance # consume ...
|
190
|
+
end_token = current_token
|
191
|
+
end_value = end_token.type == :integer ? end_token.value.to_i : end_token.value.to_f
|
192
|
+
advance
|
193
|
+
(start_value...end_value)
|
194
|
+
else
|
195
|
+
# Just a single number, treat as single-element array
|
196
|
+
[start_value]
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
def convert_array_expression_to_ruby_array(array_expr)
|
201
|
+
return nil unless array_expr.is_a?(Kumi::Syntax::ArrayExpression)
|
202
|
+
|
203
|
+
array_expr.elements.map do |element|
|
204
|
+
if element.is_a?(Kumi::Syntax::Literal)
|
205
|
+
element.value
|
206
|
+
else
|
207
|
+
# For non-literal elements, we'd need more complex evaluation
|
208
|
+
# For now, just return the element as-is
|
209
|
+
element
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
167
214
|
# Value declaration: 'value :name, expression' or 'value :name do ... end'
|
168
215
|
def parse_value_declaration
|
169
216
|
value_token = expect_token(:value)
|
@@ -494,6 +541,13 @@ module Kumi
|
|
494
541
|
case token_type
|
495
542
|
when :eq then :==
|
496
543
|
when :ne then :!=
|
544
|
+
when :gt then :>
|
545
|
+
when :lt then :<
|
546
|
+
when :gte then :>=
|
547
|
+
when :lte then :<=
|
548
|
+
when :and then :and
|
549
|
+
when :or then :or
|
550
|
+
when :exponent then :**
|
497
551
|
else token_type
|
498
552
|
end
|
499
553
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'token_metadata'
|
4
|
+
require_relative 'token'
|
5
|
+
require_relative 'errors'
|
4
6
|
|
5
7
|
module Kumi
|
6
8
|
module Parser
|
@@ -243,6 +245,43 @@ module Kumi
|
|
243
245
|
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
244
246
|
@tokens << Token.new(:lt, '<', location, Kumi::Parser::TOKEN_METADATA[:lt])
|
245
247
|
end
|
248
|
+
when '*'
|
249
|
+
if peek_char == '*'
|
250
|
+
advance
|
251
|
+
advance
|
252
|
+
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
253
|
+
@tokens << Token.new(:exponent, '**', location, Kumi::Parser::TOKEN_METADATA[:exponent])
|
254
|
+
else
|
255
|
+
# Single asterisk: fall through to single character handling
|
256
|
+
token_type = CHAR_TO_TOKEN[char]
|
257
|
+
metadata = Kumi::Parser::TOKEN_METADATA[token_type].dup
|
258
|
+
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
259
|
+
@tokens << Token.new(token_type, char, location, metadata)
|
260
|
+
advance
|
261
|
+
end
|
262
|
+
when '.'
|
263
|
+
if peek_char == '.'
|
264
|
+
advance
|
265
|
+
if peek_char == '.'
|
266
|
+
# Three dots: ...
|
267
|
+
advance
|
268
|
+
advance
|
269
|
+
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
270
|
+
@tokens << Token.new(:dot_dot_dot, '...', location, Kumi::Parser::TOKEN_METADATA[:dot_dot_dot])
|
271
|
+
else
|
272
|
+
# Two dots: ..
|
273
|
+
advance
|
274
|
+
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
275
|
+
@tokens << Token.new(:dot_dot, '..', location, Kumi::Parser::TOKEN_METADATA[:dot_dot])
|
276
|
+
end
|
277
|
+
else
|
278
|
+
# Single dot: fall through to single character handling
|
279
|
+
token_type = CHAR_TO_TOKEN[char]
|
280
|
+
metadata = Kumi::Parser::TOKEN_METADATA[token_type].dup
|
281
|
+
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
282
|
+
@tokens << Token.new(token_type, char, location, metadata)
|
283
|
+
advance
|
284
|
+
end
|
246
285
|
else
|
247
286
|
# Single character operators/punctuation
|
248
287
|
token_type = CHAR_TO_TOKEN[char]
|
@@ -36,6 +36,7 @@ module Kumi
|
|
36
36
|
FN = :fn
|
37
37
|
|
38
38
|
# Operators (by precedence)
|
39
|
+
EXPONENT = :exponent # **
|
39
40
|
MULTIPLY = :multiply # *
|
40
41
|
DIVIDE = :divide # /
|
41
42
|
MODULO = :modulo # %
|
@@ -52,6 +53,8 @@ module Kumi
|
|
52
53
|
|
53
54
|
# Punctuation
|
54
55
|
DOT = :dot # .
|
56
|
+
DOT_DOT = :dot_dot # ..
|
57
|
+
DOT_DOT_DOT = :dot_dot_dot # ...
|
55
58
|
COMMA = :comma # ,
|
56
59
|
COLON = :colon # :
|
57
60
|
LPAREN = :lparen # (
|
@@ -149,6 +152,12 @@ module Kumi
|
|
149
152
|
},
|
150
153
|
|
151
154
|
# Operators with precedence and associativity
|
155
|
+
exponent: {
|
156
|
+
category: :operator,
|
157
|
+
precedence: 7,
|
158
|
+
associativity: :right,
|
159
|
+
arity: :binary
|
160
|
+
},
|
152
161
|
multiply: {
|
153
162
|
category: :operator,
|
154
163
|
precedence: 6,
|
@@ -275,6 +284,12 @@ module Kumi
|
|
275
284
|
category: :punctuation,
|
276
285
|
indicates_member_access: true
|
277
286
|
},
|
287
|
+
dot_dot: {
|
288
|
+
category: :range
|
289
|
+
},
|
290
|
+
dot_dot_dot: {
|
291
|
+
category: :range
|
292
|
+
},
|
278
293
|
comma: {
|
279
294
|
category: :punctuation,
|
280
295
|
separates_items: true
|
data/lib/kumi/parser/version.rb
CHANGED