-
Notifications
You must be signed in to change notification settings - Fork 63
Get rid of PResult (WIP) #202
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #202 +/- ##
==========================================
+ Coverage 95.86% 95.88% +0.01%
==========================================
Files 54 54
Lines 21044 21158 +114
==========================================
+ Hits 20174 20287 +113
- Misses 870 871 +1
Continue to review full report at Codecov.
|
src/parser/control_parser.rs
Outdated
let condition = parse_expression(lexer); | ||
lexer.expect(KeywordThen)?; | ||
let condition = parse_primary_expression(lexer); | ||
expect_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.
I don't think we need this:
You can use parse in region or a similar method (there's one for statements) with a closing condition KeywordThen
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.
the parse_in_region is not good for this situation because it will try to recover until the next safe end-keywords eating everything in between:
IF condition
call1();
call2();
END_IF
the missing THEN would try to recover until the END_IF and ignore call1() and call2()
take a look how the parse_while_statement(...) treats the situation:
WHILE condition DO
...
END_WHILE
it enforces an expression after the while (and reports manually if it cannot find any) and consume_or_report the DO-keyword therefore surviving a missing DO-keyword.
only then it enters a end-while region (although maybe all of this could already be wrapped into the end-while-region)
src/parser/control_parser.rs
Outdated
let start = lexer.range().start; | ||
lexer.advance(); // FOR | ||
|
||
let counter_expression = parse_reference(lexer)?; | ||
lexer.expect(KeywordAssignment)?; // := | ||
let counter_expression = parse_reference(lexer); |
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.
If you formulate this as follows I think you can avoid the expect:
After the FOR keyword, you start a region that ends with DO
Inside this region you will get tokens for the Assignment, TO and BY. I think you can treat these as consume or report instances.
You would need to cover these by tests though (The for is an assignment, followed by a TO Reference, followed optionally by a BY reference and then closed by a DO)
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 think its a similar situation like in the first comment - but I'm not sure if I got everything right from your suggestion.
It would also be doable like the while again
let ref = match parse_reference(...) {
Err(..) => report meaningful error in the current context, return empty-statement
Ok(it) => it
};
allow(TO);
...
maybe you could even create a fancy method or macro for it
src/parser/control_parser.rs
Outdated
let selector = Box::new(parse_expression(lexer)?); | ||
let selector = Box::new(parse_primary_expression(lexer)); | ||
|
||
expect_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.
You can treat this as a region that ends with the OF
I will close this as a dead end and open a new pull request where I will build upon commit c9b45c5, since I already committed changes on this branch that turned out not suitable. |
This will resolve #196