Print codepoints in generated guards as character literals - #158
Merged
Conversation
While reading the generated files I had trouble parsing the ASCII codes in my head. `?a` and `97` are the same AST node, though, so the literal spelling has to be carried as `:token` metadata for `Macro.to_string/1` to print it. This makes `debug: true` and `mix nimble_parsec.compile` output readable at a glance. For codepoints with no printable spelling I use hex instead - `0xB80`, similar to `U+0B80`. Assisted-by: Claude Opus 5 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
josevalim
reviewed
Aug 13, 2026
| ?\t -> "?\\t" | ||
| ?\r -> "?\\r" | ||
| codepoint when codepoint in ?!..?~ -> "?" <> <<codepoint>> | ||
| codepoint -> "0x" <> String.pad_leading(Integer.to_string(codepoint, 16), 2, "0") |
Member
There was a problem hiding this comment.
Should we just fallback to a regular number in this case?
Member
|
💚 💙 💜 💛 ❤️ |
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.
While reading the generated files I had trouble parsing the ASCII codes in my head.
?aand97are the same AST node, though, so the literal spelling has to be carried as:tokenmetadata forMacro.to_string/1to print it.This makes
debug: trueandmix nimble_parsec.compileoutput readable at a glance. For codepoints with no printable spelling I use hex instead -0xB80, similar toU+0B80.Assisted-by: Claude Opus 5