From 7ff1e525b39a42f94e32c65f8c2aac0a52465dc3 Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Sat, 7 Oct 2023 15:05:25 +0200 Subject: Added the error message in case of unclosed quote in a text --- lib/qparser/analyzer.ml | 56 ++++++++++++++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 22 deletions(-) (limited to 'lib/qparser/analyzer.ml') diff --git a/lib/qparser/analyzer.ml b/lib/qparser/analyzer.ml index da1adbf..c165d03 100644 --- a/lib/qparser/analyzer.ml +++ b/lib/qparser/analyzer.ml @@ -16,27 +16,39 @@ let parse : let init = Parser.Incremental.main (fst (Lexbuf.positions l)) in - IncrementalParser.of_lexbuf lexer l init - |> Result.map_error (fun e -> - let message = - match e.IncrementalParser.code with - | Interpreter.InvalidSyntax -> "Invalid Syntax" - | Interpreter.UnrecoverableError -> "UnrecoverableError" - | Interpreter.MenhirCode c -> - let message_content = - try Parser_messages.message c - with Not_found -> - String.concat "" [ "(Error code "; string_of_int c; ")" ] - in + let evaluation = + try IncrementalParser.of_lexbuf lexer l init + with Lexer.UnclosedQuote -> + let start_pos, end_pos = Lexbuf.positions l in + let err = + IncrementalParser. + { code = Interpreter.Custom "Unclosed text"; start_pos; end_pos } + in + Error err + in - String.concat "" [ String.trim @@ message_content ] - in - let report = - Qsp_syntax.Report.error (e.start_pos, e.end_pos) message - in + Result.map_error + (fun e -> + let message = + match e.IncrementalParser.code with + | Interpreter.InvalidSyntax -> "Invalid Syntax" + | Interpreter.UnrecoverableError -> "UnrecoverableError" + | Interpreter.Custom msg -> msg + | Interpreter.MenhirCode c -> + let message_content = + try Parser_messages.message c + with Not_found -> + String.concat "" [ "(Error code "; string_of_int c; ")" ] + in - (* Discard the remaining file to read. The parser is now in a blank - state, it does not make sense to keep feeding it with the new - tokens. *) - Lexer.discard l; - report) + String.concat "" [ String.trim @@ message_content ] + in + let report = Qsp_syntax.Report.error (e.start_pos, e.end_pos) message in + + (* Discard the remaining file to read. The parser is now in a blank + state, it does not make sense to keep feeding it with the new + tokens. *) + let () = try Lexer.discard l with _ -> () in + + report) + evaluation -- cgit v1.2.3