kumi-parser 0.0.5 → 0.0.6
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 +58 -5
- data/lib/kumi/parser/smart_tokenizer.rb +23 -0
- data/lib/kumi/parser/token_metadata.rb +8 -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: 619858334f12737c169ccc4e1ba96792dff9e960af9fd533d79362cb58e003af
|
4
|
+
data.tar.gz: ce3455eeb43f52a6a58547159b23ae4885ede44c0c3c6cd1852379163454f080
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a034d7576f30d95c46051ab3572ce942617893dc5ea4e48ff01392972e488dd46dddbfab513db4d6614187abab331d0948646dfe931431a22c33aaa01f0a1464
|
7
|
+
data.tar.gz: c134ef68d51c176adaf70eb6cab9f2d66e9448ee80008906e92c05dc0503994d108640f213faa2a1d7ed038578797c110d58ea684e63f9aa293b8375d24d9eb8
|
@@ -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,12 @@ 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
|
497
550
|
else token_type
|
498
551
|
end
|
499
552
|
end
|
@@ -243,6 +243,29 @@ module Kumi
|
|
243
243
|
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
244
244
|
@tokens << Token.new(:lt, '<', location, Kumi::Parser::TOKEN_METADATA[:lt])
|
245
245
|
end
|
246
|
+
when '.'
|
247
|
+
if peek_char == '.'
|
248
|
+
advance
|
249
|
+
if peek_char == '.'
|
250
|
+
# Three dots: ...
|
251
|
+
advance
|
252
|
+
advance
|
253
|
+
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
254
|
+
@tokens << Token.new(:dot_dot_dot, '...', location, Kumi::Parser::TOKEN_METADATA[:dot_dot_dot])
|
255
|
+
else
|
256
|
+
# Two dots: ..
|
257
|
+
advance
|
258
|
+
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
259
|
+
@tokens << Token.new(:dot_dot, '..', location, Kumi::Parser::TOKEN_METADATA[:dot_dot])
|
260
|
+
end
|
261
|
+
else
|
262
|
+
# Single dot: fall through to single character handling
|
263
|
+
token_type = CHAR_TO_TOKEN[char]
|
264
|
+
metadata = Kumi::Parser::TOKEN_METADATA[token_type].dup
|
265
|
+
location = Kumi::Syntax::Location.new(file: @source_file, line: @line, column: start_column)
|
266
|
+
@tokens << Token.new(token_type, char, location, metadata)
|
267
|
+
advance
|
268
|
+
end
|
246
269
|
else
|
247
270
|
# Single character operators/punctuation
|
248
271
|
token_type = CHAR_TO_TOKEN[char]
|
@@ -52,6 +52,8 @@ module Kumi
|
|
52
52
|
|
53
53
|
# Punctuation
|
54
54
|
DOT = :dot # .
|
55
|
+
DOT_DOT = :dot_dot # ..
|
56
|
+
DOT_DOT_DOT = :dot_dot_dot # ...
|
55
57
|
COMMA = :comma # ,
|
56
58
|
COLON = :colon # :
|
57
59
|
LPAREN = :lparen # (
|
@@ -275,6 +277,12 @@ module Kumi
|
|
275
277
|
category: :punctuation,
|
276
278
|
indicates_member_access: true
|
277
279
|
},
|
280
|
+
dot_dot: {
|
281
|
+
category: :range
|
282
|
+
},
|
283
|
+
dot_dot_dot: {
|
284
|
+
category: :range
|
285
|
+
},
|
278
286
|
comma: {
|
279
287
|
category: :punctuation,
|
280
288
|
separates_items: true
|
data/lib/kumi/parser/version.rb
CHANGED