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