-
Notifications
You must be signed in to change notification settings - Fork 163
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
{ | ||
rust_debug ("Stopping Parsing at special token"); | ||
return nullptr; | ||
} | ||
if (id == SEMICOLON || id == RIGHT_PAREN || id == RIGHT_CURLY | ||
|| id == RIGHT_SQUARE || id == COMMA || id == LEFT_CURLY) | ||
return nullptr; | ||
|
@@ -12078,6 +12083,14 @@ Parser<ManagedTokenSource>::left_denotations (std::unique_ptr<AST::Expr> expr, | |
while (right_binding_power < left_binding_power (current_token)) | ||
{ | ||
lexer.skip_token (); | ||
if (restrictions.stop_on_token | ||
&& (current_token->get_id () == MATCH_ARROW | ||
|| current_token->get_id () == COMMA)) | ||
Comment on lines
+12086
to
+12088
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 => |
||
{ | ||
rust_debug ( | ||
"Stopping parsing at restricted token in left_denotations"); | ||
return expr; | ||
} | ||
|
||
// FIXME attributes should generally be applied to the null denotation. | ||
expr = left_denotation (current_token, std::move (expr), | ||
|
@@ -12116,6 +12129,13 @@ Parser<ManagedTokenSource>::null_denotation (const_TokenPtr tok, | |
/* note: tok is previous character in input stream, not current one, as | ||
* parse_expr skips it before passing it in */ | ||
|
||
if (restrictions.stop_on_token | ||
&& (tok->get_id () == MATCH_ARROW || tok->get_id () == COMMA)) | ||
{ | ||
rust_debug ("Stopping parsing at restricted token in null_denotation"); | ||
return nullptr; | ||
} | ||
|
||
/* as a Pratt parser (which works by decomposing expressions into a null | ||
* denotation and then a left denotation), null denotations handle primaries | ||
* and unary operands (but only prefix unary operands) */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. What does this mean? It seems like a hack |
||
bool consume_semi = true; | ||
/* Macro invocations that are statements can expand without a semicolon after | ||
* the final statement, if it's an expression statement. */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
extern "C" { | ||
fn printf(s: *const i8, ...); | ||
} | ||
|
||
pub fn main() { | ||
unsafe { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. it's necessary for the |
||
let value = 10; | ||
let result = match value { | ||
10 => 15, | ||
_ => 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 commentThe 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 |
||
printf(format, result); | ||
} | ||
} |
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.