Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Snippet insertion

  • Loading branch information...
commit fa4f9a7c39e08470cf7f01f47a950ed054816591 1 parent b171899
@VictorNicollet authored
Showing with 38 additions and 1 deletion.
  1. +35 −0 tool/snip.ml
  2. +3 −1 tool/tool.ml
View
35 tool/snip.ml
@@ -0,0 +1,35 @@
+(* Ohm is © 2013 Victor Nicollet *)
+
+open BatPervasives
+
+open Common
+
+let (--) name regex =
+ Str.string_match (Str.regexp regex) name 0
+ && Str.match_end () = String.length name
+
+let ml name =
+ "ocaml/" ^ String.uncapitalize name ^ ".ml"
+
+let mli name =
+ "ocaml/" ^ String.uncapitalize name ^ ".mli"
+
+let put list = List.iter (fun (file,contents) ->
+ let path = Filename.concat Path.root file in
+ if file_exists path && readfile path <> contents then
+ error "Could not write file" (Printf.sprintf "File %s already exists." path) ;
+ if putfile path contents then
+ print_endline (">> " ^ file)
+) list
+
+let id name = put [
+ ml name, "include Ohm.Id.Phantom\n" ;
+ mli name, "include Ohm.Id.PHANTOM\n" ;
+]
+
+
+let one = function
+ | name when name -- "I[A-Za-z0-9]*" -> id name
+ | name -> print_endline (Printf.sprintf "Don't know what to do with %S" name)
+
+let make args = List.iter one args
View
4 tool/tool.ml
@@ -1,4 +1,4 @@
-(* Ohm is © 2012 Victor Nicollet *)
+(* Ohm is © 2013 Victor Nicollet *)
open BatPervasives
@@ -223,6 +223,7 @@ let help () =
"vhost [apache|nginx]", "Output VHOST configuration on stdout" ;
"fastcgi [start|stop|apache]", "Control the FastCGI server" ;
"bot [start|stop]", "Control the asynchronous processing bot." ;
+ "snip", "Create a module from a snippet" ;
"publish", "Make a file or list of files public" ;
])
@@ -242,6 +243,7 @@ let () =
| Some "fastcgi" -> Fastcgi.tool args
| Some "clean" -> clean ()
| Some "publish" -> Publish.run args
+ | Some "snip" -> Snip.make args
| Some s when BatString.starts_with s "plugins." -> Plugins.parserun s args
| _ -> help ()
Please sign in to comment.
Something went wrong with that request. Please try again.