From 7eba2dfda86238cb0941edfd7aafb09f566c36d8 Mon Sep 17 00:00:00 2001 From: Enrico Tassi Date: Mon, 25 Mar 2019 17:31:55 +0100 Subject: [parser] initialization based on Loc.t rather than Loc.source In this way one can also set the current offsets in a file, useful if you are parsing a Coq fragment within a file instead of a full file starting from the first line. --- gramlib/grammar.ml | 6 +++--- gramlib/grammar.mli | 2 +- gramlib/plexing.ml | 2 +- gramlib/plexing.mli | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'gramlib') diff --git a/gramlib/grammar.ml b/gramlib/grammar.ml index f46ddffd6e..74350c4f15 100644 --- a/gramlib/grammar.ml +++ b/gramlib/grammar.ml @@ -15,7 +15,7 @@ module type S = sig type te type parsable - val parsable : char Stream.t -> parsable + val parsable : ?loc:Loc.t -> char Stream.t -> parsable val tokens : string -> (string * int) list module Entry : sig @@ -1398,8 +1398,8 @@ let clear_entry e = Dlevels _ -> e.edesc <- Dlevels [] | Dparser _ -> () - let parsable cs = - let (ts, lf) = L.lexer.Plexing.tok_func cs in + let parsable ?loc cs = + let (ts, lf) = L.lexer.Plexing.tok_func ?loc cs in {pa_chr_strm = cs; pa_tok_strm = ts; pa_loc_func = lf} module Entry = struct diff --git a/gramlib/grammar.mli b/gramlib/grammar.mli index bde07ddc48..7cb7a92f85 100644 --- a/gramlib/grammar.mli +++ b/gramlib/grammar.mli @@ -23,7 +23,7 @@ module type S = sig type te type parsable - val parsable : char Stream.t -> parsable + val parsable : ?loc:Loc.t -> char Stream.t -> parsable val tokens : string -> (string * int) list module Entry : sig diff --git a/gramlib/plexing.ml b/gramlib/plexing.ml index fce5445ad8..c294923a85 100644 --- a/gramlib/plexing.ml +++ b/gramlib/plexing.ml @@ -5,7 +5,7 @@ type pattern = string * string type location_function = int -> Loc.t -type 'te lexer_func = char Stream.t -> 'te Stream.t * location_function +type 'te lexer_func = ?loc:Loc.t -> char Stream.t -> 'te Stream.t * location_function type 'te lexer = { tok_func : 'te lexer_func; diff --git a/gramlib/plexing.mli b/gramlib/plexing.mli index 6139dc4020..f6e4d96b80 100644 --- a/gramlib/plexing.mli +++ b/gramlib/plexing.mli @@ -28,7 +28,7 @@ type 'te lexer = tok_match : pattern -> 'te -> string; tok_text : pattern -> string; } -and 'te lexer_func = char Stream.t -> 'te Stream.t * location_function +and 'te lexer_func = ?loc:Loc.t -> char Stream.t -> 'te Stream.t * location_function and location_function = int -> Loc.t (** The type of a function giving the location of a token in the source from the token number in the stream (starting from zero). *) -- cgit v1.2.3