Skip to content

Conversation

@geky
Copy link

@geky geky commented Dec 15, 2025

This avoids redundant newlines in the output when encountering a multiline char literal. I don't think multiline char literals are actually valid in C, but preserving the original whitespace is useful when mixed with other tooling.

Before:

'\(newline)  =>  '\(newline)
\(newline)       \(newline)
c'(newline)      c'(newline)
                 (newline)
                 (newline)

After:

'\(newline)  =>  '\(newline)
\(newline)       \(newline)
c'(newline)      c'(newline)

It looks like t_CPP_CHAR was trying to adjust the lineno for consumed newlines, but unlike t_CPP_STRING and t_CPP_COMMENT1, it doesn't actually consume any newlines.


As for how I even ran into this. I'm using pcpp to parse some, uh, non-C stuff, which pcpp's relaxed preprocessing is very useful for.

But I think this is unlikely to be encountered in real C code, so feel free to close if out-of-scope.

python setup.py test passed locally.

This avoids redundant newlines in the output when encountering a
multiline char literal. I don't think multiline char literals are
actually valid in C, but preserving the original whitespace is useful
when mixed with other tooling.

Before:

  '\(newline)  =>  '\(newline)
  \(newline)       \(newline)
  c'(newline)      c'(newline)
                   (newline)
                   (newline)

After:

  '\(newline)  =>  '\(newline)
  \(newline)       \(newline)
  c'(newline)      c'(newline)

It looks like t_CPP_CHAR was trying to adjust the lineno for consumed
newlines, but unlike t_CPP_STRING and t_CPP_COMMENT1, it doesn't
actually consume any newlines.
@geky geky force-pushed the fix-multiline-char-literal branch from 180d4f8 to 77df76e Compare December 15, 2025 22:34
@ned14
Copy link
Owner

ned14 commented Dec 16, 2025

Thanks for the PR.

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.

2 participants