Skip to content

Fix pud fmt continuation indentation for character literals (fixes #11) - #31

Closed
Faizaanp wants to merge 2 commits into
puddi-lang:mainfrom
Faizaanp:fix/fmt-char-literal-continuation
Closed

Faizaanp wants to merge 2 commits into
puddi-lang:mainfrom
Faizaanp:fix/fmt-char-literal-continuation

Conversation

@Faizaanp

Copy link
Copy Markdown
Contributor

Summary

Fixes #11.

In src/tools.rs, strip_line_comment stripped trailing // line comments by tracking whether characters fell inside a string literal (b'"' => in_str = !in_str), but did not handle character literals (b'\'').

When a line contained a character literal with a double quote like '"', in_str became true for the remainder of the line. Consequently:

  1. Trailing // comments after '"' were not stripped, causing continuation lines ending in binary operators (e.g. c == '"' || // comment) to not be recognized as continuations.
  2. Comments following '"' that happened to end in operators (e.g. let c = '"' // check +) were treated as code, causing accidental continuation indentation on subsequent lines.

This PR updates strip_line_comment to skip character literals when !in_str, mirroring the char literal handling in the depth scanner and strip_strings.

Changes

  • src/tools.rs: Added char literal skipping to strip_line_comment.
  • src/tools.rs: Added regression unit tests:
    • format_handles_continuation_with_char_literal
    • format_char_literal_comment_does_not_trigger_continuation
  • CHANGELOG.md: Added entry under ### Fixed.

Checklist

  • Tests: a regression test, or conformance cases for language behavior (see CONTRIBUTING.md)
  • CHANGELOG.md updated under Unreleased, for user-visible changes
  • README or documentation updated, if commands or behavior they describe changed (N/A - formatting bug fix)

@ghfind-review ghfind-review Bot added the review: medium ghfind author score; see https://ghfind.com label Nov 28, 2026
@Faizaanp Faizaanp closed this Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review: medium ghfind author score; see https://ghfind.com

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keep formatter indentation stable after quoted character literals

1 participant