-
Notifications
You must be signed in to change notification settings - Fork 162
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
Changes made to ensure that '=>' token is parsed properly #3292
base: master
Are you sure you want to change the base?
Conversation
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.
Thanks @sriganeshres for contributing!! Could you add a testcase to your PR to ensure we don't introduce a regression on this in the future?
b86ad1a
to
62abc58
Compare
Working on that. I have ran Thank You. |
5aca0e5
to
7897d6e
Compare
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_expr): Updated parsing logic to stop on encountering '=>' or ',' while having restrictions.stop_on_token turned on. (Parser::left_denotations): Updated to stop parsing on the special tokens mentioned above. (Parser::null_denotation): Updated to stop parsing on the special tokens mentioned above. * parse/rust-parse.h (struct ParseRestrictions): Added a field stop_on_token (default false) to maintain the above functionality.
7897d6e
to
e7e7360
Compare
You could write a test from the snippet given in the fixed issue, it would pass with your changes |
* rust/compile/issue-3099.rs: Added a new test for issue-3099 to parse '=>' properly.
@@ -89,6 +89,8 @@ struct ParseRestrictions | |||
bool entered_from_unary = false; | |||
bool expr_can_be_null = false; | |||
bool expr_can_be_stmt = false; | |||
bool stop_on_token | |||
= false; // This is for stopping parsing at a specific token |
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.
What does this mean? It seems like a hack
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 doesnt seem correct to me the stop_on_token doesn't seem to be set to true anywhere so to me this doesn't seem to solve anything
_ => 20, | ||
}; | ||
|
||
let format = "Result: %d\n\0" as *const str as *const i8; |
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.
hi @sriganeshres, make sure that you also update your dejagnu regex to assert that you'll get out 15 from println!.
Without asserting the printf, you're just guarantee that we at least parse it successfully. Or successfully breaking something in the parser silently
} | ||
|
||
pub fn main() { | ||
unsafe { |
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.
is the unsafe necessary?
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 necessary for the printf
call, but not before - so it could be moved down a few lines indeed
@@ -12023,6 +12023,11 @@ Parser<ManagedTokenSource>::parse_expr (int right_binding_power, | |||
if (restrictions.expr_can_be_null) | |||
{ | |||
TokenId id = current_token->get_id (); | |||
if (restrictions.stop_on_token && (id == MATCH_ARROW || id == COMMA)) |
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.
you're not setting stop_on_token to true so you're not entering these conditional either.
if (restrictions.stop_on_token | ||
&& (current_token->get_id () == MATCH_ARROW | ||
|| current_token->get_id () == COMMA)) |
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 seems weird. you'd want to enter left denotation and create the infix with =>
gcc/rust/ChangeLog:
Fixes #3099
Here is a checklist to help you with your PR.
make check-rust
passes locallyclang-format
gcc/testsuite/rust/
Parser::parse_expr
,Parser::left_denotations
,Parser::null_denotation
So that they stop on special token like=>
and,
. They would terminate the parsing to allow exatract expression.