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

More robust parse recovery after ".". #491

Merged
merged 1 commit into from
May 13, 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
27 changes: 21 additions & 6 deletions src/res_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,16 @@ let parseValuePath p =
Parser.next p;
Location.mkloc ident (mkLoc startPos p.prevEndPos)

let parseValuePathAfterDot p =
let startPos = p.Parser.startPos in
match p.Parser.token with
| Lident _
| Uident _ ->
parseValuePath p
| token ->
Parser.err p (Diagnostics.unexpected token p.breadcrumbs);
Location.mkloc (Longident.Lident "_") (mkLoc startPos p.prevEndPos)

let parseValuePathTail p startPos ident =
let rec loop p path =
match p.Parser.token with
Expand Down Expand Up @@ -2052,7 +2062,7 @@ and parsePrimaryExpr ~operand ?(noCall=false) p =
match p.Parser.token with
| Dot ->
Parser.next p;
let lident = parseValuePath p in
let lident = parseValuePathAfterDot p in
begin match p.Parser.token with
| Equal when noCall = false ->
Parser.leaveBreadcrumb p Grammar.ExprSetField;
Expand Down Expand Up @@ -3591,11 +3601,16 @@ and parseValueOrConstructor p =
let lident = buildLongident (ident::acc) in
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);
let lident = buildLongident ("_"::acc) in
Ast_helper.Exp.ident ~loc (Location.mkloc lident loc)
if acc = [] then (
Parser.next p;
Parser.err p (Diagnostics.unexpected token p.breadcrumbs);
Recover.defaultExpr()
) else (
let loc = mkLoc startPos p.prevEndPos in
Parser.err p (Diagnostics.unexpected token p.breadcrumbs);
let lident = buildLongident ("_"::acc) in
Ast_helper.Exp.ident ~loc (Location.mkloc lident loc)
)
in
aux p []

Expand Down