Handling exceptions with FParsec

118 Views Asked by At

I would like to be able to parse a file without the program launching an exception and stop the program at the first error. I use this:

let parse input = match run pprog input with
                  | Success(result, _, _) -> result
                  | Failure(msg, _, _) -> failwith msg

let program = parse myFile

The program variable is of the type AST.program (no need to show the implementation), thanks to the matching pattern of the parse function. If I do only this:

let program = run pprog myFile

program is of the type ParserResult<AST.Program, unit>, which is therefore unanalyzable.

I was wondering if there was a way not to crash the program with the exceptions launched?

0

There are 0 best solutions below