aboutsummaryrefslogtreecommitdiff
path: root/lib/qparser/lexbuf.ml
diff options
context:
space:
mode:
authorChimrod <>2023-10-07 15:05:25 +0200
committerChimrod <>2023-10-07 15:05:25 +0200
commit7ff1e525b39a42f94e32c65f8c2aac0a52465dc3 (patch)
tree45e3557a12fe868ddd3dc96488129244ef807ec9 /lib/qparser/lexbuf.ml
parent97ab5c9a21166f0bffee482210d69877fd6809fa (diff)
Added the error message in case of unclosed quote in a text
Diffstat (limited to 'lib/qparser/lexbuf.ml')
-rw-r--r--lib/qparser/lexbuf.ml13
1 files changed, 11 insertions, 2 deletions
diff --git a/lib/qparser/lexbuf.ml b/lib/qparser/lexbuf.ml
index 3f0b186..8a3e41c 100644
--- a/lib/qparser/lexbuf.ml
+++ b/lib/qparser/lexbuf.ml
@@ -18,7 +18,10 @@ let start : t -> unit =
t.expression_level <- 0
let positions : t -> Lexing.position * Lexing.position =
- fun t -> Sedlexing.lexing_positions t.buffer
+ fun t ->
+ let default, end_p = Sedlexing.lexing_positions t.buffer in
+ let start_p = Option.value ~default t.start_p in
+ (start_p, end_p)
let content : t -> string = fun t -> Sedlexing.Utf8.lexeme t.buffer
@@ -27,7 +30,12 @@ let from_lexbuf : ?reset_line:bool -> Sedlexing.lexbuf -> t =
{ buffer = t; start_p = None; expression_level = 0; reset_line }
let set_start_position : t -> Lexing.position -> unit =
- fun t position -> t.start_p <- Some position
+ fun t position ->
+ match t.start_p with
+ | None -> t.start_p <- Some position
+ | _ ->
+ (* We are already inside a block code, don’t stack it *)
+ ()
let tokenize : (t -> 'a) -> t -> unit -> 'a * Lexing.position * Lexing.position
=
@@ -39,6 +47,7 @@ let tokenize : (t -> 'a) -> t -> unit -> 'a * Lexing.position * Lexing.position
let default, curr_p = positions t in
let start_p = Option.value ~default t.start_p in
+ t.start_p <- None;
(token, start_p, curr_p)
in