diff options
author | Chimrod <> | 2023-10-07 15:05:25 +0200 |
---|---|---|
committer | Chimrod <> | 2023-10-07 15:05:25 +0200 |
commit | 7ff1e525b39a42f94e32c65f8c2aac0a52465dc3 (patch) | |
tree | 45e3557a12fe868ddd3dc96488129244ef807ec9 /lib/qparser/analyzer.ml | |
parent | 97ab5c9a21166f0bffee482210d69877fd6809fa (diff) |
Added the error message in case of unclosed quote in a text
Diffstat (limited to 'lib/qparser/analyzer.ml')
-rw-r--r-- | lib/qparser/analyzer.ml | 56 |
1 files changed, 34 insertions, 22 deletions
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 |