From 2e41a214e4c2a2984ad3b2afa3d80178d227927f Mon Sep 17 00:00:00 2001 From: Chimrod <> Date: Fri, 29 Sep 2023 19:06:41 +0200 Subject: Added a global line counter (off by default) --- lib/lexbuf.ml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'lib/lexbuf.ml') diff --git a/lib/lexbuf.ml b/lib/lexbuf.ml index 6059c8a..3f0b186 100644 --- a/lib/lexbuf.ml +++ b/lib/lexbuf.ml @@ -2,6 +2,7 @@ type t = { buffer : Sedlexing.lexbuf; mutable start_p : Lexing.position option; mutable expression_level : int; + reset_line : bool; } let buffer : t -> Sedlexing.lexbuf = fun t -> t.buffer @@ -9,7 +10,10 @@ let buffer : t -> Sedlexing.lexbuf = fun t -> t.buffer let start : t -> unit = fun t -> let _start_pos, end_pos = Sedlexing.lexing_positions t.buffer in - Sedlexing.set_position t.buffer { end_pos with Lexing.pos_lnum = 1 }; + let () = + if not t.reset_line then + Sedlexing.set_position t.buffer { end_pos with Lexing.pos_lnum = 1 } + in t.start_p <- None; t.expression_level <- 0 @@ -18,8 +22,9 @@ let positions : t -> Lexing.position * Lexing.position = let content : t -> string = fun t -> Sedlexing.Utf8.lexeme t.buffer -let from_lexbuf : Sedlexing.lexbuf -> t = - fun t -> { buffer = t; start_p = None; expression_level = 0 } +let from_lexbuf : ?reset_line:bool -> Sedlexing.lexbuf -> t = + fun ?(reset_line = true) 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 -- cgit v1.2.3