Repository navigation
feat(py): reverse mode — port of interscript-rs src/reverse.rs (WO19 G10) - #857
Merged
Merged
Conversation
…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: Runtime.reverse reverses the dependency closure and serves the reversed docs under their forward names (rs reverse_document recursion); Runtime.load_map gains the ruby DSL.parse reverse-name load fallback; MapLoader.register mirrors interscript-ts. 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: pytest 450 collected, 0 failed (GOLDEN_ROOT set); 18 new reverse tests pass; py-vs-py parse parity driver canonical 435/435, raw 435/435 (hand rev 7a84260) — reverse adds no parse behavior.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WO19 G10: reverse mode ported to the py engine (
interscript-py/) — a choice-for-choice mirror of interscript-rssrc/reverse.rs, whose expectations are ruby ground truth (Interscript::Node::*#reverseover interscript-ruby origin/main, spec'd byspec/reversibility_spec.rb).src/interscript/reverse.py(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 downcaseswap via item case walks; funcalls invert through the RubyStdlib.reverse_functiontable; document name throughDocument.reverse_name; metadata swaps source/destination scripts; aliases/languages/dependencies pass through.reverse_runin 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'sassign_group_idsmints);prioritynegates per rubySub#reverse.Runtime.reversereverses the dependency closure and serves the reversed docs under their forward names (rsreverse_documentrecursion);Runtime.load_mapgains the rubyDSL.parsereverse-name load fallback (missing map whose reverse-named sibling exists loads that sibling reversed, cached under the requested code);MapLoader.registermirrors interscript-ts.unseparateadded (thereverse_functioncounterpart ofseparate);title_casecorrected to ruby parity (upcase the first char and the char after each word separator — no lowering of the rest).MapLogicErrors at reverse time (rsError::Unsupported): repeat under ato upcase/downcasesub, 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). Mirror of the interscript-ts G10 PR.
Test plan
PYTHONPATH=src python3 -m pytest -qwithGOLDEN_ROOTset — 450 collected, 0 failed (env-gated skips unchanged: 2 model-zip, 6 embedded-row)tests/test_reverse.pyincl. the real corpus mapALA-LC:bul-Cyrl:Latn:1997(Kirillicata->Кириллиcата) and all four documented-deviation error pathspython3 scripts/parse_parity_py.py --hand-rev 7a84260— canonical 435/435, raw 435/435 (reverse adds no parse behavior)tests/reverse.rs; fixtures vendored fromtests/reverse_maps/(plusrev-upcase-repeatfor the repeat deviation)