Skip to content

feat(reverse): reverse mode — port of interscript-rs src/reverse.rs (WO19 G10) - #139

Merged
ronaldtse merged 1 commit into
mainfrom
wo19-g10-ts
Nov 14, 2026
Merged

ronaldtse merged 1 commit into
mainfrom
wo19-g10-ts

Conversation

@ronaldtse

Copy link
Copy Markdown
Contributor

Summary

WO19 G10: reverse mode ported to the TS engine — a choice-for-choice mirror of interscript-rs src/reverse.rs, whose expectations are ruby ground truth (Interscript::Node::*#reverse over interscript-ruby origin/main, spec'd by spec/reversibility_spec.rb).

  • src/reverse.ts (new): stages reverse (children in reverse order, each rule reversed); sub rules swap from/to with boundary-like alias hoisting across the transfer and the capture/ref exchange; to upcase/to downcase swap via item case walks; funcalls invert through the Ruby Stdlib.reverse_function table; document name through Document.reverse_name; metadata swaps source/destination scripts; aliases/languages/dependencies pass through.
  • Compiled-IR deltas vs the rs node model (behavior identical, documented in the module docstring): no reverse_run in the IR — empty-reversed-from rules without assertions are dropped (ruby's own JSON-IR compilers omit them too); dependency recursion lives on the runtime entry point; capture groups are numbered by the regex engine in regex order (same numbers rs's assign_group_ids mints); priority negates per ruby Sub#reverse.
  • Runtime: InterscriptRuntime#reverse reverses the dependency closure and serves the reversed docs under their forward names (rs reverse_document recursion); loadMap/loadMapAsync gain the ruby DSL.parse reverse-name load fallback (missing map whose reverse-named sibling exists loads that sibling reversed, cached under the requested code).
  • Stdlib: unseparate added (the reverse_function counterpart of separate); titleCase corrected to ruby title_case parity (upcase the first char and the char after each word separator — no lowering of the rest).
  • Documented ruby-crash deviations surface as named MapLogicErrors at reverse time (rs Error::Unsupported): repeat under a to upcase/downcase sub, a boundary hoist consuming the whole from group, a funcall outside the reverse_function map, an unhandled item kind in the transfer walk.

Ruby/rs untouched (they already have reverse).

Test plan

  • npx vitest run — 404 passed / 4 skipped (408); 18 new reverse tests in test/reverse.test.ts incl. the real corpus map ALA-LC:bul-Cyrl:Latn:1997 (Kirillicata -> Кириллиcата) and all four documented-deviation error paths
  • npm run build (tsc) clean
  • npx eslint src test clean
  • npx prettier --check clean
  • Parity expectations ported 1:1 from interscript-rs tests/reverse.rs; fixtures vendored from tests/reverse_maps/ (plus rev-upcase-repeat for the repeat deviation)

…WO19 G10)

Mirror the rs reverse engine choice-for-choice at the compiled-IR
level: stages reverse (children in reverse order), sub rules swap
from/to with boundary-like alias hoisting across the transfer and the
capture/ref exchange, to upcase/downcase swap via item case walks,
funcalls invert through the Ruby Stdlib.reverse_function table, the
document name goes through Document.reverse_name, metadata swaps
source/destination scripts, aliases/languages/dependencies pass
through.

Runtime surface: InterscriptRuntime#reverse reverses the dependency
closure and serves the reversed docs under their forward names (rs
reverse_document recursion); loadMap/loadMapAsync gain the ruby
DSL.parse reverse-name load fallback. Stdlib: unseparate added
(reverse_function counterpart of separate); title_case corrected to
ruby parity (upcase first char and the char after each separator —
no lowering).

Documented ruby-crash deviations surface as named MapLogicErrors at
reverse time (rs Error::Unsupported): repeat under a to-upcase/downcase
sub, a boundary hoist consuming the whole from group, a funcall
outside the reverse_function map, an unhandled item kind in the
transfer walk.

Gates: vitest 404 passed / 4 skipped (408); eslint clean; prettier
clean; tsc build clean.
@ronaldtse
ronaldtse merged commit 20f527a into main Nov 14, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant