Move make_loc to Loc module and rename it to of_lexbuf
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
This commit is contained in:
parent
51c9b207b1
commit
67edb7f89e
|
@ -16,3 +16,8 @@ let in_file fn =
|
||||||
}
|
}
|
||||||
|
|
||||||
let none = in_file "<none>"
|
let none = in_file "<none>"
|
||||||
|
|
||||||
|
let of_lexbuf lexbuf : t =
|
||||||
|
{ start = Lexing.lexeme_start_p lexbuf
|
||||||
|
; stop = Lexing.lexeme_end_p lexbuf
|
||||||
|
}
|
||||||
|
|
|
@ -6,3 +6,5 @@ type t =
|
||||||
val in_file : string -> t
|
val in_file : string -> t
|
||||||
|
|
||||||
val none : t
|
val none : t
|
||||||
|
|
||||||
|
val of_lexbuf : Lexing.lexbuf -> t
|
||||||
|
|
|
@ -166,11 +166,6 @@ module Parser = struct
|
||||||
; message
|
; message
|
||||||
})
|
})
|
||||||
|
|
||||||
let make_loc lexbuf : Loc.t =
|
|
||||||
{ start = Lexing.lexeme_start_p lexbuf
|
|
||||||
; stop = Lexing.lexeme_end_p lexbuf
|
|
||||||
}
|
|
||||||
|
|
||||||
module Mode = struct
|
module Mode = struct
|
||||||
type 'a t =
|
type 'a t =
|
||||||
| Single : Ast.t t
|
| Single : Ast.t t
|
||||||
|
@ -183,7 +178,7 @@ module Parser = struct
|
||||||
| Single -> begin
|
| Single -> begin
|
||||||
match sexps with
|
match sexps with
|
||||||
| [sexp] -> sexp
|
| [sexp] -> sexp
|
||||||
| [] -> error (make_loc lexbuf) "no s-expression found in input"
|
| [] -> error (Loc.of_lexbuf lexbuf) "no s-expression found in input"
|
||||||
| _ :: sexp :: _ ->
|
| _ :: sexp :: _ ->
|
||||||
error (Ast.loc sexp) "too many s-expressions found in input"
|
error (Ast.loc sexp) "too many s-expressions found in input"
|
||||||
end
|
end
|
||||||
|
@ -200,13 +195,13 @@ module Parser = struct
|
||||||
let rec loop depth lexer lexbuf acc =
|
let rec loop depth lexer lexbuf acc =
|
||||||
match (lexer lexbuf : Lexer.Token.t) with
|
match (lexer lexbuf : Lexer.Token.t) with
|
||||||
| Atom a ->
|
| Atom a ->
|
||||||
let loc = make_loc lexbuf in
|
let loc = Loc.of_lexbuf lexbuf in
|
||||||
loop depth lexer lexbuf (Ast.Atom (loc, a) :: acc)
|
loop depth lexer lexbuf (Ast.Atom (loc, a) :: acc)
|
||||||
| Quoted_string s ->
|
| 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)
|
loop depth lexer lexbuf (Quoted_string (loc, s) :: acc)
|
||||||
| Template t ->
|
| Template t ->
|
||||||
let loc = make_loc lexbuf in
|
let loc = Loc.of_lexbuf lexbuf in
|
||||||
loop depth lexer lexbuf (Template { t with loc } :: acc)
|
loop depth lexer lexbuf (Template { t with loc } :: acc)
|
||||||
| Lparen ->
|
| Lparen ->
|
||||||
let start = Lexing.lexeme_start_p lexbuf in
|
let start = Lexing.lexeme_start_p lexbuf in
|
||||||
|
@ -215,12 +210,12 @@ module Parser = struct
|
||||||
loop depth lexer lexbuf (List ({ start; stop }, sexps) :: acc)
|
loop depth lexer lexbuf (List ({ start; stop }, sexps) :: acc)
|
||||||
| Rparen ->
|
| Rparen ->
|
||||||
if depth = 0 then
|
if depth = 0 then
|
||||||
error (make_loc lexbuf)
|
error (Loc.of_lexbuf lexbuf)
|
||||||
"right parenthesis without matching left parenthesis";
|
"right parenthesis without matching left parenthesis";
|
||||||
List.rev acc
|
List.rev acc
|
||||||
| Sexp_comment ->
|
| Sexp_comment ->
|
||||||
let sexps =
|
let sexps =
|
||||||
let loc = make_loc lexbuf in
|
let loc = Loc.of_lexbuf lexbuf in
|
||||||
match loop depth lexer lexbuf [] with
|
match loop depth lexer lexbuf [] with
|
||||||
| _ :: sexps -> sexps
|
| _ :: sexps -> sexps
|
||||||
| [] -> error loc "s-expression missing after #;"
|
| [] -> error loc "s-expression missing after #;"
|
||||||
|
@ -228,7 +223,7 @@ module Parser = struct
|
||||||
List.rev_append acc sexps
|
List.rev_append acc sexps
|
||||||
| Eof ->
|
| Eof ->
|
||||||
if depth > 0 then
|
if depth > 0 then
|
||||||
error (make_loc lexbuf)
|
error (Loc.of_lexbuf lexbuf)
|
||||||
"unclosed parenthesis at end of input";
|
"unclosed parenthesis at end of input";
|
||||||
List.rev acc
|
List.rev acc
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue