Skip to content

Commit 904eaf0

Browse files
committed
fix: serialise Any Range/String payloads as any_char_class
Ruby's Node::Item::Any compiles differently depending on the payload: Array → alternation `(?:a|b|c)`, String → char class `[abc]`, Range → char class `[a-z]`. The IR serialiser was treating all three the same (Array form), which expanded Ranges via String#succ into nonsense like "zzz" and missed most of the BMP. Maps that used `any("\\u0061".."\\uFFFF")` for post-rule upcase failed because the expanded list didn't include extended-Latin characters like ā. Emit {kind: "any_char_class", range: [first, last]} for Range payloads and {kind: "any_char_class", chars: [...]} for String payloads. The interscript-ts runtime handles both forms via the AnyCharClassItem variant introduced in the parallel-mode parity work. Companion PR: interscript/interscript-ts#5
1 parent d98ee14 commit 904eaf0

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

lib/interscript/compiler/json_ir.rb

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,20 @@ def serialise_item(item)
194194
out[:map] = item.map if item.map
195195
out
196196
when Interscript::Node::Item::Any
197-
data = item.data || []
198-
{kind: "any", of: data.map { |i| serialise_item(i) }}
197+
# Any with a String payload becomes a character class in Ruby's
198+
# regex compilation. Range payloads become `[first-last]`. Both
199+
# must survive IR serialisation as char-class form, NOT expanded
200+
# into alternatives — Ruby's String#succ expansion of "a".."ᖵ"
201+
# produces nonsense like "zzz" and misses most of the BMP.
202+
case item.value
203+
when ::Range
204+
{kind: "any_char_class", range: [item.value.first, item.value.last]}
205+
when ::String
206+
{kind: "any_char_class", chars: item.value.split("")}
207+
else
208+
data = item.data || []
209+
{kind: "any", of: data.map { |i| serialise_item(i) }}
210+
end
199211
when Interscript::Node::Item::Group
200212
{kind: "group", items: item.children.map { |i| serialise_item(i) }}
201213
when Interscript::Node::Item::Repeat

0 commit comments

Comments
 (0)