Skip to content

Error recovery when handling bad inputs #3

@cpitclaudel

Description

@cpitclaudel

Hi there,

Thanks for this cool library. I'm using it to parse programs written in a lisp-like language (the stack goes like this: read sexps → parse into an AST → resolve names → typecheck).

I've added error recovery mechanisms to all phases except the first one. This way I can report multiple input errors instead of stopping at the first one, but only as long as the input is well-parenthesized.

Now I'd like to make the sexp-reading phase a bit more robust. I've already changed to an eager parser, which gives me a nice way to parse, resolve, and typecheck all top-level sexps until the first parse error. I'd like to do more, by handling the following cases:

  • Dropping extra, unexpected closing parentheses: a ) b should parse like a b (and report an error, of course).
  • Adding extra closing parentheses to unfinished terms: ((a b should parse like ((a b))
  • Closing unterminated strings when the end of the line is reached:
    (a "xyz
     b)
    
    should parse as (a "xyz" b)

I've got the first one to work by skipping characters every time I get a parse error, but number 2 and 3 seem tricky to do without access to the contents of the parser's stack. A I going about this the right way? Is there an easier approach that I missed?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    forwarded-to-js-devsThis report has been forwarded to Jane Street's internal review system.not-clear-what-next-step-isThis report is kept open as a reminder, but it is not clear what should happen next.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions