fix(faces): fix four PseudoScript transformer bugs#118
Merged
Conversation
- `output X` / `print X` / `display X` now lowers to `println(X)` instead of `IO.println(X)` (dropped stray `IO.` prefix). - `--` comment lines converted by `transform_double_dash_comment` no longer fall through to `apply_boolean_ops`, so `or` inside a comment is not clobbered with `||`. - `if`/`else if`/`while`/`for`/`match` condition strings now go through `apply_comparisons`, `apply_boolean_ops`, and `apply_literal_subs` before being emitted, so pseudocode operators in conditions lower correctly. - `transform_source` replaced with a brace-depth-tracking pass that inserts `;` after non-tail statements inside blocks, enabling multi-statement function bodies. Updated `examples/faces/hello-pseudo.affine` to exercise `set X to Y` and `output X` in a two-statement body. Updated snapshot. Removed the now-fixed Pseudocode row from `examples/faces/README.adoc`.
`transform_set` was calling `String.trim line` immediately, discarding any leading whitespace. Statements like ` set x to expr` inside a function body would lower to `let x = expr` at column 0, producing a snapshot mismatch with the 4-space-indented expected output. Fix: capture the leading indent before trimming and prepend it to the generated `let`/`let mut` expression. https://claude.ai/code/session_01Vrh2f1G8tf7ZbNcKh9r5U9
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
Fixes four text-transformer bugs in
lib/pseudocode_face.ml:output X→IO.println(X)(wrong prefix) —transform_io_outputwas emittingIO.println(instead ofprintln(. Dropped the strayIO.prefix.--comments —transform_double_dash_commentconverted-- SPDX-License-Identifier: AGPL-3.0-or-laterto// SPDX-License-Identifier: AGPL-3.0-or-later, but the line then fell through toapply_boolean_ops, turningor→||to produce// SPDX-License-Identifier: AGPL-3.||-||-later. Fixed by adding an early return intransform_linefor any line that starts with//after the--conversion step.if/else if/while/for/matchcondition text was emitted verbatim without running throughapply_comparisons,apply_boolean_ops, orapply_literal_subs. Addedapply_cond_subshelper and applied it everywhere.transform_sourcewas a trivialList.mapthat never inserted;, so multi-statement function bodies were syntactically invalid. Replaced with a brace-depth-tracking pass that inserts;after non-tail statements inside blocks (tail = the statement immediately before the matching}).Files changed
lib/pseudocode_face.mlexamples/faces/hello-pseudo.affineset X to Y+output Xin a two-statement bodytests/faces/hello-pseudo.expected.txtexamples/faces/README.adocTest plan
opam exec -- dune build lib/ bin/— confirms OCaml compiles./tools/run_face_transformer_tests.sh— snapshot regression:hello-pseudo.expected.txtshould matchpreview-pseudocodeoutputaffinescript preview-pseudocode examples/faces/hello-pseudo.affine— visually confirm output matchestests/faces/hello-pseudo.expected.txtaffinescript parse examples/faces/hello-pseudo.affine— confirm the lowered file parses without errorsGenerated by Claude Code