]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_disambiguation/test_parser.ml
- enriched Parse_error exception with error location
[helm.git] / helm / ocaml / cic_disambiguation / test_parser.ml
index 4ee8ec6ef1340c757cc2639bd44a9dac10ce9c2c..51a0d911f23ada0464480b5af8749ca441697102 100644 (file)
@@ -23,6 +23,8 @@
  * http://helm.cs.unibo.it/
  *)
 
+open Printf
+
 let pp_tactical = TacticAst2Box.tacticalPp
 
 let mode =
@@ -41,9 +43,9 @@ let _ =
   let ic = stdin in
   try
     while true do
+      let line = input_line ic in
+      let istream = Stream.of_string line in
       try
-        let line = input_line ic in
-        let istream = Stream.of_string line in
         (match mode with
         | `Term ->
             let term = CicTextualParser2.parse_term istream in
@@ -59,12 +61,13 @@ let _ =
             print_endline (CicTextualParser2.EnvironmentP3.to_string env));
         flush stdout
       with
-      | CicTextualParser2.Parse_error msg -> prerr_endline msg
-(*
-      | Stdpp.Exc_located ((p_start, p_end), exn) ->
-        prerr_endline (Printf.sprintf "Exception at character %d-%d: %s"
-          p_start p_end (Printexc.to_string exn))
-*)
+      | CicTextualParser2.Parse_error (floc, msg) ->
+          let (x, y) = CicAst.loc_of_floc floc in
+          let before = String.sub line 0 x in
+          let error = String.sub line x (y - x) in
+          let after = String.sub line y (String.length line - y) in
+          eprintf "%s\e[01;31m%s\e[00m%s\n" before error after;
+          prerr_endline (sprintf "at character %d-%d: %s" x y msg)
     done
   with End_of_file ->
     close_in ic