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

Making parser consistent with #542 #594

Closed
@Sehun0819

Description

@Sehun0819

Follow-up steps for #542 should be taken but I have no idea how to do.

  • Motivating example(I’m guessing there would be a few more, I’ve not checked though): 
#

Above simple code crashes the parser because parseIdent calls Parser.next with Eof, eventually violates an assertion of res_parser.ml added by #542. I thought it could be fixed easily by adding another pattern matching for Eof or substitute Parser.next with Parser.nextUnsafe(as far as it does not results another infinite loop), but neither pass the static analyzer. Any solution?

syntax/src/res_core.ml

Lines 564 to 586 in 08029af

let parseIdent ~msg ~startPos p =
match p.Parser.token with
| Lident ident | Uident ident ->
Parser.next p;
let loc = mkLoc startPos p.prevEndPos in
(ident, loc)
| token
when Token.isKeyword token && p.prevEndPos.pos_lnum == p.startPos.pos_lnum
->
let tokenTxt = Token.toString token in
let msg =
"`" ^ tokenTxt
^ "` is a reserved keyword. Keywords need to be escaped: \\\"" ^ tokenTxt
^ "\""
in
Parser.err ~startPos p (Diagnostics.message msg);
Parser.next p;
(tokenTxt, mkLoc startPos p.prevEndPos)
| _token ->
Parser.err ~startPos p (Diagnostics.message msg);
Parser.next p;
("", mkLoc startPos p.prevEndPos)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions