Skip to main content

Module reverse

Module reverse 

Source
Expand description

Interscript::Node::*#reverse parity for the slice-1 subset: reversed documents, stages, sub rules (with boundary-alias transfer + capture/ref exchange), funcall inversion, and the reverse_name convention.

Ground truth is interscript-ruby origin/main (lib/interscript/node/*.rb); every rule here mirrors the Ruby method named in its comment. The reversed document runs through the NORMAL executor — the interpreter skips rules whose reverse_run == Some(true), so the inversion lives entirely in the produced document. Capture numbering is positional: refs stay untouched numbers and groups re-number in regex order over the reversed rule (assign_group_ids), reproducing Ruby’s build_regexp numbering exactly.

Known deviations (all documented at the site): where the Ruby reverse would crash (NoMethodError on repeat items in case-swap subs, children= on a compacted-away from group, an upcase funcall missing from reverse_function), this implementation raises a clean Unsupported carrying the same information.

Functions§

item_downcase
Item#downcase: String data downcases; Group/CaptureGroup recurse; Alias (incl. boundary prims) and refs/ranges are identity; Any rebuilds from per-char entries.
item_upcase
Item#upcase.
reverse_document
Interscript::Node::Document#reverse. Aliases are NOT reversed (rdoc.aliases = self.aliases); tests swap their pairs; dependency documents reverse recursively.
reverse_name
Interscript::Node::Document.reverse_name: split on -, swap positions 2/3 (source/target code) when there are at least 4 segments; otherwise strip a -reverse suffix, otherwise append one.
reverse_stage
Interscript::Node::Stage#reverse / Group#reverse: children in REVERSE order, each reversed, reverse_run toggled. (The ISC grammar cannot express dont_reverse, so stages always reverse.)
reverse_sub
Interscript::Node::Rule::Sub#reverse.