Allow job names to be arbitrary OCaml expressions.
[whenjobs.git] / lib / pa_when.ml
index 764cabc..6e0592d 100644 (file)
@@ -84,8 +84,10 @@ let lift_expr = M.Expr.meta_expr
 
 (* Handle a top level statement. *)
 let rec call_stmt name (_loc, stmt, sh) =
-  let name = if name <> "" then name else unique_job_name () in
-  let name = <:expr< $str:name$ >> in
+  let name =
+    match name with
+    | None -> let name = unique_job_name () in <:expr< $str:name$ >>
+    | Some name -> name in
   match stmt with
   | `When e -> when_stmt _loc name e sh
   | `Every p -> every_stmt _loc name p sh
@@ -211,8 +213,8 @@ EXTEND Gram
 
   (* "str_item" is a top level statement in an OCaml program. *)
   str_item: LEVEL "top" [
-    [ s = statement -> call_stmt "" s ]
-  | [ "job"; name = STRING; s = statement -> call_stmt name s ]
+    [ s = statement -> call_stmt None s ]
+  | [ "job"; name = expr; s = statement -> call_stmt (Some name) s ]
   ];
 
 END