author | wenzelm |
Tue, 05 Apr 2011 13:07:40 +0200 | |
changeset 42223 | 098c86e53153 |
parent 42204 | b3277168c1e7 |
child 42242 | 39261908e12f |
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 |
42134 | 15 |
type term_context |
42223
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
16 |
val decode_term: term_context -> |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
17 |
Position.reports * term Exn.result -> Position.reports * term Exn.result |
6901 | 18 |
val term_of_typ: bool -> typ -> term |
10572 | 19 |
val no_brackets: unit -> bool |
16614 | 20 |
val no_type_brackets: unit -> bool |
2584 | 21 |
end; |
0 | 22 |
|
23 |
signature TYPE_EXT = |
|
2584 | 24 |
sig |
0 | 25 |
include TYPE_EXT0 |
2584 | 26 |
val term_of_sort: sort -> term |
1511 | 27 |
val tappl_ast_tr': Ast.ast * Ast.ast list -> Ast.ast |
8895 | 28 |
val sortT: typ |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36502
diff
changeset
|
29 |
val type_ext: Syn_Ext.syn_ext |
2584 | 30 |
end; |
0 | 31 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36502
diff
changeset
|
32 |
structure Type_Ext: TYPE_EXT = |
0 | 33 |
struct |
2584 | 34 |
|
35 |
(** input utils **) |
|
0 | 36 |
|
8895 | 37 |
(* sort_of_term *) |
2584 | 38 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
39 |
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
|
40 |
let |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
41 |
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
|
42 |
|
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
43 |
fun class s = Lexicon.unmark_class s handle Fail _ => err (); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
44 |
|
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
45 |
fun classes (Const (s, _)) = [class s] |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
46 |
| classes (Const ("_classes", _) $ Const (s, _) $ cs) = class s :: classes cs |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
47 |
| classes _ = err (); |
0 | 48 |
|
2584 | 49 |
fun sort (Const ("_topsort", _)) = [] |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
50 |
| sort (Const (s, _)) = [class s] |
3778 | 51 |
| sort (Const ("_sort", _) $ cs) = classes cs |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
52 |
| sort _ = err (); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
53 |
in sort tm end; |
8895 | 54 |
|
2584 | 55 |
|
22704 | 56 |
(* term_sorts *) |
8895 | 57 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
58 |
fun term_sorts tm = |
8895 | 59 |
let |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
60 |
val sort_of = sort_of_term; |
22704 | 61 |
|
62 |
fun add_env (Const ("_ofsort", _) $ Free (x, _) $ cs) = |
|
63 |
insert (op =) ((x, ~1), sort_of cs) |
|
64 |
| add_env (Const ("_ofsort", _) $ (Const ("_tfree", _) $ Free (x, _)) $ cs) = |
|
65 |
insert (op =) ((x, ~1), sort_of cs) |
|
66 |
| add_env (Const ("_ofsort", _) $ Var (xi, _) $ cs) = |
|
67 |
insert (op =) (xi, sort_of cs) |
|
68 |
| add_env (Const ("_ofsort", _) $ (Const ("_tvar", _) $ Var (xi, _)) $ cs) = |
|
69 |
insert (op =) (xi, sort_of cs) |
|
70 |
| add_env (Abs (_, _, t)) = add_env t |
|
71 |
| add_env (t1 $ t2) = add_env t1 #> add_env t2 |
|
72 |
| add_env _ = I; |
|
8895 | 73 |
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
|
74 |
|
9d386e6c02b7
added raw_term_sorts and changed typ_of_term accordingly (part of fix
wenzelm
parents:
347
diff
changeset
|
75 |
|
2584 | 76 |
(* typ_of_term *) |
0 | 77 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
78 |
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
|
79 |
let |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
80 |
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
|
81 |
|
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
82 |
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
|
83 |
| typ_of (Var (xi, _)) = TVar (xi, get_sort xi) |
32784 | 84 |
| typ_of (Const ("_tfree",_) $ (t as Free _)) = typ_of t |
85 |
| typ_of (Const ("_tvar",_) $ (t as Var _)) = typ_of t |
|
12317 | 86 |
| typ_of (Const ("_ofsort", _) $ Free (x, _) $ _) = TFree (x, get_sort (x, ~1)) |
16614 | 87 |
| typ_of (Const ("_ofsort", _) $ (Const ("_tfree",_) $ Free (x, _)) $ _) = |
88 |
TFree (x, get_sort (x, ~1)) |
|
12317 | 89 |
| typ_of (Const ("_ofsort", _) $ Var (xi, _) $ _) = TVar (xi, get_sort xi) |
16614 | 90 |
| typ_of (Const ("_ofsort", _) $ (Const ("_tvar",_) $ Var (xi, _)) $ _) = |
91 |
TVar (xi, get_sort xi) |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
92 |
| 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
|
93 |
| typ_of t = |
0 | 94 |
let |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
95 |
val (head, args) = Term.strip_comb t; |
0 | 96 |
val a = |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
97 |
(case head of |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
98 |
Const (c, _) => (Lexicon.unmark_type c handle Fail _ => err ()) |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
99 |
| _ => err ()); |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
100 |
in Type (a, map typ_of args) end; |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
101 |
in typ_of tm end; |
0 | 102 |
|
103 |
||
42050
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
104 |
(* positions *) |
22704 | 105 |
|
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
106 |
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
|
107 |
| decode_position _ = NONE; |
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
108 |
|
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
109 |
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
|
110 |
|
42050
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
111 |
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
|
112 |
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
|
113 |
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
|
114 |
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
|
115 |
| 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
|
116 |
| 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
|
117 |
| 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
|
118 |
|
42052
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
| 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
|
124 |
| strip_positions_ast ast = ast; |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
125 |
|
42050
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
126 |
|
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
127 |
(* 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
|
128 |
|
42133 | 129 |
fun markup_bound def id = |
42170 | 130 |
[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
|
131 |
|
42134 | 132 |
type term_context = |
133 |
{get_sort: (indexname * sort) list -> indexname -> sort, |
|
134 |
get_const: string -> bool * string, |
|
42135 | 135 |
get_free: string -> string option, |
42170 | 136 |
markup_const: string -> Markup.T list, |
137 |
markup_free: string -> Markup.T list, |
|
138 |
markup_var: indexname -> Markup.T list}; |
|
42134 | 139 |
|
42223
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
140 |
fun decode_term _ (result as (_: Position.reports, Exn.Exn _)) = result |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
141 |
| decode_term (term_context: term_context) (reports0, Exn.Result tm) = |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
142 |
let |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
143 |
val {get_sort, get_const, get_free, markup_const, markup_free, markup_var} = term_context; |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
144 |
val decodeT = typ_of_term (get_sort (term_sorts tm)); |
22704 | 145 |
|
42223
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
146 |
val reports = Unsynchronized.ref reports0; |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
147 |
fun report ps = Position.reports reports ps; |
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
148 |
|
42223
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
149 |
fun decode ps qs bs (Const ("_constrain", _) $ t $ typ) = |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
150 |
(case decode_position typ of |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
151 |
SOME p => decode (p :: ps) qs bs t |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
152 |
| NONE => Type.constraint (decodeT typ) (decode ps qs bs t)) |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
153 |
| decode ps qs bs (Const ("_constrainAbs", _) $ t $ typ) = |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
154 |
(case decode_position typ of |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
155 |
SOME q => decode ps (q :: qs) bs t |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
156 |
| NONE => Type.constraint (decodeT typ --> dummyT) (decode ps qs bs t)) |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
157 |
| 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
|
158 |
let |
42223
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
159 |
val id = serial_string (); |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
160 |
val _ = report qs (markup_bound true) id; |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
161 |
in Abs (x, T, decode [] [] (id :: bs) t) end |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
162 |
| decode _ _ bs (t $ u) = decode [] [] bs t $ decode [] [] bs u |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
163 |
| decode ps _ _ (Const (a, T)) = |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
164 |
(case try Lexicon.unmark_fixed a of |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
165 |
SOME x => (report ps markup_free x; Free (x, T)) |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
166 |
| NONE => |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
167 |
let |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
168 |
val c = |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
169 |
(case try Lexicon.unmark_const a of |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
170 |
SOME c => c |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
171 |
| NONE => snd (get_const a)); |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
172 |
val _ = report ps markup_const c; |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
173 |
in Const (c, T) end) |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
174 |
| decode ps _ _ (Free (a, T)) = |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
175 |
(case (get_free a, get_const a) of |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
176 |
(SOME x, _) => (report ps markup_free x; Free (x, T)) |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
177 |
| (_, (true, c)) => (report ps markup_const c; Const (c, T)) |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
178 |
| (_, (false, c)) => |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
179 |
if Long_Name.is_qualified c |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
180 |
then (report ps markup_const c; Const (c, T)) |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
181 |
else (report ps markup_free c; Free (c, T))) |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
182 |
| decode ps _ _ (Var (xi, T)) = (report ps markup_var xi; Var (xi, T)) |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
183 |
| decode ps _ bs (t as Bound i) = |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
184 |
(case try (nth bs) i of |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
185 |
SOME id => (report ps (markup_bound false) id; t) |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
186 |
| NONE => t); |
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
187 |
|
42223
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
188 |
val tm' = Exn.interruptible_capture (fn () => decode [] [] [] tm) (); |
098c86e53153
more precise propagation of reports/results through some inner syntax layers;
wenzelm
parents:
42204
diff
changeset
|
189 |
in (! reports, tm') end; |
22704 | 190 |
|
191 |
||
0 | 192 |
|
2584 | 193 |
(** output utils **) |
194 |
||
2699 | 195 |
(* term_of_sort *) |
2584 | 196 |
|
197 |
fun term_of_sort S = |
|
198 |
let |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
199 |
val class = Lexicon.const o Lexicon.mark_class; |
2584 | 200 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
201 |
fun classes [c] = class c |
5690 | 202 |
| classes (c :: cs) = Lexicon.const "_classes" $ class c $ classes cs; |
2584 | 203 |
in |
204 |
(case S of |
|
5690 | 205 |
[] => Lexicon.const "_topsort" |
2584 | 206 |
| [c] => class c |
5690 | 207 |
| cs => Lexicon.const "_sort" $ classes cs) |
2584 | 208 |
end; |
209 |
||
210 |
||
211 |
(* term_of_typ *) |
|
0 | 212 |
|
213 |
fun term_of_typ show_sorts ty = |
|
214 |
let |
|
2584 | 215 |
fun of_sort t S = |
5690 | 216 |
if show_sorts then Lexicon.const "_ofsort" $ t $ term_of_sort S |
2584 | 217 |
else t; |
0 | 218 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
219 |
fun term_of (Type (a, Ts)) = |
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
220 |
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
|
221 |
| 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
|
222 |
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
|
223 |
else of_sort (Lexicon.const "_tfree" $ Lexicon.free x) S |
5690 | 224 |
| term_of (TVar (xi, S)) = of_sort (Lexicon.const "_tvar" $ Lexicon.var xi) S; |
8895 | 225 |
in term_of ty end; |
0 | 226 |
|
227 |
||
228 |
||
229 |
(** the type syntax **) |
|
230 |
||
10572 | 231 |
(* print mode *) |
232 |
||
233 |
val bracketsN = "brackets"; |
|
234 |
val no_bracketsN = "no_brackets"; |
|
235 |
||
236 |
fun no_brackets () = |
|
24613 | 237 |
find_first (fn mode => mode = bracketsN orelse mode = no_bracketsN) |
238 |
(print_mode_value ()) = SOME no_bracketsN; |
|
11312 | 239 |
|
240 |
val type_bracketsN = "type_brackets"; |
|
241 |
val no_type_bracketsN = "no_type_brackets"; |
|
242 |
||
243 |
fun no_type_brackets () = |
|
24613 | 244 |
find_first (fn mode => mode = type_bracketsN orelse mode = no_type_bracketsN) |
245 |
(print_mode_value ()) <> SOME type_bracketsN; |
|
10572 | 246 |
|
247 |
||
18 | 248 |
(* parse ast translations *) |
0 | 249 |
|
42204 | 250 |
fun tapp_ast_tr [ty, c] = Ast.Appl [c, ty] |
251 |
| tapp_ast_tr asts = raise Ast.AST ("tapp_ast_tr", asts); |
|
347
cd41a57221d0
changed translation of type applications according to new grammar;
wenzelm
parents:
330
diff
changeset
|
252 |
|
42204 | 253 |
fun tappl_ast_tr [ty, tys, c] = Ast.mk_appl c (ty :: Ast.unfold_ast "_types" tys) |
254 |
| tappl_ast_tr asts = raise Ast.AST ("tappl_ast_tr", asts); |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
255 |
|
42204 | 256 |
fun bracket_ast_tr [dom, cod] = Ast.fold_ast_p "\\<^type>fun" (Ast.unfold_ast "_types" dom, cod) |
257 |
| bracket_ast_tr asts = raise Ast.AST ("bracket_ast_tr", asts); |
|
0 | 258 |
|
259 |
||
18 | 260 |
(* print ast translations *) |
0 | 261 |
|
5690 | 262 |
fun tappl_ast_tr' (f, []) = raise Ast.AST ("tappl_ast_tr'", [f]) |
263 |
| 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
|
264 |
| tappl_ast_tr' (f, ty :: tys) = |
5690 | 265 |
Ast.Appl [Ast.Constant "_tappl", ty, Ast.fold_ast "_types" tys, f]; |
0 | 266 |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
267 |
fun fun_ast_tr' (*"\\<^type>fun"*) asts = |
16614 | 268 |
if no_brackets () orelse no_type_brackets () then raise Match |
10572 | 269 |
else |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
270 |
(case Ast.unfold_ast_p "\\<^type>fun" (Ast.Appl (Ast.Constant "\\<^type>fun" :: asts)) of |
10572 | 271 |
(dom as _ :: _ :: _, cod) |
272 |
=> Ast.Appl [Ast.Constant "_bracket", Ast.fold_ast "_types" dom, cod] |
|
273 |
| _ => raise Match); |
|
0 | 274 |
|
275 |
||
276 |
(* type_ext *) |
|
277 |
||
42204 | 278 |
fun typ c = Type (c, []); |
279 |
||
280 |
val class_nameT = typ "class_name"; |
|
281 |
val type_nameT = typ "type_name"; |
|
282 |
||
283 |
val sortT = typ "sort"; |
|
284 |
val classesT = typ "classes"; |
|
285 |
val typesT = typ "types"; |
|
0 | 286 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36502
diff
changeset
|
287 |
local open Lexicon Syn_Ext in |
5690 | 288 |
|
35668 | 289 |
val type_ext = syn_ext' false (K false) |
347
cd41a57221d0
changed translation of type applications according to new grammar;
wenzelm
parents:
330
diff
changeset
|
290 |
[Mfix ("_", tidT --> typeT, "", [], max_pri), |
239 | 291 |
Mfix ("_", tvarT --> typeT, "", [], max_pri), |
42204 | 292 |
Mfix ("_", type_nameT --> typeT, "", [], max_pri), |
293 |
Mfix ("_", idT --> type_nameT, "_type_name", [], max_pri), |
|
294 |
Mfix ("_", longidT --> type_nameT, "_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
|
295 |
Mfix ("_::_", [tidT, sortT] ---> typeT, "_ofsort", [max_pri, 0], max_pri), |
239 | 296 |
Mfix ("_::_", [tvarT, sortT] ---> typeT, "_ofsort", [max_pri, 0], max_pri), |
14838 | 297 |
Mfix ("'_()::_", sortT --> typeT, "_dummy_ofsort", [0], max_pri), |
42204 | 298 |
Mfix ("_", class_nameT --> sortT, "", [], max_pri), |
299 |
Mfix ("_", idT --> class_nameT, "_class_name", [], max_pri), |
|
300 |
Mfix ("_", longidT --> class_nameT, "_class_name", [], max_pri), |
|
2584 | 301 |
Mfix ("{}", sortT, "_topsort", [], max_pri), |
239 | 302 |
Mfix ("{_}", classesT --> sortT, "_sort", [], max_pri), |
42204 | 303 |
Mfix ("_", class_nameT --> classesT, "", [], max_pri), |
304 |
Mfix ("_,_", [class_nameT, classesT] ---> classesT, "_classes", [], max_pri), |
|
305 |
Mfix ("_ _", [typeT, type_nameT] ---> typeT, "_tapp", [max_pri, 0], max_pri), |
|
306 |
Mfix ("((1'(_,/ _')) _)", [typeT, typesT, type_nameT] ---> typeT, "_tappl", [], max_pri), |
|
239 | 307 |
Mfix ("_", typeT --> typesT, "", [], max_pri), |
308 |
Mfix ("_,/ _", [typeT, typesT] ---> typesT, "_types", [], max_pri), |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
309 |
Mfix ("(_/ => _)", [typeT, typeT] ---> typeT, "\\<^type>fun", [1, 0], 0), |
624 | 310 |
Mfix ("([_]/ => _)", [typesT, typeT] ---> typeT, "_bracket", [0, 0], 0), |
2678 | 311 |
Mfix ("'(_')", typeT --> typeT, "", [0], max_pri), |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
312 |
Mfix ("'_", typeT, "\\<^type>dummy", [], max_pri)] |
35433
73cc288b4f83
"_type_prop" is syntax const -- recovered printing of OFCLASS;
wenzelm
parents:
35429
diff
changeset
|
313 |
["_type_prop"] |
42204 | 314 |
(map Syn_Ext.mk_trfun |
315 |
[("_tapp", K tapp_ast_tr), ("_tappl", K tappl_ast_tr), ("_bracket", K bracket_ast_tr)], |
|
316 |
[], [], 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
|
317 |
[] |
239 | 318 |
([], []); |
0 | 319 |
|
320 |
end; |
|
5690 | 321 |
|
322 |
end; |