-
Notifications
You must be signed in to change notification settings - Fork 38
checking Eof before calling parseIdent #596
Conversation
Looking good. A helper function for the error message should be more then enough to reduce boilerplate. |
Thank you. Lines 3603 to 3617 in 08029af
Concretely, |
There's no harm in doing all the non-obvious cases For comparison there's a PR showing how horrible the code would look using exception analysis |
This PR: #543 |
@@ -1906,7 +1915,7 @@ and parseFirstClassModuleExpr ~startPos p = | |||
and parseBracketAccess p expr startPos = | |||
Parser.leaveBreadcrumb p Grammar.ExprArrayAccess; | |||
let lbracket = p.startPos in | |||
Parser.next p; | |||
Parser.expect Lbracket p; |
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.
Though just using Parser.next
is safe as p
is always Lbracket
, this change would make it more clear.
I looked over every
|
src/res_core.ml
Outdated
with | ||
| None -> Recover.defaultPattern () | ||
| Some () -> parsePattern p) | ||
if p.Parser.token = Eof then Recover.defaultPattern () |
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.
Error message missing
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.
Can be moved to case in pattern matching
src/res_core.ml
Outdated
| Some () -> parseLident p | ||
| None -> ("_", mkLoc startPos p.prevEndPos)) | ||
| token -> ( | ||
if token = Eof then ( |
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 move this to a case in pattern matching
src/res_core.ml
Outdated
@@ -600,7 +604,11 @@ let parseHashIdent ~startPos p = | |||
in | |||
Parser.next p; | |||
(i, mkLoc startPos p.prevEndPos) | |||
| _ -> parseIdent ~startPos ~msg:ErrorMessages.variantIdent p | |||
| token -> | |||
if token = Eof then ( |
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 move this to a case in the pattern matching.
src/res_core.ml
Outdated
@@ -1090,7 +1098,12 @@ let rec parsePattern ?(alias = true) ?(or_ = true) p = | |||
in | |||
Parser.next p; | |||
(i, mkLoc startPos p.prevEndPos) | |||
| _ -> parseIdent ~msg:ErrorMessages.variantIdent ~startPos p | |||
| token -> | |||
if token = Eof then ( |
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.
Case in pattern matching
src/res_core.ml
Outdated
with | ||
| None -> Recover.defaultExpr () | ||
| Some () -> parseAtomicExpr p) | ||
if p.Parser.token = Eof then Recover.defaultExpr () |
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.
Error missing
src/res_core.ml
Outdated
Parser.err ~startPos:p.prevEndPos p | ||
(Diagnostics.unexpected token p.breadcrumbs); | ||
Recover.defaultType ()) | ||
if p.Parser.token = Eof then Recover.defaultType () |
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.
Error missing
How about now? |
src/res_core.ml
Outdated
match recoverLident p with | ||
| Some () -> parseLident p | ||
| None -> ("_", mkLoc startPos p.prevEndPos)) | ||
| token when token = Eof -> |
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.
simply | Eof
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.
😱
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 is looking great.
Any tests missing, that trigger the new cases?
@@ -556,6 +556,9 @@ let rec parseLident p = | |||
Parser.next p; | |||
let loc = mkLoc startPos p.prevEndPos in | |||
(ident, loc) | |||
| Eof -> | |||
Parser.err ~startPos p (Diagnostics.unexpected p.Parser.token p.breadcrumbs); |
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 looks good, perhaps put this line, which is repeated many times, in a function?
Merged as needed for release |
Handling #594.
Guards are added before
parseIdent
, to prevent it from callingParser.next
onEof
.