2020-03-24 20:47:24 +04:00
|
|
|
module Region = Simple_utils.Region
|
|
|
|
|
|
|
|
let highlight msg = Printf.eprintf "\027[31m%s\027[0m%!" msg
|
|
|
|
|
|
|
|
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
|
|
|
|
let () =
|
|
|
|
try
|
|
|
|
let tree = E_Parser.expr E_Lexer.scan buffer in
|
|
|
|
let value = Preproc.(eval Env.empty tree)
|
|
|
|
in Printf.printf "%s\n" (string_of_bool value)
|
|
|
|
with
|
|
|
|
E_Lexer.Error error ->
|
|
|
|
let formatted =
|
2020-03-25 00:05:39 +04:00
|
|
|
E_Lexer.format
|
2020-03-24 20:47:24 +04:00
|
|
|
~offsets:options#offsets ~file:true error
|
|
|
|
in highlight formatted.Region.value
|
|
|
|
| E_Parser.Error ->
|
|
|
|
let region = Preproc.mk_reg buffer
|
2020-03-25 00:05:39 +04:00
|
|
|
and value = Preproc.Parse_error in
|
2020-03-24 20:47:24 +04:00
|
|
|
let error = Region.{value; region} in
|
|
|
|
let formatted =
|
2020-03-25 00:05:39 +04:00
|
|
|
Preproc.format ~offsets:options#offsets
|
|
|
|
~file:true error
|
2020-03-24 20:47:24 +04:00
|
|
|
in highlight formatted.Region.value
|
|
|
|
in close_in cin
|