From 67edb7f89e0fd6d108649b32a2a3c8d2d186d97c Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Sun, 1 Jul 2018 15:19:54 +0700 Subject: [PATCH] Move make_loc to Loc module and rename it to of_lexbuf Signed-off-by: Rudi Grinberg --- src/usexp/loc.ml | 5 +++++ src/usexp/loc.mli | 2 ++ src/usexp/usexp.ml | 19 +++++++------------ 3 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/usexp/loc.ml b/src/usexp/loc.ml index d7ac4844..54c9aeac 100644 --- a/src/usexp/loc.ml +++ b/src/usexp/loc.ml @@ -16,3 +16,8 @@ let in_file fn = } let none = in_file "" + +let of_lexbuf lexbuf : t = + { start = Lexing.lexeme_start_p lexbuf + ; stop = Lexing.lexeme_end_p lexbuf + } diff --git a/src/usexp/loc.mli b/src/usexp/loc.mli index 514f3a68..2526948e 100644 --- a/src/usexp/loc.mli +++ b/src/usexp/loc.mli @@ -6,3 +6,5 @@ type t = val in_file : string -> t val none : t + +val of_lexbuf : Lexing.lexbuf -> t diff --git a/src/usexp/usexp.ml b/src/usexp/usexp.ml index 3681098a..b687686e 100644 --- a/src/usexp/usexp.ml +++ b/src/usexp/usexp.ml @@ -166,11 +166,6 @@ module Parser = struct ; message }) - let make_loc lexbuf : Loc.t = - { start = Lexing.lexeme_start_p lexbuf - ; stop = Lexing.lexeme_end_p lexbuf - } - module Mode = struct type 'a t = | Single : Ast.t t @@ -183,7 +178,7 @@ module Parser = struct | Single -> begin match sexps with | [sexp] -> sexp - | [] -> error (make_loc lexbuf) "no s-expression found in input" + | [] -> error (Loc.of_lexbuf lexbuf) "no s-expression found in input" | _ :: sexp :: _ -> error (Ast.loc sexp) "too many s-expressions found in input" end @@ -200,13 +195,13 @@ module Parser = struct let rec loop depth lexer lexbuf acc = match (lexer lexbuf : Lexer.Token.t) with | Atom a -> - let loc = make_loc lexbuf in + let loc = Loc.of_lexbuf lexbuf in loop depth lexer lexbuf (Ast.Atom (loc, a) :: acc) | Quoted_string s -> - let loc = make_loc lexbuf in + let loc = Loc.of_lexbuf lexbuf in loop depth lexer lexbuf (Quoted_string (loc, s) :: acc) | Template t -> - let loc = make_loc lexbuf in + let loc = Loc.of_lexbuf lexbuf in loop depth lexer lexbuf (Template { t with loc } :: acc) | Lparen -> let start = Lexing.lexeme_start_p lexbuf in @@ -215,12 +210,12 @@ module Parser = struct loop depth lexer lexbuf (List ({ start; stop }, sexps) :: acc) | Rparen -> if depth = 0 then - error (make_loc lexbuf) + error (Loc.of_lexbuf lexbuf) "right parenthesis without matching left parenthesis"; List.rev acc | Sexp_comment -> let sexps = - let loc = make_loc lexbuf in + let loc = Loc.of_lexbuf lexbuf in match loop depth lexer lexbuf [] with | _ :: sexps -> sexps | [] -> error loc "s-expression missing after #;" @@ -228,7 +223,7 @@ module Parser = struct List.rev_append acc sexps | Eof -> if depth > 0 then - error (make_loc lexbuf) + error (Loc.of_lexbuf lexbuf) "unclosed parenthesis at end of input"; List.rev acc