diff options
| author | Pierre-Marie Pédrot | 2018-11-04 19:00:35 +0100 |
|---|---|---|
| committer | Pierre-Marie Pédrot | 2018-11-05 19:02:31 +0100 |
| commit | 9f17f5aad33d320e96d7cc4fa370b39e7d772697 (patch) | |
| tree | da2319eb528ac7a1d936591c56e959b6c8fd73ac /gramlib | |
| parent | d382b815fd5ec0ee81f01aec6a72b1f7adf8b907 (diff) | |
Remove patches of dead code in Gramlib.
Diffstat (limited to 'gramlib')
| -rw-r--r-- | gramlib/ploc.ml | 109 | ||||
| -rw-r--r-- | gramlib/ploc.mli | 29 |
2 files changed, 0 insertions, 138 deletions
diff --git a/gramlib/ploc.ml b/gramlib/ploc.ml index 6aa7c1a2bb..082686db01 100644 --- a/gramlib/ploc.ml +++ b/gramlib/ploc.ml @@ -55,115 +55,6 @@ let sub loc sh len = {loc with bp = loc.bp + sh; ep = loc.bp + sh + len} let after loc sh len = {loc with bp = loc.ep + sh; ep = loc.ep + sh + len} let with_comment loc comm = {loc with comm = comm} -let name = ref "loc" - -let from_file fname loc = - let (bp, ep) = first_pos loc, last_pos loc in - try - let ic = open_in_bin fname in - let strm = Stream.of_channel ic in - let rec loop fname lin = - let rec not_a_line_dir col (strm__ : _ Stream.t) = - let cnt = Stream.count strm__ in - match Stream.peek strm__ with - Some c -> - Stream.junk strm__; - let s = strm__ in - if cnt < bp then - if c = '\n' then loop fname (lin + 1) - else not_a_line_dir (col + 1) s - else let col = col - (cnt - bp) in fname, lin, col, col + ep - bp - | _ -> fname, lin, col, col + 1 - in - let rec a_line_dir str n col (strm__ : _ Stream.t) = - match Stream.peek strm__ with - Some '\n' -> Stream.junk strm__; loop str n - | Some _ -> Stream.junk strm__; a_line_dir str n (col + 1) strm__ - | _ -> raise Stream.Failure - in - let rec spaces col (strm__ : _ Stream.t) = - match Stream.peek strm__ with - Some ' ' -> Stream.junk strm__; spaces (col + 1) strm__ - | _ -> col - in - let rec check_string str n col (strm__ : _ Stream.t) = - match Stream.peek strm__ with - Some '"' -> - Stream.junk strm__; - let col = - try spaces (col + 1) strm__ with - Stream.Failure -> raise (Stream.Error "") - in - a_line_dir str n col strm__ - | Some c when c <> '\n' -> - Stream.junk strm__; - check_string (str ^ String.make 1 c) n (col + 1) strm__ - | _ -> not_a_line_dir col strm__ - in - let check_quote n col (strm__ : _ Stream.t) = - match Stream.peek strm__ with - Some '"' -> Stream.junk strm__; check_string "" n (col + 1) strm__ - | _ -> not_a_line_dir col strm__ - in - let rec check_num n col (strm__ : _ Stream.t) = - match Stream.peek strm__ with - Some ('0'..'9' as c) -> - Stream.junk strm__; - check_num (10 * n + Char.code c - Char.code '0') (col + 1) strm__ - | _ -> let col = spaces col strm__ in check_quote n col strm__ - in - let begin_line (strm__ : _ Stream.t) = - match Stream.peek strm__ with - Some '#' -> - Stream.junk strm__; - let col = - try spaces 1 strm__ with - Stream.Failure -> raise (Stream.Error "") - in - check_num 0 col strm__ - | _ -> not_a_line_dir 0 strm__ - in - begin_line strm - in - let r = - try loop fname 1 with - Stream.Failure -> - let bol = bol_pos loc in fname, line_nb loc, bp - bol, ep - bol - in - close_in ic; r - with Sys_error _ -> fname, 1, bp, ep - -let second_line fname ep0 (line, bp) ep = - let ic = open_in fname in - seek_in ic bp; - let rec loop line bol p = - if p = ep then - begin close_in ic; if bol = bp then line, ep0 else line, ep - bol end - else - let (line, bol) = - match input_char ic with - '\n' -> line + 1, p + 1 - | _ -> line, bol - in - loop line bol (p + 1) - in - loop line bp bp - -let get loc = - if loc.fname = "" || loc.fname = "-" then - loc.line_nb, loc.bp - loc.bol_pos, loc.line_nb, loc.ep - loc.bol_pos, - loc.ep - loc.bp - else - let (bl, bc, ec) = - loc.line_nb, loc.bp - loc.bol_pos, loc.ep - loc.bol_pos - in - let (el, eep) = second_line loc.fname ec (bl, loc.bp) loc.ep in - bl, bc, el, eep, ec - bc - -let call_with r v f a = - let saved = !r in - try r := v; let b = f a in r := saved; b with e -> r := saved; raise e - exception Exc of t * exn let raise loc exc = diff --git a/gramlib/ploc.mli b/gramlib/ploc.mli index afddefcd6e..2ce6382183 100644 --- a/gramlib/ploc.mli +++ b/gramlib/ploc.mli @@ -84,32 +84,3 @@ val after : t -> int -> int -> t [len]. *) val with_comment : t -> string -> t (** Change the comment part of the given location *) - -(* miscellaneous *) - -val name : string ref - (** [Ploc.name.val] is the name of the location variable used in grammars - and in the predefined quotations for OCaml syntax trees. Default: - ["loc"] *) - -val get : t -> int * int * int * int * int - (** [Ploc.get loc] returns in order: 1/ the line number of the begin - of the location, 2/ its column, 3/ the line number of the first - character not in the location, 4/ its column and 5/ the length - of the location. The file where the location occurs (if any) may - be read during this operation. *) - -val from_file : string -> t -> string * int * int * int - (** [Ploc.from_file fname loc] reads the file [fname] up to the - location [loc] and returns the real input file, the line number - and the characters location in the line; the real input file - can be different from [fname] because of possibility of line - directives typically generated by /lib/cpp. *) - -(* pervasives *) - -val call_with : 'a ref -> 'a -> ('b -> 'c) -> 'b -> 'c - (** [Ploc.call_with r v f a] sets the reference [r] to the value [v], - then call [f a], and resets [r] to its initial value. If [f a] raises - an exception, its initial value is also reset and the exception is - re-raised. The result is the result of [f a]. *) |
