author | paulson |
Thu, 05 Sep 1996 10:30:42 +0200 | |
changeset 1952 | 4acc84e5831f |
parent 1507 | f600215b6ea7 |
child 2199 | bcb360f80dac |
permissions | -rw-r--r-- |
384 | 1 |
(* Title: Pure/Syntax/mixfix.ML |
2 |
ID: $Id$ |
|
551 | 3 |
Author: Tobias Nipkow and Markus Wenzel, TU Muenchen |
384 | 4 |
|
5 |
Mixfix declarations, infixes, binders. Part of the Pure syntax. |
|
6 |
*) |
|
7 |
||
8 |
signature MIXFIX0 = |
|
1507 | 9 |
sig |
384 | 10 |
datatype mixfix = |
11 |
NoSyn | |
|
12 |
Mixfix of string * int list * int | |
|
13 |
Delimfix of string | |
|
14 |
Infixl of int | |
|
15 |
Infixr of int | |
|
865 | 16 |
Binder of string * int * int |
384 | 17 |
val max_pri: int |
1507 | 18 |
end; |
384 | 19 |
|
20 |
signature MIXFIX1 = |
|
1507 | 21 |
sig |
384 | 22 |
include MIXFIX0 |
23 |
val type_name: string -> mixfix -> string |
|
24 |
val const_name: string -> mixfix -> string |
|
25 |
val pure_types: (string * int * mixfix) list |
|
26 |
val pure_syntax: (string * string * mixfix) list |
|
1181 | 27 |
val pure_appl_syntax: (string * string * mixfix) list |
28 |
val pure_applC_syntax: (string * string * mixfix) list |
|
1507 | 29 |
end; |
384 | 30 |
|
31 |
signature MIXFIX = |
|
1507 | 32 |
sig |
384 | 33 |
include MIXFIX1 |
1507 | 34 |
val syn_ext_types: string list -> (string * int * mixfix) list -> SynExt.syn_ext |
35 |
val syn_ext_consts: string list -> (string * typ * mixfix) list -> SynExt.syn_ext |
|
36 |
end; |
|
384 | 37 |
|
1507 | 38 |
structure Mixfix : MIXFIX = |
384 | 39 |
struct |
40 |
||
1507 | 41 |
open Lexicon SynExt Ast SynTrans; |
384 | 42 |
|
43 |
(** mixfix declarations **) |
|
44 |
||
45 |
datatype mixfix = |
|
46 |
NoSyn | |
|
47 |
Mixfix of string * int list * int | |
|
48 |
Delimfix of string | |
|
49 |
Infixl of int | |
|
50 |
Infixr of int | |
|
887 | 51 |
Binder of string * int * int; |
384 | 52 |
|
53 |
||
54 |
(* type / const names *) |
|
55 |
||
56 |
fun strip ("'" :: c :: cs) = c :: strip cs |
|
57 |
| strip ["'"] = [] |
|
58 |
| strip (c :: cs) = c :: strip cs |
|
59 |
| strip [] = []; |
|
60 |
||
61 |
val strip_esc = implode o strip o explode; |
|
62 |
||
63 |
||
64 |
fun type_name t (Infixl _) = strip_esc t |
|
65 |
| type_name t (Infixr _) = strip_esc t |
|
66 |
| type_name t _ = t; |
|
67 |
||
68 |
fun infix_name c = "op " ^ strip_esc c; |
|
69 |
||
70 |
fun const_name c (Infixl _) = infix_name c |
|
71 |
| const_name c (Infixr _) = infix_name c |
|
72 |
| const_name c _ = c; |
|
73 |
||
74 |
||
75 |
(* syn_ext_types *) |
|
76 |
||
764
b60e77395d1a
changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents:
639
diff
changeset
|
77 |
fun syn_ext_types logtypes type_decls = |
384 | 78 |
let |
79 |
fun name_of (t, _, mx) = type_name t mx; |
|
80 |
||
81 |
fun mk_infix t p1 p2 p3 = |
|
82 |
Mfix ("(_ " ^ t ^ "/ _)", [typeT, typeT] ---> typeT, |
|
83 |
strip_esc t, [p1, p2], p3); |
|
84 |
||
85 |
fun mfix_of (_, _, NoSyn) = None |
|
86 |
| mfix_of (t, 2, Infixl p) = Some (mk_infix t p (p + 1) p) |
|
87 |
| mfix_of (t, 2, Infixr p) = Some (mk_infix t (p + 1) p p) |
|
88 |
| mfix_of decl = error ("Bad mixfix declaration for type " ^ |
|
89 |
quote (name_of decl)); |
|
90 |
||
91 |
val mfix = mapfilter mfix_of type_decls; |
|
92 |
val xconsts = map name_of type_decls; |
|
93 |
in |
|
764
b60e77395d1a
changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents:
639
diff
changeset
|
94 |
syn_ext logtypes mfix xconsts ([], [], [], []) ([], []) |
384 | 95 |
end; |
96 |
||
97 |
||
98 |
(* syn_ext_consts *) |
|
99 |
||
764
b60e77395d1a
changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents:
639
diff
changeset
|
100 |
fun syn_ext_consts logtypes const_decls = |
384 | 101 |
let |
102 |
fun name_of (c, _, mx) = const_name c mx; |
|
103 |
||
104 |
fun mk_infix sy ty c p1 p2 p3 = |
|
105 |
[Mfix ("(_ " ^ sy ^ "/ _)", ty, c, [p1, p2], p3), |
|
106 |
Mfix ("op " ^ sy, ty, c, [], max_pri)]; |
|
107 |
||
108 |
fun binder_typ _ (Type ("fun", [Type ("fun", [_, ty2]), ty3])) = |
|
109 |
[Type ("idts", []), ty2] ---> ty3 |
|
110 |
| binder_typ c _ = error ("Bad type of binder " ^ quote c); |
|
111 |
||
112 |
fun mfix_of (_, _, NoSyn) = [] |
|
113 |
| mfix_of (c, ty, Mixfix (sy, ps, p)) = [Mfix (sy, ty, c, ps, p)] |
|
114 |
| mfix_of (c, ty, Delimfix sy) = [Mfix (sy, ty, c, [], max_pri)] |
|
115 |
| mfix_of (sy, ty, Infixl p) = mk_infix sy ty (infix_name sy) p (p + 1) p |
|
116 |
| mfix_of (sy, ty, Infixr p) = mk_infix sy ty (infix_name sy) (p + 1) p p |
|
887 | 117 |
| mfix_of (c, ty, Binder (sy, p, q)) = |
118 |
[Mfix ("(3" ^ sy ^ "_./ _)", binder_typ c ty, sy, [0, p], q)]; |
|
384 | 119 |
|
865 | 120 |
fun binder (c, _, Binder (sy, _, _)) = Some (sy, c) |
384 | 121 |
| binder _ = None; |
122 |
||
123 |
val mfix = flat (map mfix_of const_decls); |
|
124 |
val xconsts = map name_of const_decls; |
|
125 |
val binders = mapfilter binder const_decls; |
|
126 |
val binder_trs = map mk_binder_tr binders; |
|
127 |
val binder_trs' = map (mk_binder_tr' o swap) binders; |
|
128 |
in |
|
764
b60e77395d1a
changed Pure's grammar and the way types are converted to nonterminals
clasohm
parents:
639
diff
changeset
|
129 |
syn_ext logtypes mfix xconsts ([], binder_trs, binder_trs', []) ([], []) |
384 | 130 |
end; |
131 |
||
132 |
||
133 |
||
134 |
(** Pure syntax **) |
|
135 |
||
136 |
val pure_types = |
|
137 |
map (fn t => (t, 0, NoSyn)) |
|
1178 | 138 |
(terminals @ [logic, "type", "types", "sort", "classes", args, cargs, |
1067
00ed040f66e1
I have modified the grammar for idts (sequences of identifiers with optional
nipkow
parents:
922
diff
changeset
|
139 |
"pttrn", "idt", "idts", "aprop", "asms", any, sprop]); |
384 | 140 |
|
141 |
val pure_syntax = |
|
781 | 142 |
[("_lambda", "[idts, 'a] => logic", Mixfix ("(3%_./ _)", [], 0)), |
921 | 143 |
("_abs", "'a", NoSyn), |
384 | 144 |
("", "'a => " ^ args, Delimfix "_"), |
145 |
("_args", "['a, " ^ args ^ "] => " ^ args, Delimfix "_,/ _"), |
|
146 |
("", "id => idt", Delimfix "_"), |
|
147 |
("_idtyp", "[id, type] => idt", Mixfix ("_::_", [], 0)), |
|
148 |
("", "idt => idt", Delimfix "'(_')"), |
|
1067
00ed040f66e1
I have modified the grammar for idts (sequences of identifiers with optional
nipkow
parents:
922
diff
changeset
|
149 |
("", "idt => pttrn", Delimfix "_"), |
00ed040f66e1
I have modified the grammar for idts (sequences of identifiers with optional
nipkow
parents:
922
diff
changeset
|
150 |
("", "pttrn => idts", Delimfix "_"), |
00ed040f66e1
I have modified the grammar for idts (sequences of identifiers with optional
nipkow
parents:
922
diff
changeset
|
151 |
("_idts", "[pttrn, idts] => idts", Mixfix ("_/ _", [1, 0], 0)), |
384 | 152 |
("", "id => aprop", Delimfix "_"), |
153 |
("", "var => aprop", Delimfix "_"), |
|
154 |
("_aprop", "aprop => prop", Delimfix "PROP _"), |
|
155 |
("", "prop => asms", Delimfix "_"), |
|
156 |
("_asms", "[prop, asms] => asms", Delimfix "_;/ _"), |
|
1952
4acc84e5831f
Pretty-printing change to emphasize the scope of assumptions
paulson
parents:
1507
diff
changeset
|
157 |
("_bigimpl", "[asms, prop] => prop", Mixfix ("((3[| _ |])/ ==> _)", [0, 1], 1)), |
842 | 158 |
("_ofclass", "[type, logic] => prop", Delimfix "(1OFCLASS/(1'(_,/ _')))"), |
384 | 159 |
("_K", "'a", NoSyn), |
624 | 160 |
("", "id => logic", Delimfix "_"), |
922
196ca0973a6d
added CPure (curried functions) and ProtoPure (ancestor of Pure and CPure)
clasohm
parents:
921
diff
changeset
|
161 |
("", "var => logic", Delimfix "_")] |
384 | 162 |
|
1181 | 163 |
val pure_appl_syntax = |
164 |
[("_appl", "[('b => 'a), args] => logic", Mixfix ("(1_/(1'(_')))", |
|
165 |
[max_pri, 0], max_pri)), |
|
166 |
("_appl", "[('b => 'a), args] => aprop", Mixfix ("(1_/(1'(_')))", |
|
167 |
[max_pri, 0], max_pri))]; |
|
168 |
||
169 |
val pure_applC_syntax = |
|
170 |
[("", "'a => cargs", Delimfix "_"), |
|
171 |
("_cargs", "['a, cargs] => cargs", Mixfix ("_/ _", |
|
172 |
[max_pri, max_pri], |
|
173 |
max_pri)), |
|
174 |
("_applC", "[('b => 'a), cargs] => logic", Mixfix ("(1_/ _)", |
|
175 |
[max_pri, max_pri], |
|
176 |
max_pri-1)), |
|
177 |
("_applC", "[('b => 'a), cargs] => aprop", Mixfix ("(1_/ _)", |
|
178 |
[max_pri, max_pri], |
|
179 |
max_pri-1))]; |
|
384 | 180 |
end; |