This repository was archived by the owner on Jun 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
checking Eof before calling parseIdent #596
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c38341d
checking Eof before calling parseIdent
Sehun0819 f01534e
check Eof before calling Parser.next
Sehun0819 c8608dd
add guard for Parser.next
Sehun0819 32387e3
add error handling & fix pattern matching
Sehun0819 12d00eb
fix pattern match Eof
Sehun0819 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
("_", mkLoc startPos p.prevEndPos) | ||
| _ -> ( | ||
match recoverLident p with | ||
| Some () -> parseLident p | ||
|
@@ -600,6 +603,9 @@ let parseHashIdent ~startPos p = | |
in | ||
Parser.next p; | ||
(i, mkLoc startPos p.prevEndPos) | ||
| Eof -> | ||
Parser.err ~startPos p (Diagnostics.unexpected p.token p.breadcrumbs); | ||
("", mkLoc startPos p.prevEndPos) | ||
| _ -> parseIdent ~startPos ~msg:ErrorMessages.variantIdent p | ||
|
||
(* Ldot (Ldot (Lident "Foo", "Bar"), "baz") *) | ||
|
@@ -635,11 +641,11 @@ let parseValuePath p = | |
Parser.err p (Diagnostics.unexpected p.Parser.token p.breadcrumbs); | ||
Longident.Lident ident) | ||
in | ||
if p.token <> Eof then Parser.next p; | ||
Parser.nextUnsafe p; | ||
res | ||
| token -> | ||
Parser.err p (Diagnostics.unexpected token p.breadcrumbs); | ||
Parser.next p; | ||
Parser.nextUnsafe p; | ||
Longident.Lident "_" | ||
in | ||
Location.mkloc ident (mkLoc startPos p.prevEndPos) | ||
|
@@ -826,7 +832,7 @@ let parseConstant p = | |
Parser.err p (Diagnostics.unexpected token p.breadcrumbs); | ||
Pconst_string ("", None) | ||
in | ||
Parser.next p; | ||
Parser.nextUnsafe p; | ||
constant | ||
|
||
let parseTemplateConstant ~prefix (p : Parser.t) = | ||
|
@@ -1090,6 +1096,10 @@ let rec parsePattern ?(alias = true) ?(or_ = true) p = | |
in | ||
Parser.next p; | ||
(i, mkLoc startPos p.prevEndPos) | ||
| Eof -> | ||
Parser.err ~startPos p | ||
(Diagnostics.unexpected p.token p.breadcrumbs); | ||
("", mkLoc startPos p.prevEndPos) | ||
| _ -> parseIdent ~msg:ErrorMessages.variantIdent ~startPos p | ||
in | ||
match p.Parser.token with | ||
|
@@ -1113,6 +1123,9 @@ let rec parsePattern ?(alias = true) ?(or_ = true) p = | |
let extension = parseExtension p in | ||
let loc = mkLoc startPos p.prevEndPos in | ||
Ast_helper.Pat.extension ~loc ~attrs extension | ||
| Eof -> | ||
Parser.err p (Diagnostics.unexpected p.Parser.token p.breadcrumbs); | ||
Recover.defaultPattern () | ||
| token -> ( | ||
Parser.err p (Diagnostics.unexpected token p.breadcrumbs); | ||
match | ||
|
@@ -1859,6 +1872,10 @@ and parseAtomicExpr p = | |
Parser.err p (Diagnostics.lident token); | ||
Parser.next p; | ||
Recover.defaultExpr () | ||
| Eof -> | ||
Parser.err ~startPos:p.prevEndPos p | ||
(Diagnostics.unexpected p.Parser.token p.breadcrumbs); | ||
Recover.defaultExpr () | ||
| token -> ( | ||
let errPos = p.prevEndPos in | ||
Parser.err ~startPos:errPos p (Diagnostics.unexpected token p.breadcrumbs); | ||
|
@@ -1897,7 +1914,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 commentThe reason will be displayed to describe this comment to others. Learn more. Though just using |
||
let stringStart = p.startPos in | ||
match p.Parser.token with | ||
| String s -> ( | ||
|
@@ -3249,7 +3266,10 @@ and parseForRest hasOpeningParen pattern startPos p = | |
Parser.err p (Diagnostics.unexpected token p.breadcrumbs); | ||
Asttypes.Upto | ||
in | ||
Parser.next p; | ||
if p.Parser.token = Eof then | ||
Parser.err ~startPos:p.startPos p | ||
(Diagnostics.unexpected p.Parser.token p.breadcrumbs) | ||
else Parser.next p; | ||
let e2 = parseExpr ~context:WhenExpr p in | ||
if hasOpeningParen then Parser.expect Rparen p; | ||
Parser.expect Lbrace p; | ||
|
@@ -3607,7 +3627,7 @@ and parseValueOrConstructor p = | |
Ast_helper.Exp.ident ~loc (Location.mkloc lident loc) | ||
| token -> | ||
if acc = [] then ( | ||
Parser.next p; | ||
Parser.nextUnsafe p; | ||
Parser.err p (Diagnostics.unexpected token p.breadcrumbs); | ||
Recover.defaultExpr ()) | ||
else | ||
|
@@ -3808,7 +3828,11 @@ and parseAtomicTypExpr ~attrs p = | |
| SingleQuote -> | ||
Parser.next p; | ||
let ident, loc = | ||
parseIdent ~msg:ErrorMessages.typeVar ~startPos:p.startPos p | ||
if p.Parser.token = Eof then ( | ||
Parser.err ~startPos:p.startPos p | ||
(Diagnostics.unexpected p.Parser.token p.breadcrumbs); | ||
("", mkLoc p.startPos p.prevEndPos)) | ||
else parseIdent ~msg:ErrorMessages.typeVar ~startPos:p.startPos p | ||
in | ||
Ast_helper.Typ.var ~loc ~attrs ident | ||
| Underscore -> | ||
|
@@ -3854,6 +3878,9 @@ and parseAtomicTypExpr ~attrs p = | |
let loc = mkLoc startPos p.prevEndPos in | ||
Ast_helper.Typ.extension ~attrs ~loc extension | ||
| Lbrace -> parseRecordOrObjectType ~attrs p | ||
| Eof -> | ||
Parser.err p (Diagnostics.unexpected p.Parser.token p.breadcrumbs); | ||
Recover.defaultType () | ||
| token -> ( | ||
Parser.err p (Diagnostics.unexpected token p.breadcrumbs); | ||
match | ||
|
@@ -4596,7 +4623,11 @@ and parseTypeParam p = | |
| SingleQuote -> | ||
Parser.next p; | ||
let ident, loc = | ||
parseIdent ~msg:ErrorMessages.typeParam ~startPos:p.startPos p | ||
if p.Parser.token = Eof then ( | ||
Parser.err ~startPos:p.startPos p | ||
(Diagnostics.unexpected p.Parser.token p.breadcrumbs); | ||
("", mkLoc p.startPos p.prevEndPos)) | ||
else parseIdent ~msg:ErrorMessages.typeParam ~startPos:p.startPos p | ||
in | ||
Some (Ast_helper.Typ.var ~loc ident, variance) | ||
| Underscore -> | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
Syntax error! | ||
tests/parsing/errors/other/for.res:1:6-2:0 | ||
|
||
1 │ for x | ||
2 │ | ||
|
||
Did you forget a `in` here? | ||
|
||
;;for x = [%rescript.exprhole ] to [%rescript.exprhole ] do | ||
[%rescript.exprhole ] | ||
done |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
for x |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
|
||
Syntax error! | ||
tests/parsing/errors/typeDef/keywordOnly.res:1:5 | ||
|
||
1 │ type | ||
|
||
I'm not sure what to parse here when looking at "eof". | ||
|
||
type nonrec _ |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
type |
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 looks good, perhaps put this line, which is repeated many times, in a function?