5368
|
1 |
(* Title: HOL/ex/Antiquote.thy
|
|
2 |
Author: Markus Wenzel, TU Muenchen
|
|
3 |
*)
|
|
4 |
|
59031
|
5 |
section \<open>Antiquotations\<close>
|
10357
|
6 |
|
35113
|
7 |
theory Antiquote
|
|
8 |
imports Main
|
|
9 |
begin
|
5368
|
10 |
|
59031
|
11 |
text \<open>A simple example on quote / antiquote in higher-order abstract syntax.\<close>
|
11586
|
12 |
|
56233
|
13 |
definition Expr :: "(('a \<Rightarrow> nat) \<Rightarrow> nat) \<Rightarrow> ('a \<Rightarrow> nat) \<Rightarrow> nat"
|
35113
|
14 |
where "Expr exp env = exp env"
|
5368
|
15 |
|
44603
|
16 |
syntax
|
81215
|
17 |
"_Expr" :: "'a \<Rightarrow> 'a" (\<open>(\<open>notation=\<open>prefix EXPR\<close>\<close>EXPR _)\<close> [1000] 999)
|
|
18 |
"_Var" :: "'a \<Rightarrow> ('a \<Rightarrow> nat) \<Rightarrow> nat" (\<open>(\<open>notation=\<open>prefix VAR\<close>\<close>VAR _)\<close> [1000] 999)
|
|
19 |
|
|
20 |
syntax_consts
|
|
21 |
"_Expr" \<rightleftharpoons> Expr
|
44603
|
22 |
|
59031
|
23 |
parse_translation
|
|
24 |
\<open>[Syntax_Trans.quote_antiquote_tr
|
81214
|
25 |
\<^syntax_const>\<open>_Expr\<close> \<^syntax_const>\<open>_Var\<close> \<^const_syntax>\<open>Expr\<close>]\<close>
|
35113
|
26 |
|
59031
|
27 |
print_translation
|
|
28 |
\<open>[Syntax_Trans.quote_antiquote_tr'
|
81214
|
29 |
\<^syntax_const>\<open>_Expr\<close> \<^syntax_const>\<open>_Var\<close> \<^const_syntax>\<open>Expr\<close>]\<close>
|
8559
|
30 |
|
9297
|
31 |
term "EXPR (a + b + c)"
|
|
32 |
term "EXPR (a + b + c + VAR x + VAR y + 1)"
|
|
33 |
term "EXPR (VAR (f w) + VAR x)"
|
5368
|
34 |
|
61933
|
35 |
term "Expr (\<lambda>env. env x)" \<comment> \<open>improper\<close>
|
10357
|
36 |
term "Expr (\<lambda>env. f env)"
|
61933
|
37 |
term "Expr (\<lambda>env. f env + env x)" \<comment> \<open>improper\<close>
|
10357
|
38 |
term "Expr (\<lambda>env. f env y z)"
|
|
39 |
term "Expr (\<lambda>env. f env + g y env)"
|
|
40 |
term "Expr (\<lambda>env. f env + g env y + h a env z)"
|
5368
|
41 |
|
9297
|
42 |
end
|