fix(faces): stop appending ; to -- comment lines in LucidScript#119
Merged
Conversation
The previous pipeline first called `convert_dashdash_comment` (turning `-- text` into `// text`), then passed the result to `strip_dashdash_comment`. Because `strip_dashdash_comment` scans for `--` and found none in the converted line, it returned the entire `// text` string as the "code part". That code part fell through to the expression handler, which appended `;`, producing `// text;`. Fix: apply `strip_dashdash_comment` directly to the raw (pre-conversion) line. A `-- comment` line now yields an empty code part and a populated comment_opt, so it is emitted as `// text\n` with no trailing `;`. As a side effect, `convert_dashdash_comment` becomes unused and is deleted. `is_blank_line` is updated to treat canonical `//` lines as blank (so the next-meaningful-indent scan skips them), and a new dispatch branch in `transform_source` passes canonical `//`/`/*` lines through unchanged before they can reach the equation handler. Updated snapshot `tests/faces/hello-lucid.expected.txt`.
When a `--`-comment line has no text (e.g. just `--`), `strip_dashdash_comment` returns `Some ""`. The previous code would emit `"// " ^ "" ^ "\n"` = `"// \n"`, leaving a trailing space. The expected snapshot (and readable output) needs `"//\n"` with no trailing space. Fix: check the trimmed comment text and emit bare `"//"` when it is empty. https://claude.ai/code/session_01Vrh2f1G8tf7ZbNcKh9r5U9
When source ends with \n, String.split_on_char '\n' produces a trailing empty string. The loop processes it as an empty line, emitting an extra \n via Buffer.add_char — making output end with \n\n instead of \n. Strip the redundant newline at the end of transform_source so the output matches the snapshot (which was already updated to have exactly one trailing newline). 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 stray
;being appended to--comment lines inlib/lucid_face.ml.Root cause: the previous pipeline applied
convert_dashdash_commentto each raw line (turning-- text→// text), then passed the result tostrip_dashdash_comment. Becausestrip_dashdash_commentscans for--and finds none in// text, it returned the full// textstring as the code part with no comment. That code fell through to the expression handler, which appended;, producing// text;.Fix:
convert_dashdash_commententirely (now unused).strip_dashdash_commentdirectly to the raw (pre-conversion) line intransform_source. A-- commentline now yields an empty code part and a populatedcomment_opt, so it is emitted as// text\nwith no trailing;.is_blank_lineto treat canonical//lines as blank so the next-meaningful-indent scan correctly skips them.transform_sourcethat passes canonical////*lines through unchanged before they can reach the equation handler.Files changed
lib/lucid_face.mlconvert_dashdash_comment; fixstrip_dashdash_commentapplication; add//passthrough; fixis_blank_linetests/faces/hello-lucid.expected.txt;on comment linesTest plan
opam exec -- dune build lib/ bin/— confirms OCaml compiles./tools/run_face_transformer_tests.sh— snapshot regression:hello-lucid.expected.txtshould matchpreview-lucidoutputaffinescript preview-lucid examples/faces/hello-lucid.affine— visually confirm no;on comment linesaffinescript parse examples/faces/hello-lucid.affine— confirm the lowered file parses without errorsGenerated by Claude Code