]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/ocaml/cic_disambiguation/test_parser.ml
- factorized DisambiguateChoices module
[helm.git] / helm / ocaml / cic_disambiguation / test_parser.ml
index 1813fd641457953419cb74324ca1312eda26c082..a3bba5a5a9b4bf74207a562ab288fdbd976c56bf 100644 (file)
  * http://helm.cs.unibo.it/
  *)
 
-try
-  let ic =
-    (try
-      open_in Sys.argv.(1)
-    with Invalid_argument _ -> stdin)
-  in
-  let term = CicTextualParser2.parse_term (Stream.of_channel ic) in
-  close_in ic;
-  print_endline (CicTextualParser2Pp.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
+
+let _ =
+  try
+    match Sys.argv.(1) with
+    | "alias" -> mode := `Alias
+    | "term" -> mode := `Term
+    | _ -> ()
+  with Invalid_argument _ -> ()
+
+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 (CicTextualParser2Pp.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))