diff options
Diffstat (limited to 'lib/lexbuf.ml')
-rw-r--r-- | lib/lexbuf.ml | 11 |
1 files changed, 8 insertions, 3 deletions
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 |