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/analyzer.ml | 5 ++--- lib/analyzer.mli | 2 +- lib/lexbuf.ml | 11 ++++++++--- lib/lexbuf.mli | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/analyzer.ml b/lib/analyzer.ml index 547b3da..7a64cab 100644 --- a/lib/analyzer.ml +++ b/lib/analyzer.ml @@ -5,14 +5,13 @@ *) let parse : (module Qsp_syntax.S.Analyzer with type Location.repr = 'a) -> - Sedlexing.lexbuf -> + Lexbuf.t -> ('a, Qsp_syntax.Report.t) Result.t = fun (type a) (module S : Qsp_syntax.S.Analyzer with type Location.repr = a) -> let module Parser = Parser.Make (S) in let module IncrementalParser = Interpreter.Interpreter (Parser.MenhirInterpreter) in - fun lexbuf -> - let l = Lexbuf.from_lexbuf lexbuf in + fun l -> let lexer = Lexbuf.tokenize Lexer.token l in let init = Parser.Incremental.main (fst (Lexbuf.positions l)) in diff --git a/lib/analyzer.mli b/lib/analyzer.mli index d79ea76..30b6625 100644 --- a/lib/analyzer.mli +++ b/lib/analyzer.mli @@ -1,6 +1,6 @@ val parse : (module Qsp_syntax.S.Analyzer with type Location.repr = 'a) -> - Sedlexing.lexbuf -> + Lexbuf.t -> ('a, Qsp_syntax.Report.t) Result.t (** Read the source and build a analyzis over it. 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 diff --git a/lib/lexbuf.mli b/lib/lexbuf.mli index 918c011..41f07d1 100644 --- a/lib/lexbuf.mli +++ b/lib/lexbuf.mli @@ -1,6 +1,6 @@ type t -val from_lexbuf : Sedlexing.lexbuf -> t +val from_lexbuf : ?reset_line:bool -> Sedlexing.lexbuf -> t (** Create a new buffer *) val start : t -> unit -- cgit v1.2.3