git.annexia.org
/
whenjobs.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Allow get_dependencies to check dependencies of multiple variables.
[whenjobs.git]
/
lib
/
pa_when.ml
diff --git
a/lib/pa_when.ml
b/lib/pa_when.ml
index
6e0592d
..
2f415ea
100644
(file)
--- a/
lib/pa_when.ml
+++ b/
lib/pa_when.ml
@@
-75,6
+75,11
@@
let expr_of_loc _loc loc =
$`int:stop_line$, $`int:stop_bol$, $`int:stop_off$,
$`bool:ghost$) >>
$`int:stop_line$, $`int:stop_bol$, $`int:stop_off$,
$`bool:ghost$) >>
+(* Convert 'expr option' to an expression that contains the option inside. *)
+let expr_of_option _loc = function
+ | None -> <:expr< None >>
+ | Some e -> <:expr< Some $e$ >>
+
(* "Lift" an expression, turning it from an expression into an OCaml
* abstract syntax tree in the output. This is pretty obscure.
* http://caml.inria.fr/pub/ml-archives/caml-list/2008/09/591f7c4a8df9295d675a5adcb6802748.en.html
(* "Lift" an expression, turning it from an expression into an OCaml
* abstract syntax tree in the output. This is pretty obscure.
* http://caml.inria.fr/pub/ml-archives/caml-list/2008/09/591f7c4a8df9295d675a5adcb6802748.en.html
@@
-83,14
+88,16
@@
module M = Ast.Meta.Make (Ast.Meta.MetaGhostLoc)
let lift_expr = M.Expr.meta_expr
(* Handle a top level statement. *)
let lift_expr = M.Expr.meta_expr
(* Handle a top level statement. *)
-let rec call_stmt
name
(_loc, stmt, sh) =
+let rec call_stmt
?name ?pre ?post
(_loc, stmt, sh) =
let name =
match name with
| None -> let name = unique_job_name () in <:expr< $str:name$ >>
| Some name -> name in
let name =
match name with
| None -> let name = unique_job_name () in <:expr< $str:name$ >>
| Some name -> name in
+ let pre = expr_of_option _loc pre in
+ let post = expr_of_option _loc post in
match stmt with
match stmt with
- | `When e -> when_stmt _loc name e sh
- | `Every p -> every_stmt _loc name p sh
+ | `When e -> when_stmt _loc name
pre post
e sh
+ | `Every p -> every_stmt _loc name p
re post p
sh
(* Handle a top level "when" statement.
* e -> when expression
(* Handle a top level "when" statement.
* e -> when expression
@@
-98,20
+105,20
@@
let rec call_stmt name (_loc, stmt, sh) =
* Returns a top level statement (str_item) which when executed just
* adds the statement to a global list.
*)
* Returns a top level statement (str_item) which when executed just
* adds the statement to a global list.
*)
-and when_stmt _loc name e sh =
+and when_stmt _loc name
pre post
e sh =
let loc = expr_of_loc _loc _loc in
let e = lift_expr _loc e in
<:str_item<
open Camlp4.PreCast
let loc = expr_of_loc _loc _loc in
let e = lift_expr _loc e in
<:str_item<
open Camlp4.PreCast
- Whenfile.add_when_job $loc$ $name$ $e$ $sh$
+ Whenfile.add_when_job $loc$ $name$ $
pre$ $post$ $
e$ $sh$
>>
(* Handle a top level "every" statement. *)
>>
(* Handle a top level "every" statement. *)
-and every_stmt _loc name period sh =
+and every_stmt _loc name p
re post p
eriod sh =
let loc = expr_of_loc _loc _loc in
<:str_item<
open Camlp4.PreCast
let loc = expr_of_loc _loc _loc in
<:str_item<
open Camlp4.PreCast
- Whenfile.add_every_job $loc$ $name$ $period$ $sh$
+ Whenfile.add_every_job $loc$ $name$ $p
re$ $post$ $p
eriod$ $sh$
>>
let () =
>>
let () =
@@
-203,6
+210,10
@@
EXTEND Gram
| [ e = period_parser -> e ]
];
| [ e = period_parser -> e ]
];
+ (* Pre and post functions. *)
+ pre: [[ "pre"; f = expr -> f ]];
+ post: [[ "post"; f = expr -> f ]];
+
(* Top level statements. *)
statement: [
[ "when"; e = expr; ":"; sh = expr ->
(* Top level statements. *)
statement: [
[ "when"; e = expr; ":"; sh = expr ->
@@
-213,8
+224,12
@@
EXTEND Gram
(* "str_item" is a top level statement in an OCaml program. *)
str_item: LEVEL "top" [
(* "str_item" is a top level statement in an OCaml program. *)
str_item: LEVEL "top" [
- [ s = statement -> call_stmt None s ]
- | [ "job"; name = expr; s = statement -> call_stmt (Some name) s ]
+ [ s = statement -> call_stmt s ]
+ | [ "job"; name = expr;
+ pre = OPT pre;
+ post = OPT post;
+ s = statement ->
+ call_stmt ~name ?pre ?post s ]
];
END
];
END