Proposal - use guards in expanded code - #159
Closed
dkuku wants to merge 4 commits into
Closed
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>
A range set expanding to three or more comparisons, or matching a well-known class, is emitted once per module as a defguardp and shared by every parser using it. Guards are named after the class they match, or after a hash of the ranges, so the same set always resolves to the same guard regardless of compilation order. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Member
|
Thanks but I’d rather not go down this path. The code is not meant to be readable, the guards are going to be macro expanded anyway (so it won’t be faster), and it adds more code to the compiler, so the benefits are not there. The $ token changes would not hurt though. :) |
Contributor
Author
|
ok, closing this one. |
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.
I think the readme update explains it best.
It generates guards for the function heads to avoid repetition.
I tested it on cldr parser and there is almost 500 lines less on a 9k lines file - the code also is more readable.