From: Jérémie D. <Ba...@us...> - 2010-03-27 00:17:13
|
This is an automated email from the git hooks/post-receive script. It was generated because a ref change was pushed to the repository containing the project "krobot". The branch, master has been updated via 18c7915f2a9ef5e87d54d6403c22c59fbb032fa6 (commit) from 88fdac751bdee68f38724e833e8091651cec68d6 (commit) Those revisions listed above that are new to this repository have not appeared on any other notification email; so we list those revisions in full, below. - Log ----------------------------------------------------------------- commit 18c7915f2a9ef5e87d54d6403c22c59fbb032fa6 Author: Jérémie Dimino <je...@di...> Date: Sat Mar 27 01:16:49 2010 +0100 Add Gen_print ----------------------------------------------------------------------- Changes: diff --git a/PC_Mainboard/generators/gen_print.ml b/PC_Mainboard/generators/gen_print.ml new file mode 100644 index 0000000..2fb2305 --- /dev/null +++ b/PC_Mainboard/generators/gen_print.ml @@ -0,0 +1,42 @@ +(* + * gen_print.ml + * ------------ + * Copyright : (c) 2010, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +type template = string + +exception Unbound + +let print ?env template = + match env with + | None -> + print_string template; + print_char '\n' + | Some env -> + let buf = Buffer.create 42 in + let env name = + try + List.assoc name env + with Not_found -> + Printf.ksprintf failwith "Gen_print.print: unbound variable %S" name + in + let eval expr = + try + let i = String.index expr ':' in + let command = String.sub expr 0 i + and var = String.sub expr (i + 1) (String.length expr - (i + 1)) in + match command with + | "lid" -> Gen.lid (env var) + | "uid" -> Gen.uid (env var) + | "caml-case" -> Gen.caml_case (env var) + | _ -> Printf.ksprintf failwith "Gen_print.print: unknown command %S" command + with Not_found -> + env expr + in + Buffer.add_substitute buf eval template; + Buffer.add_char buf '\n'; + Buffer.output_buffer stdout buf diff --git a/PC_Mainboard/generators/gen_print.mli b/PC_Mainboard/generators/gen_print.mli new file mode 100644 index 0000000..684a60d --- /dev/null +++ b/PC_Mainboard/generators/gen_print.mli @@ -0,0 +1,23 @@ +(* + * gen_print.mli + * ------------- + * Copyright : (c) 2010, Jeremie Dimino <je...@di...> + * Licence : BSD3 + * + * This file is a part of [kro]bot. + *) + +(** Helpers for printing code *) + +type template = string + (** A string nthat may contains variables of the form: + + - [$(var)] + - [$(uid:var)] + - [$(lid:var)] + - [$(caml-case:var)] + *) + +val print : ?env : (string * string) list -> template -> unit + (** [print ?env template] prints the instantiation of [template] + using [env] on stdout *) hooks/post-receive -- krobot |