Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Recovery when encountering errors parsing long idents. #484

Merged
merged 2 commits into from
Apr 22, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 20 additions & 8 deletions src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -699,18 +699,28 @@ let parseValuePath p =
| Lident ident -> Longident.Ldot(path, ident)
| Uident uident ->
Parser.next p;
Parser.expect Dot p;
aux p (Ldot (path, uident))
if p.Parser.token = Dot then (
Parser.expect Dot p;
aux p (Ldot (path, uident))
) else (
Parser.err p (Diagnostics.unexpected p.Parser.token p.breadcrumbs);
path
)
| token ->
Parser.err p (Diagnostics.unexpected token p.breadcrumbs);
Longident.Lident "_"
Longident.Ldot (path, "_")
in
let ident = match p.Parser.token with
| Lident ident -> Longident.Lident ident
| Uident ident ->
Parser.next p;
Parser.expect Dot p;
aux p (Lident ident)
if p.Parser.token = Dot then (
Parser.expect Dot p;
aux p (Lident ident)
) else (
Parser.err p (Diagnostics.unexpected p.Parser.token p.breadcrumbs);
Longident.Lident ident
)
| token ->
Parser.err p (Diagnostics.unexpected token p.breadcrumbs);
Longident.Lident "_"
Expand All @@ -730,7 +740,7 @@ let parseValuePathTail p startPos ident =
loop p (Longident.Ldot (path, ident))
| token ->
Parser.err p (Diagnostics.unexpected token p.breadcrumbs);
Location.mknoloc path
Location.mkloc (Longident.Ldot (path, "_")) (mkLoc startPos p.prevEndPos)
in
loop p ident

Expand All @@ -753,7 +763,7 @@ let parseModuleLongIdentTail ~lowercase p startPos ident =
end
| t ->
Parser.err p (Diagnostics.uident t);
Location.mkloc acc (mkLoc startPos p.prevEndPos)
Location.mkloc (Longident.Ldot (acc, "_")) (mkLoc startPos p.prevEndPos)
in
loop p ident

Expand Down Expand Up @@ -3582,8 +3592,10 @@ and parseValueOrConstructor p =
Ast_helper.Exp.ident ~loc (Location.mkloc lident loc)
| token ->
Parser.next p;
let loc = mkLoc startPos p.prevEndPos in
Parser.err p (Diagnostics.unexpected token p.breadcrumbs);
Recover.defaultExpr()
let lident = buildLongident ("_"::acc) in
Ast_helper.Exp.ident ~loc (Location.mkloc lident loc)
in
aux p []

Expand Down