Changed signature of [Lexer.S] so the implementation of [print_error]
does not depend on [EvalOpt].
This commit is contained in:
parent
4d61ac0a13
commit
fd5bee397b
@ -132,7 +132,7 @@ module type S =
|
||||
exception Error of Error.t Region.reg
|
||||
|
||||
val print_error : ?offsets:bool -> [`Byte | `Point] ->
|
||||
Error.t Region.reg -> unit
|
||||
Error.t Region.reg -> file:bool -> unit
|
||||
|
||||
end
|
||||
|
||||
|
@ -154,7 +154,7 @@ module type S = sig
|
||||
exception Error of Error.t Region.reg
|
||||
|
||||
val print_error : ?offsets:bool -> [`Byte | `Point] ->
|
||||
Error.t Region.reg -> unit
|
||||
Error.t Region.reg -> file:bool -> unit
|
||||
end
|
||||
|
||||
(* The functorised interface
|
||||
@ -382,11 +382,8 @@ module Make (Token: TOKEN) : (S with module Token = Token) =
|
||||
|
||||
exception Error of Error.t Region.reg
|
||||
|
||||
let print_error ?(offsets=true) mode Region.{region; value} =
|
||||
let print_error ?(offsets=true) mode Region.{region; value} ~file =
|
||||
let msg = error_to_string value in
|
||||
let file = match EvalOpt.input with
|
||||
None | Some "-" -> false
|
||||
| Some _ -> true in
|
||||
let reg = region#to_string ~file ~offsets mode in
|
||||
Utils.highlight (sprintf "Lexical error %s:\n%s%!" reg msg)
|
||||
|
||||
|
@ -2,6 +2,11 @@
|
||||
|
||||
let sprintf = Printf.sprintf
|
||||
|
||||
let file =
|
||||
match EvalOpt.input with
|
||||
None | Some "-" -> false
|
||||
| Some _ -> true
|
||||
|
||||
module type S =
|
||||
sig
|
||||
module Lexer : Lexer.S
|
||||
@ -62,7 +67,8 @@ module Make (Lexer: Lexer.S) : (S with module Lexer = Lexer) =
|
||||
if Token.is_eof token then close_all ()
|
||||
else iter ()
|
||||
| exception Lexer.Error e ->
|
||||
Lexer.print_error ~offsets mode e; close_all ()
|
||||
Lexer.print_error ~offsets mode e ~file;
|
||||
close_all ()
|
||||
in iter ()
|
||||
with Sys_error msg -> Utils.highlight (sprintf "%s\n" msg)
|
||||
|
||||
|
@ -115,7 +115,7 @@ sepseq(X,Sep):
|
||||
%inline type_name : Ident { $1 }
|
||||
%inline fun_name : Ident { $1 }
|
||||
%inline field_name : Ident { $1 }
|
||||
%inline record_name : Ident { $1 }
|
||||
%inline struct_name : Ident { $1 }
|
||||
|
||||
(* Main *)
|
||||
|
||||
@ -998,11 +998,11 @@ record_expr:
|
||||
record_injection { RecordInj $1 }
|
||||
|
||||
projection:
|
||||
record_name DOT nsepseq(selection,DOT) {
|
||||
struct_name DOT nsepseq(selection,DOT) {
|
||||
let stop = nsepseq_to_region selection_to_region $3 in
|
||||
let region = cover $1.region stop
|
||||
and value = {
|
||||
record_name = $1;
|
||||
struct_name = $1;
|
||||
selector = $2;
|
||||
field_path = $3}
|
||||
in {region; value}}
|
||||
|
@ -4,6 +4,11 @@ open! EvalOpt (* Reads the command-line options: Effectful! *)
|
||||
|
||||
let sprintf = Printf.sprintf
|
||||
|
||||
let file =
|
||||
match EvalOpt.input with
|
||||
None | Some "-" -> false
|
||||
| Some _ -> true
|
||||
|
||||
(* Error printing and exception tracing *)
|
||||
|
||||
let () = Printexc.record_backtrace true
|
||||
@ -17,11 +22,8 @@ let error_to_string = function
|
||||
ParseError -> "Syntax error.\n"
|
||||
| _ -> assert false
|
||||
|
||||
let print_error ?(offsets=true) mode Region.{region; value} =
|
||||
let print_error ?(offsets=true) mode Region.{region; value} ~file =
|
||||
let msg = error_to_string value in
|
||||
let file = match EvalOpt.input with
|
||||
None | Some "-" -> false
|
||||
| Some _ -> true in
|
||||
let reg = region#to_string ~file ~offsets mode in
|
||||
Utils.highlight (sprintf "Parse error %s:\n%s%!" reg msg)
|
||||
|
||||
@ -93,10 +95,10 @@ let () =
|
||||
with
|
||||
Lexer.Error err ->
|
||||
close_all ();
|
||||
Lexer.print_error ~offsets EvalOpt.mode err
|
||||
Lexer.print_error ~offsets EvalOpt.mode err ~file
|
||||
| Parser.Error ->
|
||||
let region = get_last () in
|
||||
let error = Region.{region; value=ParseError} in
|
||||
let () = close_all () in
|
||||
print_error ~offsets EvalOpt.mode error
|
||||
print_error ~offsets EvalOpt.mode error ~file
|
||||
| Sys_error msg -> Utils.highlight msg
|
||||
|
Loading…
Reference in New Issue
Block a user