author | wenzelm |
Sun, 27 Mar 2011 19:27:31 +0200 | |
changeset 42133 | 74479999cf25 |
parent 42131 | 1d9710ff7209 |
child 42134 | 4bc55652c685 |
permissions | -rw-r--r-- |
18 | 1 |
(* Title: Pure/Syntax/type_ext.ML |
0 | 2 |
Author: Tobias Nipkow and Markus Wenzel, TU Muenchen |
3 |
||
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
4 |
Utilities for input and output of types. The concrete syntax of types. |
0 | 5 |
*) |
6 |
||
7 |
signature TYPE_EXT0 = |
|
2584 | 8 |
sig |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
9 |
val sort_of_term: term -> sort |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
10 |
val term_sorts: term -> (indexname * sort) list |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
11 |
val typ_of_term: (indexname -> sort) -> term -> typ |
42053
006095137a81
update_name_tr: more precise handling of explicit constraints, including positions;
wenzelm
parents:
42052
diff
changeset
|
12 |
val is_position: term -> bool |
42050
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
13 |
val strip_positions: term -> term |
42052
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
14 |
val strip_positions_ast: Ast.ast -> Ast.ast |
22764 | 15 |
val decode_term: (((string * int) * sort) list -> string * int -> sort) -> |
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
16 |
(string -> bool * string) -> (string -> string option) -> term -> |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
17 |
(Position.T * Markup.T) list * term |
6901 | 18 |
val term_of_typ: bool -> typ -> term |
10572 | 19 |
val no_brackets: unit -> bool |
16614 | 20 |
val no_type_brackets: unit -> bool |
35668 | 21 |
val type_ast_trs: |
22 |
{read_class: Proof.context -> string -> string, |
|
23 |
read_type: Proof.context -> string -> string} -> |
|
24 |
(string * (Proof.context -> Ast.ast list -> Ast.ast)) list |
|
2584 | 25 |
end; |
0 | 26 |
|
27 |
signature TYPE_EXT = |
|
2584 | 28 |
sig |
0 | 29 |
include TYPE_EXT0 |
2584 | 30 |
val term_of_sort: sort -> term |
1511 | 31 |
val tappl_ast_tr': Ast.ast * Ast.ast list -> Ast.ast |
8895 | 32 |
val sortT: typ |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36502
diff
changeset
|
33 |
val type_ext: Syn_Ext.syn_ext |
2584 | 34 |
end; |
0 | 35 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36502
diff
changeset
|
36 |
structure Type_Ext: TYPE_EXT = |
0 | 37 |
struct |
2584 | 38 |
|
39 |
(** input utils **) |
|
0 | 40 |
|
8895 | 41 |
(* sort_of_term *) |
2584 | 42 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
43 |
fun sort_of_term tm = |
557
9d386e6c02b7
added raw_term_sorts and changed typ_of_term accordingly (part of fix
wenzelm
parents:
347
diff
changeset
|
44 |
let |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
45 |
fun err () = raise TERM ("sort_of_term: bad encoding of classes", [tm]); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
46 |
|
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
47 |
fun class s = Lexicon.unmark_class s handle Fail _ => err (); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
48 |
|
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
49 |
fun classes (Const (s, _)) = [class s] |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
50 |
| classes (Const ("_classes", _) $ Const (s, _) $ cs) = class s :: classes cs |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
51 |
| classes _ = err (); |
0 | 52 |
|
2584 | 53 |
fun sort (Const ("_topsort", _)) = [] |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
54 |
| sort (Const (s, _)) = [class s] |
3778 | 55 |
| sort (Const ("_sort", _) $ cs) = classes cs |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
56 |
| sort _ = err (); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
57 |
in sort tm end; |
8895 | 58 |
|
2584 | 59 |
|
22704 | 60 |
(* term_sorts *) |
8895 | 61 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
62 |
fun term_sorts tm = |
8895 | 63 |
let |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
64 |
val sort_of = sort_of_term; |
22704 | 65 |
|
66 |
fun add_env (Const ("_ofsort", _) $ Free (x, _) $ cs) = |
|
67 |
insert (op =) ((x, ~1), sort_of cs) |
|
68 |
| add_env (Const ("_ofsort", _) $ (Const ("_tfree", _) $ Free (x, _)) $ cs) = |
|
69 |
insert (op =) ((x, ~1), sort_of cs) |
|
70 |
| add_env (Const ("_ofsort", _) $ Var (xi, _) $ cs) = |
|
71 |
insert (op =) (xi, sort_of cs) |
|
72 |
| add_env (Const ("_ofsort", _) $ (Const ("_tvar", _) $ Var (xi, _)) $ cs) = |
|
73 |
insert (op =) (xi, sort_of cs) |
|
74 |
| add_env (Abs (_, _, t)) = add_env t |
|
75 |
| add_env (t1 $ t2) = add_env t1 #> add_env t2 |
|
76 |
| add_env _ = I; |
|
8895 | 77 |
in add_env tm [] end; |
557
9d386e6c02b7
added raw_term_sorts and changed typ_of_term accordingly (part of fix
wenzelm
parents:
347
diff
changeset
|
78 |
|
9d386e6c02b7
added raw_term_sorts and changed typ_of_term accordingly (part of fix
wenzelm
parents:
347
diff
changeset
|
79 |
|
2584 | 80 |
(* typ_of_term *) |
0 | 81 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
82 |
fun typ_of_term get_sort tm = |
557
9d386e6c02b7
added raw_term_sorts and changed typ_of_term accordingly (part of fix
wenzelm
parents:
347
diff
changeset
|
83 |
let |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
84 |
fun err () = raise TERM ("typ_of_term: bad encoding of type", [tm]); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
85 |
|
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
86 |
fun typ_of (Free (x, _)) = TFree (x, get_sort (x, ~1)) |
557
9d386e6c02b7
added raw_term_sorts and changed typ_of_term accordingly (part of fix
wenzelm
parents:
347
diff
changeset
|
87 |
| typ_of (Var (xi, _)) = TVar (xi, get_sort xi) |
32784 | 88 |
| typ_of (Const ("_tfree",_) $ (t as Free _)) = typ_of t |
89 |
| typ_of (Const ("_tvar",_) $ (t as Var _)) = typ_of t |
|
12317 | 90 |
| typ_of (Const ("_ofsort", _) $ Free (x, _) $ _) = TFree (x, get_sort (x, ~1)) |
16614 | 91 |
| typ_of (Const ("_ofsort", _) $ (Const ("_tfree",_) $ Free (x, _)) $ _) = |
92 |
TFree (x, get_sort (x, ~1)) |
|
12317 | 93 |
| typ_of (Const ("_ofsort", _) $ Var (xi, _) $ _) = TVar (xi, get_sort xi) |
16614 | 94 |
| typ_of (Const ("_ofsort", _) $ (Const ("_tvar",_) $ Var (xi, _)) $ _) = |
95 |
TVar (xi, get_sort xi) |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
96 |
| typ_of (Const ("_dummy_ofsort", _) $ t) = TFree ("'_dummy_", sort_of_term t) |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
97 |
| typ_of t = |
0 | 98 |
let |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
99 |
val (head, args) = Term.strip_comb t; |
0 | 100 |
val a = |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
101 |
(case head of |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
102 |
Const (c, _) => (Lexicon.unmark_type c handle Fail _ => err ()) |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
103 |
| _ => err ()); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
104 |
in Type (a, map typ_of args) end; |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
105 |
in typ_of tm end; |
0 | 106 |
|
107 |
||
42050
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
108 |
(* positions *) |
22704 | 109 |
|
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
110 |
fun decode_position (Free (x, _)) = Lexicon.decode_position x |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
111 |
| decode_position _ = NONE; |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
112 |
|
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
113 |
val is_position = is_some o decode_position; |
42048
afd11ca8e018
support for encoded positions (for id_position, longid_position) as pseudo type-constraints -- still inactive;
wenzelm
parents:
39288
diff
changeset
|
114 |
|
42050
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
115 |
fun strip_positions ((t as Const (c, _)) $ u $ v) = |
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
116 |
if (c = "_constrain" orelse c = "_constrainAbs") andalso is_position v |
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
117 |
then strip_positions u |
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
118 |
else t $ strip_positions u $ strip_positions v |
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
119 |
| strip_positions (t $ u) = strip_positions t $ strip_positions u |
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
120 |
| strip_positions (Abs (x, T, t)) = Abs (x, T, strip_positions t) |
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
121 |
| strip_positions t = t; |
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
122 |
|
42052
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
123 |
fun strip_positions_ast (Ast.Appl ((t as Ast.Constant c) :: u :: (v as Ast.Variable x) :: asts)) = |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
124 |
if (c = "_constrain" orelse c = "_constrainAbs") andalso is_some (Lexicon.decode_position x) |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
125 |
then Ast.mk_appl (strip_positions_ast u) (map strip_positions_ast asts) |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
126 |
else Ast.Appl (map strip_positions_ast (t :: u :: v :: asts)) |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
127 |
| strip_positions_ast (Ast.Appl asts) = Ast.Appl (map strip_positions_ast asts) |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
128 |
| strip_positions_ast ast = ast; |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
129 |
|
42050
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
130 |
|
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
131 |
(* decode_term -- transform parse tree into raw term *) |
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
132 |
|
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
133 |
val markup_const = Markup.const; |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
134 |
fun markup_free x = Markup.name x Markup.free; |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
135 |
fun markup_var xi = Markup.name (Term.string_of_vname xi) Markup.var; |
42133 | 136 |
|
137 |
fun markup_bound def id = |
|
138 |
Markup.properties [(if def then Markup.defN else Markup.refN, id)] Markup.bound; |
|
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
139 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
140 |
fun decode_term get_sort map_const map_free tm = |
22704 | 141 |
let |
36448
edb757388592
get_sort: minimize sorts given in the text, while keeping those from the context unchanged (the latter are preferred);
wenzelm
parents:
35668
diff
changeset
|
142 |
val decodeT = typ_of_term (get_sort (term_sorts tm)); |
22704 | 143 |
|
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
144 |
val reports = Unsynchronized.ref ([]: (Position.T * Markup.T) list); |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
145 |
fun report [] _ _ = () |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
146 |
| report ps markup x = |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
147 |
let val m = markup x |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
148 |
in Unsynchronized.change reports (fold (fn p => cons (p, m)) ps) end; |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
149 |
|
42133 | 150 |
fun decode ps qs bs (Const ("_constrain", _) $ t $ typ) = |
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
151 |
(case decode_position typ of |
42133 | 152 |
SOME p => decode (p :: ps) qs bs t |
153 |
| NONE => Type.constraint (decodeT typ) (decode ps qs bs t)) |
|
154 |
| decode ps qs bs (Const ("_constrainAbs", _) $ t $ typ) = |
|
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
155 |
(case decode_position typ of |
42133 | 156 |
SOME q => decode ps (q :: qs) bs t |
157 |
| NONE => Type.constraint (decodeT typ --> dummyT) (decode ps qs bs t)) |
|
158 |
| decode _ qs bs (Abs (x, T, t)) = |
|
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
159 |
let |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
160 |
val id = serial_string (); |
42133 | 161 |
val _ = report qs (markup_bound true) id; |
162 |
in Abs (x, T, decode [] [] (id :: bs) t) end |
|
163 |
| decode _ _ bs (t $ u) = decode [] [] bs t $ decode [] [] bs u |
|
164 |
| decode ps _ _ (Const (a, T)) = |
|
36502
586af36cf3cc
uniform decoding of fixed/const syntax entities, allows to pass "\<^fixed>foo__" through the syntax layer (supersedes 1b7109c10b7b);
wenzelm
parents:
36448
diff
changeset
|
165 |
(case try Lexicon.unmark_fixed a of |
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
166 |
SOME x => (report ps markup_free x; Free (x, T)) |
36502
586af36cf3cc
uniform decoding of fixed/const syntax entities, allows to pass "\<^fixed>foo__" through the syntax layer (supersedes 1b7109c10b7b);
wenzelm
parents:
36448
diff
changeset
|
167 |
| NONE => |
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
168 |
let |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
169 |
val c = |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
170 |
(case try Lexicon.unmark_const a of |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
171 |
SOME c => c |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
172 |
| NONE => snd (map_const a)); |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
173 |
val _ = report ps markup_const c; |
36502
586af36cf3cc
uniform decoding of fixed/const syntax entities, allows to pass "\<^fixed>foo__" through the syntax layer (supersedes 1b7109c10b7b);
wenzelm
parents:
36448
diff
changeset
|
174 |
in Const (c, T) end) |
42133 | 175 |
| decode ps _ _ (Free (a, T)) = |
22704 | 176 |
(case (map_free a, map_const a) of |
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
177 |
(SOME x, _) => (report ps markup_free x; Free (x, T)) |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
178 |
| (_, (true, c)) => (report ps markup_const c; Const (c, T)) |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
179 |
| (_, (false, c)) => |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
180 |
if Long_Name.is_qualified c |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
181 |
then (report ps markup_const c; Const (c, T)) |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
182 |
else (report ps markup_free c; Free (c, T))) |
42133 | 183 |
| decode ps _ _ (Var (xi, T)) = (report ps markup_var xi; Var (xi, T)) |
184 |
| decode ps _ bs (t as Bound i) = |
|
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
185 |
(case try (nth bs) i of |
42133 | 186 |
SOME id => (report ps (markup_bound false) id; t) |
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
187 |
| NONE => t); |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
188 |
|
42133 | 189 |
val tm' = decode [] [] [] tm; |
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
190 |
in (! reports, tm') end; |
22704 | 191 |
|
192 |
||
0 | 193 |
|
2584 | 194 |
(** output utils **) |
195 |
||
2699 | 196 |
(* term_of_sort *) |
2584 | 197 |
|
198 |
fun term_of_sort S = |
|
199 |
let |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
200 |
val class = Lexicon.const o Lexicon.mark_class; |
2584 | 201 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
202 |
fun classes [c] = class c |
5690 | 203 |
| classes (c :: cs) = Lexicon.const "_classes" $ class c $ classes cs; |
2584 | 204 |
in |
205 |
(case S of |
|
5690 | 206 |
[] => Lexicon.const "_topsort" |
2584 | 207 |
| [c] => class c |
5690 | 208 |
| cs => Lexicon.const "_sort" $ classes cs) |
2584 | 209 |
end; |
210 |
||
211 |
||
212 |
(* term_of_typ *) |
|
0 | 213 |
|
214 |
fun term_of_typ show_sorts ty = |
|
215 |
let |
|
2584 | 216 |
fun of_sort t S = |
5690 | 217 |
if show_sorts then Lexicon.const "_ofsort" $ t $ term_of_sort S |
2584 | 218 |
else t; |
0 | 219 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
220 |
fun term_of (Type (a, Ts)) = |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
221 |
Term.list_comb (Lexicon.const (Lexicon.mark_type a), map term_of Ts) |
42048
afd11ca8e018
support for encoded positions (for id_position, longid_position) as pseudo type-constraints -- still inactive;
wenzelm
parents:
39288
diff
changeset
|
222 |
| term_of (TFree (x, S)) = |
afd11ca8e018
support for encoded positions (for id_position, longid_position) as pseudo type-constraints -- still inactive;
wenzelm
parents:
39288
diff
changeset
|
223 |
if is_some (Lexicon.decode_position x) then Lexicon.free x |
afd11ca8e018
support for encoded positions (for id_position, longid_position) as pseudo type-constraints -- still inactive;
wenzelm
parents:
39288
diff
changeset
|
224 |
else of_sort (Lexicon.const "_tfree" $ Lexicon.free x) S |
5690 | 225 |
| term_of (TVar (xi, S)) = of_sort (Lexicon.const "_tvar" $ Lexicon.var xi) S; |
8895 | 226 |
in term_of ty end; |
0 | 227 |
|
228 |
||
229 |
||
230 |
(** the type syntax **) |
|
231 |
||
10572 | 232 |
(* print mode *) |
233 |
||
234 |
val bracketsN = "brackets"; |
|
235 |
val no_bracketsN = "no_brackets"; |
|
236 |
||
237 |
fun no_brackets () = |
|
24613 | 238 |
find_first (fn mode => mode = bracketsN orelse mode = no_bracketsN) |
239 |
(print_mode_value ()) = SOME no_bracketsN; |
|
11312 | 240 |
|
241 |
val type_bracketsN = "type_brackets"; |
|
242 |
val no_type_bracketsN = "no_type_brackets"; |
|
243 |
||
244 |
fun no_type_brackets () = |
|
24613 | 245 |
find_first (fn mode => mode = type_bracketsN orelse mode = no_type_bracketsN) |
246 |
(print_mode_value ()) <> SOME type_bracketsN; |
|
10572 | 247 |
|
248 |
||
18 | 249 |
(* parse ast translations *) |
0 | 250 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
251 |
val class_ast = Ast.Constant o Lexicon.mark_class; |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
252 |
val type_ast = Ast.Constant o Lexicon.mark_type; |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
253 |
|
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
254 |
fun class_name_tr read_class (*"_class_name"*) [Ast.Variable c] = class_ast (read_class c) |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
255 |
| class_name_tr _ (*"_class_name"*) asts = raise Ast.AST ("class_name_tr", asts); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
256 |
|
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
257 |
fun classes_tr read_class (*"_classes"*) [Ast.Variable c, ast] = |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
258 |
Ast.mk_appl (Ast.Constant "_classes") [class_ast (read_class c), ast] |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
259 |
| classes_tr _ (*"_classes"*) asts = raise Ast.AST ("classes_tr", asts); |
347
cd41a57221d0
changed translation of type applications according to new grammar;
wenzelm
parents:
330
diff
changeset
|
260 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
261 |
fun type_name_tr read_type (*"_type_name"*) [Ast.Variable c] = type_ast (read_type c) |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
262 |
| type_name_tr _ (*"_type_name"*) asts = raise Ast.AST ("type_name_tr", asts); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
263 |
|
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
264 |
fun tapp_ast_tr read_type (*"_tapp"*) [ty, Ast.Variable c] = |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
265 |
Ast.Appl [type_ast (read_type c), ty] |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
266 |
| tapp_ast_tr _ (*"_tapp"*) asts = raise Ast.AST ("tapp_ast_tr", asts); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
267 |
|
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
268 |
fun tappl_ast_tr read_type (*"_tappl"*) [ty, tys, Ast.Variable c] = |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
269 |
Ast.Appl (type_ast (read_type c) :: ty :: Ast.unfold_ast "_types" tys) |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
270 |
| tappl_ast_tr _ (*"_tappl"*) asts = raise Ast.AST ("tappl_ast_tr", asts); |
0 | 271 |
|
272 |
fun bracket_ast_tr (*"_bracket"*) [dom, cod] = |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
273 |
Ast.fold_ast_p "\\<^type>fun" (Ast.unfold_ast "_types" dom, cod) |
5690 | 274 |
| bracket_ast_tr (*"_bracket"*) asts = raise Ast.AST ("bracket_ast_tr", asts); |
0 | 275 |
|
276 |
||
18 | 277 |
(* print ast translations *) |
0 | 278 |
|
5690 | 279 |
fun tappl_ast_tr' (f, []) = raise Ast.AST ("tappl_ast_tr'", [f]) |
280 |
| tappl_ast_tr' (f, [ty]) = Ast.Appl [Ast.Constant "_tapp", ty, f] |
|
347
cd41a57221d0
changed translation of type applications according to new grammar;
wenzelm
parents:
330
diff
changeset
|
281 |
| tappl_ast_tr' (f, ty :: tys) = |
5690 | 282 |
Ast.Appl [Ast.Constant "_tappl", ty, Ast.fold_ast "_types" tys, f]; |
0 | 283 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
284 |
fun fun_ast_tr' (*"\\<^type>fun"*) asts = |
16614 | 285 |
if no_brackets () orelse no_type_brackets () then raise Match |
10572 | 286 |
else |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
287 |
(case Ast.unfold_ast_p "\\<^type>fun" (Ast.Appl (Ast.Constant "\\<^type>fun" :: asts)) of |
10572 | 288 |
(dom as _ :: _ :: _, cod) |
289 |
=> Ast.Appl [Ast.Constant "_bracket", Ast.fold_ast "_types" dom, cod] |
|
290 |
| _ => raise Match); |
|
0 | 291 |
|
292 |
||
293 |
(* type_ext *) |
|
294 |
||
295 |
val sortT = Type ("sort", []); |
|
296 |
val classesT = Type ("classes", []); |
|
297 |
val typesT = Type ("types", []); |
|
298 |
||
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36502
diff
changeset
|
299 |
local open Lexicon Syn_Ext in |
5690 | 300 |
|
35668 | 301 |
val type_ext = syn_ext' false (K false) |
347
cd41a57221d0
changed translation of type applications according to new grammar;
wenzelm
parents:
330
diff
changeset
|
302 |
[Mfix ("_", tidT --> typeT, "", [], max_pri), |
239 | 303 |
Mfix ("_", tvarT --> typeT, "", [], max_pri), |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
304 |
Mfix ("_", idT --> typeT, "_type_name", [], max_pri), |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
305 |
Mfix ("_", longidT --> typeT, "_type_name", [], max_pri), |
330
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
258
diff
changeset
|
306 |
Mfix ("_::_", [tidT, sortT] ---> typeT, "_ofsort", [max_pri, 0], max_pri), |
239 | 307 |
Mfix ("_::_", [tvarT, sortT] ---> typeT, "_ofsort", [max_pri, 0], max_pri), |
14838 | 308 |
Mfix ("'_()::_", sortT --> typeT, "_dummy_ofsort", [0], max_pri), |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
309 |
Mfix ("_", idT --> sortT, "_class_name", [], max_pri), |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
310 |
Mfix ("_", longidT --> sortT, "_class_name", [], max_pri), |
2584 | 311 |
Mfix ("{}", sortT, "_topsort", [], max_pri), |
239 | 312 |
Mfix ("{_}", classesT --> sortT, "_sort", [], max_pri), |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
313 |
Mfix ("_", idT --> classesT, "_class_name", [], max_pri), |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
314 |
Mfix ("_", longidT --> classesT, "_class_name", [], max_pri), |
239 | 315 |
Mfix ("_,_", [idT, classesT] ---> classesT, "_classes", [], max_pri), |
3829 | 316 |
Mfix ("_,_", [longidT, classesT] ---> classesT, "_classes", [], max_pri), |
330
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
258
diff
changeset
|
317 |
Mfix ("_ _", [typeT, idT] ---> typeT, "_tapp", [max_pri, 0], max_pri), |
3829 | 318 |
Mfix ("_ _", [typeT, longidT] ---> typeT, "_tapp", [max_pri, 0], max_pri), |
9067 | 319 |
Mfix ("((1'(_,/ _')) _)", [typeT, typesT, idT] ---> typeT, "_tappl", [], max_pri), |
320 |
Mfix ("((1'(_,/ _')) _)", [typeT, typesT, longidT] ---> typeT, "_tappl", [], max_pri), |
|
239 | 321 |
Mfix ("_", typeT --> typesT, "", [], max_pri), |
322 |
Mfix ("_,/ _", [typeT, typesT] ---> typesT, "_types", [], max_pri), |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
323 |
Mfix ("(_/ => _)", [typeT, typeT] ---> typeT, "\\<^type>fun", [1, 0], 0), |
624 | 324 |
Mfix ("([_]/ => _)", [typesT, typeT] ---> typeT, "_bracket", [0, 0], 0), |
2678 | 325 |
Mfix ("'(_')", typeT --> typeT, "", [0], max_pri), |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
326 |
Mfix ("'_", typeT, "\\<^type>dummy", [], max_pri)] |
35433
73cc288b4f83
"_type_prop" is syntax const -- recovered printing of OFCLASS;
wenzelm
parents:
35429
diff
changeset
|
327 |
["_type_prop"] |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36502
diff
changeset
|
328 |
([], [], [], map Syn_Ext.mk_trfun [("\\<^type>fun", K fun_ast_tr')]) |
26708
fc2e7d2f763d
moved default token translations to proof_context.ML, if all fails the pretty printer falls back on plain output;
wenzelm
parents:
26039
diff
changeset
|
329 |
[] |
239 | 330 |
([], []); |
0 | 331 |
|
35668 | 332 |
fun type_ast_trs {read_class, read_type} = |
333 |
[("_class_name", class_name_tr o read_class), |
|
334 |
("_classes", classes_tr o read_class), |
|
335 |
("_type_name", type_name_tr o read_type), |
|
336 |
("_tapp", tapp_ast_tr o read_type), |
|
337 |
("_tappl", tappl_ast_tr o read_type), |
|
338 |
("_bracket", K bracket_ast_tr)]; |
|
339 |
||
0 | 340 |
end; |
5690 | 341 |
|
342 |
end; |