-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Update expression span when transcribing macro args #31089
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
b285ebc
Update expression span when transcribing macro args
fhahn 877ed0d
Update tests
fhahn 20edb36
Set span for interpolated tokens correctly
fhahn 1bde18d
Use interpolated token span when building spans for bigger expressions
fhahn 2bc8f4f
Add interpolated_or_expr_span macro and pass lo to newly added parse_…
fhahn 9d8c64b
Push try! to call site of interpolated_or_expr_span!
fhahn 47bfd8c
Turn interpolated_or_expr_span into a function
fhahn e533ed9
Avoid storing interolated token in Parser.last_token
fhahn ecb7b01
Add NOTE test annotations
fhahn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add interpolated_or_expr_span macro and pass lo to newly added parse_…
…dot_suffix
- Loading branch information
commit 2bc8f4ff80a4343bacfcab9629eb681e576dee48
There are no files selected for viewing
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this makes me feel better about the pattern here. (I still worry people may not know when to call this, but at least now it's easy to see and swap in.)
AFAICT, the reason you made this a macro is due to the use of
try!
in the given $parse_expr.I would prefer you make this a
fn
that returns Result, and shift the trys at the call sites.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a macro so it can be used with different methods for parsing expressions. In particular it is once used with Parser::parse_bottom_expr and also with Parser::parse_prefix_expr.
I've update the macro to return
Result
, which should have the same effect making it afn
, at least with respect to thetry!
(I hope). A similarfn
would have to take a closure which is probably slightly less ergomatic. However if you still think afn
would be better, I'd be happy to change that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your argument still doesn't make sense to me.
Both
Parser::parse_bottom_expr
andParser::parse_prefix_expr
have the same return type, so its not like you are using the macro to inject some kind of duck-typing...To be clear: You have a macro here that takes in two expressions as input (
$p
and$parse_expr
). It unconditionally evaluates both expressions at the outset. (There's a second evaluation of$p
but I don't think that was a deliberate choice.)So, why wouldn't this work:
(And then update the macro calls to call this method instead.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that makes sense. I've pushed another commit that turns it into a function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I now remembered to original reason for that being a macro. As it was,
interpolated_or_expr_span
used the current token to check if it is interpolated, which means the parse functions has to be called after that check.But by using
last_token
it works as expected. I pushed another commit however, which avoids storing (and cloning) interpolated tokens and instead added aParser.last_token_interpolated
flag.