From 89308bcf4eac2b4bd0cc91a67499ddb918a9a56b Mon Sep 17 00:00:00 2001 From: Galfour Date: Wed, 8 May 2019 13:46:16 +0000 Subject: [PATCH] add better error message when parsing expressions --- src/ligo/parser/parser.ml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ligo/parser/parser.ml b/src/ligo/parser/parser.ml index f3057c843..854029d33 100644 --- a/src/ligo/parser/parser.ml +++ b/src/ligo/parser/parser.ml @@ -96,7 +96,18 @@ let parse_expression (s:string) : AST_Raw.expr result = end_.pos_lnum (end_.pos_cnum - end_.pos_bol) in simple_error str ) - | _ -> simple_error "unrecognized parse_ error" + | exn -> + let start = Lexing.lexeme_start_p lexbuf in + let end_ = Lexing.lexeme_end_p lexbuf in + let str = Format.sprintf + "Unrecognized error (%s) at \"%s\" from (%d, %d) to (%d, %d). In expression \"%s|%s\"\n" + (Printexc.to_string exn) + (Lexing.lexeme lexbuf) + start.pos_lnum (start.pos_cnum - start.pos_bol) + end_.pos_lnum (end_.pos_cnum - end_.pos_bol) + start.pos_fname s + in + simple_error str ) @@ (fun () -> let raw = Parser.interactive_expr read lexbuf in close () ;