]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_disambiguation/test_parser.ml
split into two major parts:
[helm.git] / helm / ocaml / cic_disambiguation / test_parser.ml
index 0f6b2d162c07ab05d4fd1b21b21b8e6a26bcad52..581b8d3e401c13f9952577d39f1872eb051952f7 100644 (file)
  * http://helm.cs.unibo.it/
  *)
 
-try
-  let ic =
-    (try
-      open_in Sys.argv.(1)
-    with Invalid_argument _ -> stdin)
-  in
-  let term = Parser.parse_term (Stream.of_channel ic) in
-  close_in ic;
-  print_endline (Pp.pp_term term)
-with 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))
+let mode = ref `Term
 
-(* print_endline (Macro.expand "def") *)
+let _ =
+  try
+    match Sys.argv.(1) with
+    | "alias" -> mode := `Alias
+    | "term" -> mode := `Term
+    | _ -> ()
+  with Invalid_argument _ -> ()
 
-(* Printf.printf "'%s'\n" (Macro.expand Sys.argv.(1)) *)
+let _ =
+  try
+    let ic = stdin in
+    (match !mode with
+    | `Term ->
+        let term = CicTextualParser2.parse_term (Stream.of_channel ic) in
+        close_in ic;
+        print_endline (CicAstPp.pp_term term)
+    | `Alias ->
+        while true do
+          let line = input_line ic in
+          let env = CicTextualParser2.EnvironmentP3.of_string line in
+          print_endline (CicTextualParser2.EnvironmentP3.to_string env)
+        done)
+  with
+  | End_of_file -> ()
+  | 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))