aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorChimrod <>2023-10-14 15:00:49 +0200
committerChimrod <>2023-10-15 19:04:21 +0200
commit617d2ee554ccf502c718391aa05b7b72668b83e7 (patch)
tree3d376be8b5e8d111412602773688e9df81f6143d /lib
parent7ff1e525b39a42f94e32c65f8c2aac0a52465dc3 (diff)
Added a new error case
Diffstat (limited to 'lib')
-rw-r--r--lib/qparser/analyzer.ml23
-rw-r--r--lib/qparser/lexer.ml13
-rw-r--r--lib/qparser/lexer.mli1
3 files changed, 19 insertions, 18 deletions
diff --git a/lib/qparser/analyzer.ml b/lib/qparser/analyzer.ml
index c165d03..fba96e0 100644
--- a/lib/qparser/analyzer.ml
+++ b/lib/qparser/analyzer.ml
@@ -17,14 +17,21 @@ let parse :
let init = Parser.Incremental.main (fst (Lexbuf.positions l)) 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
+ try IncrementalParser.of_lexbuf lexer l init with
+ | Lexer.LexError message ->
+ let start_pos, end_pos = Lexbuf.positions l in
+ let err =
+ IncrementalParser.
+ { code = Interpreter.Custom message; start_pos; end_pos }
+ in
+ Error err
+ | 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
Result.map_error
diff --git a/lib/qparser/lexer.ml b/lib/qparser/lexer.ml
index 3e1c05b..fe2b487 100644
--- a/lib/qparser/lexer.ml
+++ b/lib/qparser/lexer.ml
@@ -5,12 +5,9 @@
open Tokens
exception UnclosedQuote
-exception LexError of Lexing.position * string
+exception LexError of string
exception EOF
-let pp_pos out { Lexing.pos_lnum; pos_cnum; pos_bol; _ } =
- Format.fprintf out "line %d:%d" pos_lnum (pos_cnum - pos_bol)
-
(* Extract the location name from the pattern *)
let location_name = Str.regexp {|.* \(.*\)|}
@@ -177,14 +174,10 @@ let rec token : Lexbuf.t -> token =
| '{' -> LITERAL (wait_balance (read_long_string 0) buffer)
| eof -> raise EOF
| _ ->
- let position = fst @@ Sedlexing.lexing_positions lexbuf in
let tok = Lexbuf.content buffer in
+ let msg = Format.asprintf "Unexpected character %S" tok in
- let msg =
- Format.asprintf "Unexpected character %S at %a" tok pp_pos position
- in
-
- raise @@ LexError (position, msg)
+ raise @@ LexError msg
let rec discard buffer =
let lexbuf = Lexbuf.buffer buffer in
diff --git a/lib/qparser/lexer.mli b/lib/qparser/lexer.mli
index 41ecb16..30766e0 100644
--- a/lib/qparser/lexer.mli
+++ b/lib/qparser/lexer.mli
@@ -1,5 +1,6 @@
exception EOF
exception UnclosedQuote
+exception LexError of string
val token : Lexbuf.t -> Tokens.token
val discard : Lexbuf.t -> unit