author | wenzelm |
Wed, 06 Apr 2011 21:55:41 +0200 | |
changeset 42262 | 4821a2a91548 |
parent 42245 | 29e3967550d5 |
child 42263 | 49b1b8d0782f |
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 |
42242
39261908e12f
moved decode/parse operations to standard_syntax.ML;
wenzelm
parents:
42223
diff
changeset
|
9 |
val decode_position_term: term -> Position.T option |
42053
006095137a81
update_name_tr: more precise handling of explicit constraints, including positions;
wenzelm
parents:
42052
diff
changeset
|
10 |
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
|
11 |
val strip_positions: term -> term |
42052
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
12 |
val strip_positions_ast: Ast.ast -> Ast.ast |
2584 | 13 |
end; |
0 | 14 |
|
15 |
signature TYPE_EXT = |
|
2584 | 16 |
sig |
0 | 17 |
include TYPE_EXT0 |
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36502
diff
changeset
|
18 |
val type_ext: Syn_Ext.syn_ext |
2584 | 19 |
end; |
0 | 20 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36502
diff
changeset
|
21 |
structure Type_Ext: TYPE_EXT = |
0 | 22 |
struct |
2584 | 23 |
|
24 |
(** input utils **) |
|
0 | 25 |
|
42050
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
26 |
(* positions *) |
22704 | 27 |
|
42242
39261908e12f
moved decode/parse operations to standard_syntax.ML;
wenzelm
parents:
42223
diff
changeset
|
28 |
fun decode_position_term (Free (x, _)) = Lexicon.decode_position x |
39261908e12f
moved decode/parse operations to standard_syntax.ML;
wenzelm
parents:
42223
diff
changeset
|
29 |
| decode_position_term _ = NONE; |
42131
1d9710ff7209
decode_term/disambig: report resolved term variables for the unique (!) result;
wenzelm
parents:
42053
diff
changeset
|
30 |
|
42242
39261908e12f
moved decode/parse operations to standard_syntax.ML;
wenzelm
parents:
42223
diff
changeset
|
31 |
val is_position = is_some o decode_position_term; |
42048
afd11ca8e018
support for encoded positions (for id_position, longid_position) as pseudo type-constraints -- still inactive;
wenzelm
parents:
39288
diff
changeset
|
32 |
|
42050
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
33 |
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
|
34 |
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
|
35 |
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
|
36 |
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
|
37 |
| 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
|
38 |
| 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
|
39 |
| 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
|
40 |
|
42052
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
41 |
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
|
42 |
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
|
43 |
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
|
44 |
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
|
45 |
| 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
|
46 |
| strip_positions_ast ast = ast; |
34f1d2d81284
statespace syntax: strip positions -- type constraints are unexpected here;
wenzelm
parents:
42050
diff
changeset
|
47 |
|
42050
5a505dfec04e
datatype case_tr: strip positions -- type constraints are unexpected despite the "any" category in "case_syn";
wenzelm
parents:
42048
diff
changeset
|
48 |
|
0 | 49 |
|
50 |
(** the type syntax **) |
|
51 |
||
42204 | 52 |
fun typ c = Type (c, []); |
53 |
||
54 |
val class_nameT = typ "class_name"; |
|
55 |
val type_nameT = typ "type_name"; |
|
56 |
||
57 |
val sortT = typ "sort"; |
|
58 |
val classesT = typ "classes"; |
|
59 |
val typesT = typ "types"; |
|
0 | 60 |
|
37216
3165bc303f66
modernized some structure names, keeping a few legacy aliases;
wenzelm
parents:
36502
diff
changeset
|
61 |
local open Lexicon Syn_Ext in |
5690 | 62 |
|
35668 | 63 |
val type_ext = syn_ext' false (K false) |
347
cd41a57221d0
changed translation of type applications according to new grammar;
wenzelm
parents:
330
diff
changeset
|
64 |
[Mfix ("_", tidT --> typeT, "", [], max_pri), |
239 | 65 |
Mfix ("_", tvarT --> typeT, "", [], max_pri), |
42204 | 66 |
Mfix ("_", type_nameT --> typeT, "", [], max_pri), |
67 |
Mfix ("_", idT --> type_nameT, "_type_name", [], max_pri), |
|
68 |
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
|
69 |
Mfix ("_::_", [tidT, sortT] ---> typeT, "_ofsort", [max_pri, 0], max_pri), |
239 | 70 |
Mfix ("_::_", [tvarT, sortT] ---> typeT, "_ofsort", [max_pri, 0], max_pri), |
14838 | 71 |
Mfix ("'_()::_", sortT --> typeT, "_dummy_ofsort", [0], max_pri), |
42204 | 72 |
Mfix ("_", class_nameT --> sortT, "", [], max_pri), |
73 |
Mfix ("_", idT --> class_nameT, "_class_name", [], max_pri), |
|
74 |
Mfix ("_", longidT --> class_nameT, "_class_name", [], max_pri), |
|
2584 | 75 |
Mfix ("{}", sortT, "_topsort", [], max_pri), |
239 | 76 |
Mfix ("{_}", classesT --> sortT, "_sort", [], max_pri), |
42204 | 77 |
Mfix ("_", class_nameT --> classesT, "", [], max_pri), |
78 |
Mfix ("_,_", [class_nameT, classesT] ---> classesT, "_classes", [], max_pri), |
|
79 |
Mfix ("_ _", [typeT, type_nameT] ---> typeT, "_tapp", [max_pri, 0], max_pri), |
|
80 |
Mfix ("((1'(_,/ _')) _)", [typeT, typesT, type_nameT] ---> typeT, "_tappl", [], max_pri), |
|
239 | 81 |
Mfix ("_", typeT --> typesT, "", [], max_pri), |
82 |
Mfix ("_,/ _", [typeT, typesT] ---> typesT, "_types", [], max_pri), |
|
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
83 |
Mfix ("(_/ => _)", [typeT, typeT] ---> typeT, "\\<^type>fun", [1, 0], 0), |
624 | 84 |
Mfix ("([_]/ => _)", [typesT, typeT] ---> typeT, "_bracket", [0, 0], 0), |
2678 | 85 |
Mfix ("'(_')", typeT --> typeT, "", [0], max_pri), |
35429
afa8cf9e63d8
authentic syntax for classes and type constructors;
wenzelm
parents:
35262
diff
changeset
|
86 |
Mfix ("'_", typeT, "\\<^type>dummy", [], max_pri)] |
35433
73cc288b4f83
"_type_prop" is syntax const -- recovered printing of OFCLASS;
wenzelm
parents:
35429
diff
changeset
|
87 |
["_type_prop"] |
42262 | 88 |
([], [], [], []) |
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
|
89 |
[] |
239 | 90 |
([], []); |
0 | 91 |
|
92 |
end; |
|
5690 | 93 |
|
94 |
end; |