Source

ocaml-lib / ipp / essai.ml

type t = Atom of string | Literal of string | Not of t | And of t list | Or of t * t

let rec print = ipp
  [ Atom s -> 's
  | Literal s -> "\""; ' String.escaped s; "\""
  | Not f -> "not "; print of f
  | And [] -> "true"
  | And l -> "("; LIST1 print SEP " and " of l; ")"
(*  | And (f1,f2) -> "("; print of f1; " and "; print of f2; ")" *)
  | Or (f1,f2) -> "("; print of f1; " or "; print of f2; ")"
  ]
(*
and print_and = ipp
    [ [] -> 
    | x::l -> " and "; print of x; print_and of l ]
*)

let do_print f =
  Ipp.once (ipp [f -> print of f; EOF ]) f (Printer.cursor_of_formatter Format.std_formatter) ();
  Format.pp_print_newline Format.std_formatter ()

let _ =
  do_print (Atom "x");
  do_print (Literal "toto");
  do_print (And [Atom "x"; Not (Literal "toto"); Or (Literal "a", Literal "b")])
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.