2020-03-24 20:47:24 +04:00
|
|
|
module Region = Simple_utils.Region
|
|
|
|
|
2020-03-25 21:52:23 +04:00
|
|
|
let highlight msg = Printf.eprintf "\027[31m%s\027[0m\n%!" msg
|
2020-03-25 00:05:39 +04:00
|
|
|
|
2020-03-24 20:47:24 +04:00
|
|
|
let options = EvalOpt.read ();;
|
|
|
|
|
|
|
|
match open_in options#input with
|
2020-03-25 00:05:39 +04:00
|
|
|
exception Sys_error msg -> highlight msg
|
2020-03-24 20:47:24 +04:00
|
|
|
| cin ->
|
|
|
|
let buffer = Lexing.from_channel cin in
|
|
|
|
let open Lexing in
|
|
|
|
let () =
|
|
|
|
buffer.lex_curr_p <-
|
|
|
|
{buffer.lex_curr_p with pos_fname = options#input} in
|
2020-03-25 21:52:23 +04:00
|
|
|
match Preproc.lex options buffer with
|
2020-03-24 20:47:24 +04:00
|
|
|
pp -> print_string (Buffer.contents pp)
|
|
|
|
| exception E_Lexer.Error err ->
|
|
|
|
let formatted =
|
2020-03-25 00:05:39 +04:00
|
|
|
E_Lexer.format ~offsets:options#offsets ~file:true err
|
|
|
|
in highlight formatted.Region.value
|
2020-03-25 21:52:23 +04:00
|
|
|
| exception Preproc.Error (_out, err) ->
|
2020-03-24 20:47:24 +04:00
|
|
|
let formatted =
|
2020-03-25 00:05:39 +04:00
|
|
|
Preproc.format ~offsets:options#offsets ~file:true err in
|
2020-03-24 20:47:24 +04:00
|
|
|
begin
|
2020-03-25 21:52:23 +04:00
|
|
|
(* print_string (Buffer.contents out);*)
|
2020-03-25 00:05:39 +04:00
|
|
|
highlight formatted.Region.value
|
2020-03-24 20:47:24 +04:00
|
|
|
end
|