-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Move non-grammar combinators to Parser
#40
Merged
Conversation
This file contains 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
So far, I've been using the combinator's name when moving them to `Parser`. The problem is `recognize` and `consumed` parallel each other but its not obvious by the name. `combine` calls it `recognize_with_value`. `nom-supreme` takes the approach of `Parser::with_recognized`. I feel like that makes the intent clear. The problem comes in that `with_recognized` implies an order (`u32.with_recognized()`), so I needed to swap the order of the tuple elements compared to `consumed`, `combine`s `recognize_with_value`, and ` `nom-supreme`s `with_recognized`.
This is a translation of `dbg_dmp`. The name changed because we are only printing errors, we might want to print something else in the future Random thoughts on the name - `debug` is out because that implies a debug build (`debug_assert`) - `dbg` mirrors `dbg!` for dumping content to output - `_err` is a common suffix (`unwrap_err`) - We want this easily discoverably to audit to prevent going into production. People likely will audit for `dbg` so having a similar name will likely get this caught as well. I had also considered `dump_err` which I favored until I considered code audits. As for functionality, this adds - Support for any input that supports `AsBytes`, instead of just `&[u8]` - Allows any displayable context - Print to stderr, instead of stdout
Pull Request Test Coverage Report for Build 3709890254
💛 - Coveralls |
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.
This is a followup to #37 and is working towards rust-bakery/nom#1408
The criteria for moving parsers was if they were common enough and did not affect the grammar. This way, the code structure can help highlight the grammar. This means I left out
cut
. While it mutates the error, likecomplerte
, it does so in a way that affects parsing and it should be elevated (I think). I'm still a little mixed on that one.Highlights
consumed
->Parser::with_recognized
recognize
andconsumed
parallel each otherbut its not obvious by the name.
combine
calls itrecognize_with_value
.nom-supreme
takes the approach ofParser::with_recognized
. I feel like that makes the intent clear.The problem comes in that
with_recognized
implies an order(
u32.with_recognized()
), so I needed to swap the order of the tupleelements compared to
consumed
,combine
srecognize_with_value
, andnom-supreme
swith_recognized
.dbg_dmp
->Parser::dbg_err
print something else in the future. See that commit for more details
AsBytes
, instead of just&[u8]