Skip to content

Commit 845fb21

Browse files
committed
feat(isc): stage_item accepts comments/noops, run stage.X, rababa directive, list_item as item
- Parser: stage_item now accepts comments and stray identifiers as no-ops - Parser: run_rule accepts 'run stage.Y' (without map.X prefix) - Parser: list_item uses item (not quoted_string | item) for proper concat - Codemod: rababa config: directive converted to comment - DocumentBuilder: handle Parslet::Slice in extract_rule/stage_items - Transform: use fully-qualified materialize_item in capture/maybe/some Verification: 226/289 maps equivalent (78%).
1 parent cfbe549 commit 845fb21

5 files changed

Lines changed: 39 additions & 15 deletions

File tree

exe/codemod-imp-to-isc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ module Interscript
121121
convert_stage_header
122122
elsif @scanner.scan(/\b(parallel|sequence|separate|deep|compose|downcase|upcase|title_case)\b/)
123123
@out << @scanner.matched
124+
elsif @scanner.scan(/\brababa\b/)
125+
# rababa config: "200" — special directive, pass through as comment
126+
rest = @scanner.scan_until(/\n/)
127+
@out << "# rababa directive: #{rest.chomp}\n"
124128
elsif @scanner.scan(/\bsub\b/)
125129
@out << "sub"
126130
convert_sub_rule

lib/interscript/isc/document_builder.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,16 @@ def extract_aliases(arr)
145145

146146
def extract_tests(arr)
147147
Array(arr).map do |t|
148+
next { input: "", expected: "" } unless t.is_a?(Hash)
149+
150+
input_val = t[:input]
151+
expected_val = t[:expected]
152+
note_val = t[:note]
153+
148154
{
149-
input: unquote(t[:input]),
150-
expected: unquote(t[:expected]),
151-
note: t[:note] && unquote(t[:note]),
155+
input: input_val.is_a?(Hash) ? unquote(input_val) : input_val.to_s,
156+
expected: expected_val.is_a?(Hash) ? unquote(expected_val) : expected_val.to_s,
157+
note: note_val.is_a?(Hash) ? unquote(note_val) : note_val&.to_s,
152158
}.compact
153159
end
154160
end
@@ -161,23 +167,30 @@ def extract_stage(item)
161167
end
162168

163169
def extract_stage_items(n)
170+
return [] unless n.is_a?(Hash)
164171
case
165172
when n[:sequence] then [{ kind: :sequence, rules: Array(n[:sequence]).map { |r| extract_rule(r) } }]
166173
when n[:parallel] then [{ kind: :parallel, rules: Array(n[:parallel]).map { |r| extract_rule(r) } }]
167174
when n[:separate] then [{ kind: :separate }]
168175
when n[:compose] then [{ kind: :compose }]
169176
when n[:case] then [{ kind: :string_case, op: n[:case].to_s }]
170177
when n[:dep] then [{ kind: :run, dependency: ident(n[:dep]), stage: ident(n[:stage]) }]
178+
when n[:run_stage_only] then [{ kind: :run, dependency: nil, stage: ident(n[:run_stage_only]) }]
171179
when n[:bare_rule] then [{ kind: :bare_rule, rule: extract_rule(n[:bare_rule]) }]
180+
when n[:comment] then []
181+
when n[:noop] then []
172182
else []
173183
end
174184
end
175185

176186
def extract_rule(r)
187+
from_val = r.is_a?(Hash) ? r[:from] : nil
188+
to_val = r.is_a?(Hash) ? r[:to] : nil
189+
constraints_val = r.is_a?(Hash) ? r[:constraints] : nil
177190
{
178-
from: materialize(r[:from]),
179-
to: materialize(r[:to]),
180-
constraints: extract_constraints(r[:constraints]),
191+
from: from_val ? materialize(from_val) : Items::None.new,
192+
to: to_val ? materialize(to_val) : Items::None.new,
193+
constraints: extract_constraints(constraints_val),
181194
}
182195
end
183196

lib/interscript/isc/grammar/concerns/items.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,9 @@ module Items
8787
whitespace? >> str("]"))
8888
end
8989

90-
# A list item can be a quoted string OR a more complex expression
91-
# (e.g., `boundary + "X"` for concat inside a list).
90+
# A list item is an item expression (which includes quoted strings).
9291
rule(:list_item) do
93-
quoted_string | item
92+
item
9493
end
9594

9695
rule(:alias_reference) do

lib/interscript/isc/grammar/concerns/stages.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,17 @@ module Stages
2020
rule(:stage_item) do
2121
whitespace? >>
2222
(sequence_block | parallel_block | run_rule | separate_directive |
23-
string_case_directive | compose_directive | bare_rule) >>
23+
string_case_directive | compose_directive | bare_rule |
24+
comment_item) >>
2425
whitespace?
2526
end
2627

28+
# Comments and stray identifiers are silently consumed.
29+
rule(:comment_item) do
30+
(str("#") >> (str("\n").absent? >> any).repeat).as(:comment) |
31+
identifier.as(:noop)
32+
end
33+
2734
# Bare rule directly in a stage body (not wrapped in sequence/parallel).
2835
# The original .imp allows this; treat it as a one-rule sequence.
2936
rule(:bare_rule) do
@@ -86,8 +93,9 @@ module Stages
8693

8794
rule(:run_rule) do
8895
str("run") >> whitespace >>
89-
str("map.") >> identifier.as(:dep) >>
90-
str(".stage.") >> identifier.as(:stage)
96+
((str("map.") >> identifier.as(:dep) >>
97+
str(".stage.") >> identifier.as(:stage)) |
98+
(str("stage.") >> identifier.as(:stage)).as(:run_stage_only))
9199
end
92100
end
93101
end

lib/interscript/isc/transform.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ class Transform < Parslet::Transform
5555
rule(function: simple(:f)) { Items::Function.new(f.to_s) }
5656
rule(alias: simple(:n)) { Items::AliasRef.new(n.to_s) }
5757
rule(ref: subtree(:h)) { Items::Capture.new(h[:digit].to_s.to_i) }
58-
rule(capture_inner: subtree(:inner)) { Items::CaptureGroup.new(materialize_item(inner)) }
59-
rule(maybe_inner: subtree(:inner)) { Items::Maybe.new(materialize_item(inner)) }
60-
rule(some_inner: subtree(:inner)) { Items::Some.new(materialize_item(inner)) }
58+
rule(capture_inner: subtree(:inner)) { Items::CaptureGroup.new(Interscript::Isc::Transform.materialize_item(inner)) }
59+
rule(maybe_inner: subtree(:inner)) { Items::Maybe.new(Interscript::Isc::Transform.materialize_item(inner)) }
60+
rule(some_inner: subtree(:inner)) { Items::Some.new(Interscript::Isc::Transform.materialize_item(inner)) }
6161

6262
rule(dquote: simple(:_)) { '"' }
6363
rule(backslash: simple(:_)) { "\\" }

0 commit comments

Comments
 (0)