| author | wenzelm |
| Wed, 23 Mar 2011 20:57:37 +0100 | |
| changeset 42078 | d5bf0ce40bd7 |
| parent 35113 | 1a0c129bb2e0 |
| child 42284 | 326f57825e1a |
| permissions | -rw-r--r-- |
| 5368 | 1 |
(* Title: HOL/ex/Antiquote.thy |
2 |
Author: Markus Wenzel, TU Muenchen |
|
3 |
*) |
|
4 |
||
| 10357 | 5 |
header {* Antiquotations *}
|
6 |
||
| 35113 | 7 |
theory Antiquote |
8 |
imports Main |
|
9 |
begin |
|
| 5368 | 10 |
|
| 11586 | 11 |
text {*
|
12 |
A simple example on quote / antiquote in higher-order abstract |
|
13 |
syntax. |
|
14 |
*} |
|
15 |
||
| 5368 | 16 |
syntax |
| 35113 | 17 |
"_Expr" :: "'a => 'a" ("EXPR _" [1000] 999)
|
| 5368 | 18 |
|
| 35113 | 19 |
definition |
20 |
var :: "'a => ('a => nat) => nat" ("VAR _" [1000] 999)
|
|
21 |
where "var x env = env x" |
|
| 5368 | 22 |
|
| 35113 | 23 |
definition |
| 8559 | 24 |
Expr :: "(('a => nat) => nat) => ('a => nat) => nat"
|
| 35113 | 25 |
where "Expr exp env = exp env" |
| 5368 | 26 |
|
| 35113 | 27 |
parse_translation {*
|
28 |
[Syntax.quote_antiquote_tr @{syntax_const "_Expr"} @{const_syntax var} @{const_syntax Expr}]
|
|
29 |
*} |
|
30 |
||
31 |
print_translation {*
|
|
32 |
[Syntax.quote_antiquote_tr' @{syntax_const "_Expr"} @{const_syntax var} @{const_syntax Expr}]
|
|
33 |
*} |
|
| 8559 | 34 |
|
| 9297 | 35 |
term "EXPR (a + b + c)" |
36 |
term "EXPR (a + b + c + VAR x + VAR y + 1)" |
|
37 |
term "EXPR (VAR (f w) + VAR x)" |
|
| 5368 | 38 |
|
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
16417
diff
changeset
|
39 |
term "Expr (\<lambda>env. env x)" -- {* improper *}
|
| 10357 | 40 |
term "Expr (\<lambda>env. f env)" |
|
32960
69916a850301
eliminated hard tabulators, guessing at each author's individual tab-width;
wenzelm
parents:
16417
diff
changeset
|
41 |
term "Expr (\<lambda>env. f env + env x)" -- {* improper *}
|
| 10357 | 42 |
term "Expr (\<lambda>env. f env y z)" |
43 |
term "Expr (\<lambda>env. f env + g y env)" |
|
44 |
term "Expr (\<lambda>env. f env + g env y + h a env z)" |
|
| 5368 | 45 |
|
| 9297 | 46 |
end |