diff options
author | Chimrod <> | 2023-09-29 19:06:41 +0200 |
---|---|---|
committer | Chimrod <> | 2023-09-29 19:10:04 +0200 |
commit | 2e41a214e4c2a2984ad3b2afa3d80178d227927f (patch) | |
tree | 5c02005d6bec087a455f840f766de482fb6cf66d /lib | |
parent | 7f93c2a6b351c02e506d521ea7363f813618e430 (diff) |
Added a global line counter (off by default)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/analyzer.ml | 5 | ||||
-rw-r--r-- | lib/analyzer.mli | 2 | ||||
-rw-r--r-- | lib/lexbuf.ml | 11 | ||||
-rw-r--r-- | lib/lexbuf.mli | 2 |
4 files changed, 12 insertions, 8 deletions
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 |