diff options
author | Nicolas Pouillard <np@nicolaspouillard.fr> | 2007-12-18 09:02:19 +0000 |
---|---|---|
committer | Nicolas Pouillard <np@nicolaspouillard.fr> | 2007-12-18 09:02:19 +0000 |
commit | 63bfcc74c699260f5973c4f6f5ac98276b08a88b (patch) | |
tree | c6abe9e518ed8e1272fa3f074ad905a4cf9d1987 /camlp4/examples/lambda_quot_expr.ml | |
parent | ebb6348c1e6f68a4256ac84827e730ca6deac3e9 (diff) |
camlp4,fix,quot: Properly handle <:patt< $`bool:p$ >>.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@8721 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Diffstat (limited to 'camlp4/examples/lambda_quot_expr.ml')
-rw-r--r-- | camlp4/examples/lambda_quot_expr.ml | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/camlp4/examples/lambda_quot_expr.ml b/camlp4/examples/lambda_quot_expr.ml new file mode 100644 index 000000000..3b51f47f5 --- /dev/null +++ b/camlp4/examples/lambda_quot_expr.ml @@ -0,0 +1,40 @@ +(* Please keep me in sync with brion.inria.fr/gallium/index.php/Lambda_calculus_quotations *) + +open Camlp4.PreCast;; +module CamlSyntax = Camlp4OCamlParser.Make(Camlp4OCamlRevisedParser.Make(Syntax));; + +let expr_of_string = CamlSyntax.Gram.parse_string CamlSyntax.expr_eoi;; + +module LambdaGram = MakeGram(Lexer);; + +let term = LambdaGram.Entry.mk "term";; +let term_eoi = LambdaGram.Entry.mk "lambda term quotation";; + +Camlp4_config.antiquotations := true;; + +EXTEND LambdaGram + GLOBAL: term term_eoi; + term: + [ "top" + [ "fun"; v = var; "->"; t = term -> <:expr< `Lam($v$, $t$) >> ] + | "app" + [ t1 = SELF; t2 = SELF -> <:expr< `App($t1$, $t2$) >> ] + | "simple" + [ `ANTIQUOT((""|"term"), a) -> expr_of_string _loc a + | v = var -> <:expr< `Var($v$) >> + | "("; t = term; ")" -> t ] + ]; + var: + [[ v = LIDENT -> <:expr< $str:v$ >> + | `ANTIQUOT((""|"var"), a) -> expr_of_string _loc a + ]]; + term_eoi: + [[ t = term; `EOI -> t ]]; +END;; + +let expand_lambda_quot_expr loc _loc_name_opt quotation_contents = + LambdaGram.parse_string term_eoi loc quotation_contents;; + +Syntax.Quotation.add "lam" Syntax.Quotation.DynAst.expr_tag expand_lambda_quot_expr;; + +Syntax.Quotation.default := "lam";; |