author | wenzelm |
Sat, 09 Dec 2006 18:05:52 +0100 | |
changeset 21731 | 360fa2caaf2f |
parent 21702 | 9300bec44e6a |
child 21772 | 7c7ade4f537b |
permissions | -rw-r--r-- |
18 | 1 |
(* Title: Pure/Syntax/syntax.ML |
0 | 2 |
ID: $Id$ |
3 |
Author: Tobias Nipkow and Markus Wenzel, TU Muenchen |
|
18 | 4 |
|
5 |
Root of Isabelle's syntax module. |
|
0 | 6 |
*) |
7 |
||
260 | 8 |
signature BASIC_SYNTAX = |
2383 | 9 |
sig |
260 | 10 |
include AST0 |
556 | 11 |
include SYN_TRANS0 |
12 |
include MIXFIX0 |
|
260 | 13 |
include PRINTER0 |
2383 | 14 |
end; |
260 | 15 |
|
0 | 16 |
signature SYNTAX = |
2383 | 17 |
sig |
260 | 18 |
include AST1 |
0 | 19 |
include LEXICON0 |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
20 |
include SYN_EXT0 |
0 | 21 |
include TYPE_EXT0 |
556 | 22 |
include SYN_TRANS1 |
23 |
include MIXFIX1 |
|
0 | 24 |
include PRINTER0 |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
25 |
val extend_trtab: string -> (string * ('a * stamp)) list -> |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
26 |
('a * stamp) Symtab.table -> ('a * stamp) Symtab.table |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
27 |
val merge_trtabs: string -> ('a * stamp) Symtab.table -> ('a * stamp) Symtab.table -> |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
28 |
('a * stamp) Symtab.table |
14648
0e67b385a6df
tuned interfaces to accomodate advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
29 |
val merge_tr'tabs: ('a * stamp) list Symtab.table -> ('a * stamp) list Symtab.table |
0e67b385a6df
tuned interfaces to accomodate advanced translation functions;
wenzelm
parents:
14598
diff
changeset
|
30 |
-> ('a * stamp) list Symtab.table |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
31 |
val extend_tr'tab: (string * ('a * stamp)) list -> |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
32 |
('a * stamp) list Symtab.table -> ('a * stamp) list Symtab.table |
1158 | 33 |
datatype 'a trrule = |
3526 | 34 |
ParseRule of 'a * 'a | |
35 |
PrintRule of 'a * 'a | |
|
36 |
ParsePrintRule of 'a * 'a |
|
556 | 37 |
type syntax |
17079 | 38 |
val eq_syntax: syntax * syntax -> bool |
14687 | 39 |
val is_keyword: syntax -> string -> bool |
20784 | 40 |
type mode |
41 |
val default_mode: mode |
|
21702 | 42 |
val input_mode: mode |
21731 | 43 |
val internal_mode: mode |
12073
b4401452928e
extend_XXX: sane argument order ... -> syntax -> syntax;
wenzelm
parents:
11546
diff
changeset
|
44 |
val extend_type_gram: (string * int * mixfix) list -> syntax -> syntax |
14904
7d8dc92fcb7f
removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents:
14798
diff
changeset
|
45 |
val extend_const_gram: (string -> bool) -> |
20784 | 46 |
mode -> (string * typ * mixfix) list -> syntax -> syntax |
12073
b4401452928e
extend_XXX: sane argument order ... -> syntax -> syntax;
wenzelm
parents:
11546
diff
changeset
|
47 |
val extend_consts: string list -> syntax -> syntax |
b4401452928e
extend_XXX: sane argument order ... -> syntax -> syntax;
wenzelm
parents:
11546
diff
changeset
|
48 |
val extend_trfuns: |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
49 |
(string * ((ast list -> ast) * stamp)) list * |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
50 |
(string * ((term list -> term) * stamp)) list * |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
51 |
(string * ((bool -> typ -> term list -> term) * stamp)) list * |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
52 |
(string * ((ast list -> ast) * stamp)) list -> syntax -> syntax |
16613
76e57e08dcb5
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15833
diff
changeset
|
53 |
val extend_advanced_trfuns: |
18857 | 54 |
(string * ((Context.generic -> ast list -> ast) * stamp)) list * |
55 |
(string * ((Context.generic -> term list -> term) * stamp)) list * |
|
56 |
(string * ((Context.generic -> bool -> typ -> term list -> term) * stamp)) list * |
|
57 |
(string * ((Context.generic -> ast list -> ast) * stamp)) list -> syntax -> syntax |
|
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
58 |
val extend_tokentrfuns: (string * string * (string -> string * real)) list -> syntax -> syntax |
19262 | 59 |
val remove_const_gram: (string -> bool) -> |
20784 | 60 |
mode -> (string * typ * mixfix) list -> syntax -> syntax |
18857 | 61 |
val extend_trrules: Context.generic -> (string -> bool) -> syntax -> |
14904
7d8dc92fcb7f
removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents:
14798
diff
changeset
|
62 |
(string * string) trrule list -> syntax -> syntax |
19262 | 63 |
val remove_trrules: Context.generic -> (string -> bool) -> syntax -> |
64 |
(string * string) trrule list -> syntax -> syntax |
|
65 |
val extend_trrules_i: ast trrule list -> syntax -> syntax |
|
66 |
val remove_trrules_i: ast trrule list -> syntax -> syntax |
|
4618 | 67 |
val map_trrule: ('a -> 'b) -> 'a trrule -> 'b trrule |
556 | 68 |
val merge_syntaxes: syntax -> syntax -> syntax |
18720 | 69 |
val basic_syn: syntax |
70 |
val basic_nonterms: string list |
|
71 |
val appl_syntax: (string * string * mixfix) list |
|
72 |
val applC_syntax: (string * string * mixfix) list |
|
556 | 73 |
val print_gram: syntax -> unit |
74 |
val print_trans: syntax -> unit |
|
75 |
val print_syntax: syntax -> unit |
|
18857 | 76 |
val read: Context.generic -> (string -> bool) -> syntax -> typ -> string -> term list |
77 |
val read_typ: Context.generic -> syntax -> ((indexname * sort) list -> indexname -> sort) -> |
|
16613
76e57e08dcb5
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15833
diff
changeset
|
78 |
(sort -> sort) -> string -> typ |
18857 | 79 |
val read_sort: Context.generic -> syntax -> string -> sort |
19375
8198a4ffff24
pretty_term: late externing of consts (support authentic syntax);
wenzelm
parents:
19300
diff
changeset
|
80 |
val pretty_term: (string -> xstring) -> Context.generic -> syntax -> bool -> term -> Pretty.T |
18857 | 81 |
val pretty_typ: Context.generic -> syntax -> typ -> Pretty.T |
82 |
val pretty_sort: Context.generic -> syntax -> sort -> Pretty.T |
|
882
b118d1ea0dfd
moved ambiguity_level from sign.ML to Syntax/syntax.ML
clasohm
parents:
865
diff
changeset
|
83 |
val ambiguity_level: int ref |
14177
06b19a7e675a
Added 'ambiguity_is_error' flag, which, if set, makes the parser fail,
skalberg
parents:
12785
diff
changeset
|
84 |
val ambiguity_is_error: bool ref |
2383 | 85 |
end; |
0 | 86 |
|
12094 | 87 |
structure Syntax: SYNTAX = |
0 | 88 |
struct |
89 |
||
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
90 |
(** tables of translation functions **) |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
91 |
|
5692 | 92 |
(* parse (ast) translations *) |
93 |
||
17412 | 94 |
fun lookup_tr tab c = Option.map fst (Symtab.lookup tab c); |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
95 |
|
383
fcea89074e4c
added incremental extension functions: extend_log_types, extend_type_gram,
wenzelm
parents:
330
diff
changeset
|
96 |
fun err_dup_trfuns name cs = |
fcea89074e4c
added incremental extension functions: extend_log_types, extend_type_gram,
wenzelm
parents:
330
diff
changeset
|
97 |
error ("More than one " ^ name ^ " for " ^ commas_quote cs); |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
98 |
|
21536
f119c730f509
extend_trtab: allow identical trfuns to be overwritten;
wenzelm
parents:
20784
diff
changeset
|
99 |
fun remove_trtab trfuns = fold (Symtab.remove SynExt.eq_trfun) trfuns; |
f119c730f509
extend_trtab: allow identical trfuns to be overwritten;
wenzelm
parents:
20784
diff
changeset
|
100 |
|
f119c730f509
extend_trtab: allow identical trfuns to be overwritten;
wenzelm
parents:
20784
diff
changeset
|
101 |
fun extend_trtab name trfuns tab = Symtab.extend (remove_trtab trfuns tab, trfuns) |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
102 |
handle Symtab.DUPS cs => err_dup_trfuns name cs; |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
103 |
|
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
104 |
fun merge_trtabs name tab1 tab2 = Symtab.merge SynExt.eq_trfun (tab1, tab2) |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
105 |
handle Symtab.DUPS cs => err_dup_trfuns name cs; |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
106 |
|
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
107 |
|
5692 | 108 |
(* print (ast) translations *) |
109 |
||
18931 | 110 |
fun lookup_tr' tab c = map fst (Symtab.lookup_list tab c); |
111 |
fun extend_tr'tab trfuns = fold_rev Symtab.update_list trfuns; |
|
112 |
fun remove_tr'tab trfuns = fold (Symtab.remove_list SynExt.eq_trfun) trfuns; |
|
113 |
fun merge_tr'tabs tab1 tab2 = Symtab.merge_list SynExt.eq_trfun (tab1, tab2); |
|
5692 | 114 |
|
115 |
||
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
116 |
|
2700 | 117 |
(** tables of token translation functions **) |
118 |
||
119 |
fun lookup_tokentr tabs modes = |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19375
diff
changeset
|
120 |
let val trs = distinct (eq_fst (op =)) (maps (these o AList.lookup (op =) tabs) (modes @ [""])) |
17314 | 121 |
in fn c => Option.map fst (AList.lookup (op =) trs c) end; |
2700 | 122 |
|
123 |
fun merge_tokentrtabs tabs1 tabs2 = |
|
124 |
let |
|
125 |
fun eq_tr ((c1, (_, s1)), (c2, (_, s2))) = c1 = c2 andalso s1 = s2; |
|
126 |
||
4703 | 127 |
fun name (s, _) = implode (tl (Symbol.explode s)); |
2706 | 128 |
|
2700 | 129 |
fun merge mode = |
130 |
let |
|
17213 | 131 |
val trs1 = these (AList.lookup (op =) tabs1 mode); |
132 |
val trs2 = these (AList.lookup (op =) tabs2 mode); |
|
19046
bc5c6c9b114e
removed distinct, renamed gen_distinct to distinct;
wenzelm
parents:
18977
diff
changeset
|
133 |
val trs = distinct eq_tr (trs1 @ trs2); |
2700 | 134 |
in |
18964 | 135 |
(case duplicates (eq_fst (op =)) trs of |
2700 | 136 |
[] => (mode, trs) |
137 |
| dups => error ("More than one token translation function in mode " ^ |
|
2706 | 138 |
quote mode ^ " for " ^ commas_quote (map name dups))) |
2700 | 139 |
end; |
19046
bc5c6c9b114e
removed distinct, renamed gen_distinct to distinct;
wenzelm
parents:
18977
diff
changeset
|
140 |
in map merge (distinct (op =) (map fst (tabs1 @ tabs2))) end; |
2700 | 141 |
|
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
142 |
fun extend_tokentrtab tokentrs tabs = |
2700 | 143 |
let |
17213 | 144 |
fun ins_tokentr (m, c, f) = |
145 |
AList.default (op =) (m, []) |
|
146 |
#> AList.map_entry (op =) m (cons ("_" ^ c, (f, stamp ()))); |
|
15759 | 147 |
in merge_tokentrtabs tabs (fold ins_tokentr tokentrs []) end; |
2700 | 148 |
|
149 |
||
150 |
||
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
151 |
(** tables of translation rules **) |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
152 |
|
5692 | 153 |
type ruletab = (Ast.ast * Ast.ast) list Symtab.table; |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
154 |
|
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19375
diff
changeset
|
155 |
fun dest_ruletab tab = maps snd (Symtab.dest tab); |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
156 |
|
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
157 |
|
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
158 |
(* empty, extend, merge ruletabs *) |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
159 |
|
18931 | 160 |
val extend_ruletab = fold_rev (fn r => Symtab.update_list (Ast.head_of_rule r, r)); |
161 |
val remove_ruletab = fold (fn r => Symtab.remove_list (op =) (Ast.head_of_rule r, r)); |
|
162 |
fun merge_ruletabs tab1 tab2 = Symtab.merge_list (op =) (tab1, tab2); |
|
0 | 163 |
|
164 |
||
165 |
||
166 |
(** datatype syntax **) |
|
167 |
||
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
168 |
datatype syntax = |
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
169 |
Syntax of { |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
170 |
input: SynExt.xprod list, |
4703 | 171 |
lexicon: Scan.lexicon, |
5692 | 172 |
gram: Parser.gram, |
18 | 173 |
consts: string list, |
2913 | 174 |
prmodes: string list, |
18857 | 175 |
parse_ast_trtab: ((Context.generic -> Ast.ast list -> Ast.ast) * stamp) Symtab.table, |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
176 |
parse_ruletab: ruletab, |
18857 | 177 |
parse_trtab: ((Context.generic -> term list -> term) * stamp) Symtab.table, |
178 |
print_trtab: ((Context.generic -> bool -> typ -> term list -> term) * stamp) list Symtab.table, |
|
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
179 |
print_ruletab: ruletab, |
18857 | 180 |
print_ast_trtab: ((Context.generic -> Ast.ast list -> Ast.ast) * stamp) list Symtab.table, |
6322 | 181 |
tokentrtab: (string * (string * ((string -> string * real) * stamp)) list) list, |
17079 | 182 |
prtabs: Printer.prtabs} * stamp; |
0 | 183 |
|
17079 | 184 |
fun eq_syntax (Syntax (_, s1), Syntax (_, s2)) = s1 = s2; |
185 |
||
186 |
fun is_keyword (Syntax ({lexicon, ...}, _)) = Scan.is_literal lexicon o Symbol.explode; |
|
14687 | 187 |
|
20784 | 188 |
type mode = string * bool; |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
189 |
val default_mode = ("", true); |
21702 | 190 |
val input_mode = ("input", true); |
21731 | 191 |
val internal_mode = ("internal", true); |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
192 |
|
18 | 193 |
|
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
194 |
(* empty_syntax *) |
18 | 195 |
|
17079 | 196 |
val empty_syntax = Syntax |
197 |
({input = [], |
|
4703 | 198 |
lexicon = Scan.empty_lexicon, |
5692 | 199 |
gram = Parser.empty_gram, |
167 | 200 |
consts = [], |
2913 | 201 |
prmodes = [], |
5692 | 202 |
parse_ast_trtab = Symtab.empty, |
203 |
parse_ruletab = Symtab.empty, |
|
204 |
parse_trtab = Symtab.empty, |
|
205 |
print_trtab = Symtab.empty, |
|
206 |
print_ruletab = Symtab.empty, |
|
207 |
print_ast_trtab = Symtab.empty, |
|
2700 | 208 |
tokentrtab = [], |
17079 | 209 |
prtabs = Printer.empty_prtabs}, stamp ()); |
167 | 210 |
|
211 |
||
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
212 |
(* extend_syntax *) |
167 | 213 |
|
17079 | 214 |
fun extend_syntax (mode, inout) syn_ext (Syntax (tabs, _)) = |
167 | 215 |
let |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
216 |
val {input, lexicon, gram, consts = consts1, prmodes = prmodes1, |
2366 | 217 |
parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab, print_ruletab, |
2700 | 218 |
print_ast_trtab, tokentrtab, prtabs} = tabs; |
14904
7d8dc92fcb7f
removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents:
14798
diff
changeset
|
219 |
val SynExt.SynExt {xprods, consts = consts2, prmodes = prmodes2, |
2913 | 220 |
parse_ast_translation, parse_rules, parse_translation, print_translation, print_rules, |
2700 | 221 |
print_ast_translation, token_translation} = syn_ext; |
19546
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
222 |
fun if_inout xs = if inout then xs else []; |
167 | 223 |
in |
17079 | 224 |
Syntax |
19546
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
225 |
({input = if_inout xprods @ input, |
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
226 |
lexicon = Scan.extend_lexicon lexicon (if_inout (SynExt.delims_of xprods)), |
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
227 |
gram = Parser.extend_gram gram (if_inout xprods), |
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
228 |
consts = Library.merge (op =) (consts1, filter_out NameSpace.is_qualified consts2), |
18921 | 229 |
prmodes = insert (op =) mode (Library.merge (op =) (prmodes1, prmodes2)), |
167 | 230 |
parse_ast_trtab = |
19546
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
231 |
extend_trtab "parse ast translation" (if_inout parse_ast_translation) parse_ast_trtab, |
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
232 |
parse_ruletab = extend_ruletab (if_inout parse_rules) parse_ruletab, |
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
233 |
parse_trtab = extend_trtab "parse translation" (if_inout parse_translation) parse_trtab, |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
234 |
print_trtab = extend_tr'tab print_translation print_trtab, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
235 |
print_ruletab = extend_ruletab print_rules print_ruletab, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
236 |
print_ast_trtab = extend_tr'tab print_ast_translation print_ast_trtab, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
237 |
tokentrtab = extend_tokentrtab token_translation tokentrtab, |
17079 | 238 |
prtabs = Printer.extend_prtabs mode xprods prtabs}, stamp ()) |
18 | 239 |
end; |
240 |
||
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
241 |
|
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
242 |
(* remove_syntax *) |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
243 |
|
17079 | 244 |
fun remove_syntax (mode, inout) syn_ext (Syntax (tabs, _)) = |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
245 |
let |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
246 |
val SynExt.SynExt {xprods, consts = _, prmodes = _, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
247 |
parse_ast_translation, parse_rules, parse_translation, print_translation, print_rules, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
248 |
print_ast_translation, token_translation = _} = syn_ext; |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
249 |
val {input, lexicon, gram, consts, prmodes, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
250 |
parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab, print_ruletab, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
251 |
print_ast_trtab, tokentrtab, prtabs} = tabs; |
19300 | 252 |
val input' = if inout then subtract (op =) xprods input else input; |
19546
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
253 |
fun if_inout xs = if inout then xs else []; |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
254 |
in |
17079 | 255 |
Syntax |
256 |
({input = input', |
|
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
257 |
lexicon = if inout then Scan.make_lexicon (SynExt.delims_of input') else lexicon, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
258 |
gram = if inout then Parser.make_gram input' else gram, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
259 |
consts = consts, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
260 |
prmodes = prmodes, |
19546
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
261 |
parse_ast_trtab = remove_trtab (if_inout parse_ast_translation) parse_ast_trtab, |
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
262 |
parse_ruletab = remove_ruletab (if_inout parse_rules) parse_ruletab, |
00d5c7c7ce07
extend/remove_syntax: observe inout flag for translations, too;
wenzelm
parents:
19482
diff
changeset
|
263 |
parse_trtab = remove_trtab (if_inout parse_translation) parse_trtab, |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
264 |
print_trtab = remove_tr'tab print_translation print_trtab, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
265 |
print_ruletab = remove_ruletab print_rules print_ruletab, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
266 |
print_ast_trtab = remove_tr'tab print_ast_translation print_ast_trtab, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
267 |
tokentrtab = tokentrtab, |
17079 | 268 |
prtabs = Printer.remove_prtabs mode xprods prtabs}, stamp ()) |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
269 |
end; |
14904
7d8dc92fcb7f
removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents:
14798
diff
changeset
|
270 |
|
18 | 271 |
|
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
272 |
(* merge_syntaxes *) |
0 | 273 |
|
17079 | 274 |
fun merge_syntaxes (Syntax (tabs1, _)) (Syntax (tabs2, _)) = |
0 | 275 |
let |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
276 |
val {input = input1, lexicon = lexicon1, gram = gram1, consts = consts1, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
277 |
prmodes = prmodes1, parse_ast_trtab = parse_ast_trtab1, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
278 |
parse_ruletab = parse_ruletab1, parse_trtab = parse_trtab1, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
279 |
print_trtab = print_trtab1, print_ruletab = print_ruletab1, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
280 |
print_ast_trtab = print_ast_trtab1, tokentrtab = tokentrtab1, prtabs = prtabs1} = tabs1; |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
281 |
|
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
282 |
val {input = input2, lexicon = lexicon2, gram = gram2, consts = consts2, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
283 |
prmodes = prmodes2, parse_ast_trtab = parse_ast_trtab2, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
284 |
parse_ruletab = parse_ruletab2, parse_trtab = parse_trtab2, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
285 |
print_trtab = print_trtab2, print_ruletab = print_ruletab2, |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
286 |
print_ast_trtab = print_ast_trtab2, tokentrtab = tokentrtab2, prtabs = prtabs2} = tabs2; |
0 | 287 |
in |
17079 | 288 |
Syntax |
18921 | 289 |
({input = Library.merge (op =) (input1, input2), |
4703 | 290 |
lexicon = Scan.merge_lexicons lexicon1 lexicon2, |
5692 | 291 |
gram = Parser.merge_grams gram1 gram2, |
18428 | 292 |
consts = sort_distinct string_ord (consts1 @ consts2), |
18921 | 293 |
prmodes = Library.merge (op =) (prmodes1, prmodes2), |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
294 |
parse_ast_trtab = |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
295 |
merge_trtabs "parse ast translation" parse_ast_trtab1 parse_ast_trtab2, |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
296 |
parse_ruletab = merge_ruletabs parse_ruletab1 parse_ruletab2, |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
297 |
parse_trtab = merge_trtabs "parse translation" parse_trtab1 parse_trtab2, |
5692 | 298 |
print_trtab = merge_tr'tabs print_trtab1 print_trtab2, |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
299 |
print_ruletab = merge_ruletabs print_ruletab1 print_ruletab2, |
5692 | 300 |
print_ast_trtab = merge_tr'tabs print_ast_trtab1 print_ast_trtab2, |
2700 | 301 |
tokentrtab = merge_tokentrtabs tokentrtab1 tokentrtab2, |
17079 | 302 |
prtabs = Printer.merge_prtabs prtabs1 prtabs2}, stamp ()) |
0 | 303 |
end; |
304 |
||
305 |
||
18720 | 306 |
(* basic syntax *) |
260 | 307 |
|
18720 | 308 |
val basic_syn = |
17168 | 309 |
empty_syntax |
310 |
|> extend_syntax default_mode TypeExt.type_ext |
|
311 |
|> extend_syntax default_mode SynExt.pure_ext; |
|
260 | 312 |
|
18720 | 313 |
val basic_nonterms = |
314 |
(Lexicon.terminals @ [SynExt.logic, "type", "types", "sort", "classes", |
|
315 |
SynExt.args, SynExt.cargs, "pttrn", "pttrns", "idt", "idts", "aprop", |
|
316 |
"asms", SynExt.any, SynExt.sprop, "num_const", "index", "struct"]); |
|
317 |
||
318 |
val appl_syntax = |
|
319 |
[("_appl", "[('b => 'a), args] => logic", Mixfix.Mixfix ("(1_/(1'(_')))", [1000, 0], 1000)), |
|
320 |
("_appl", "[('b => 'a), args] => aprop", Mixfix.Mixfix ("(1_/(1'(_')))", [1000, 0], 1000))]; |
|
321 |
||
322 |
val applC_syntax = |
|
323 |
[("", "'a => cargs", Mixfix.Delimfix "_"), |
|
324 |
("_cargs", "['a, cargs] => cargs", Mixfix.Mixfix ("_/ _", [1000, 1000], 1000)), |
|
325 |
("_applC", "[('b => 'a), cargs] => logic", Mixfix.Mixfix ("(1_/ _)", [1000, 1000], 999)), |
|
326 |
("_applC", "[('b => 'a), cargs] => aprop", Mixfix.Mixfix ("(1_/ _)", [1000, 1000], 999))]; |
|
327 |
||
0 | 328 |
|
4887 | 329 |
|
15759 | 330 |
(** print syntax **) |
331 |
||
332 |
local |
|
0 | 333 |
|
260 | 334 |
fun pretty_strs_qs name strs = |
14598
7009f59711e3
Replaced quote by Library.quote, since quote now refers to Symbol.quote
berghofe
parents:
14177
diff
changeset
|
335 |
Pretty.strs (name :: map Library.quote (sort_strings strs)); |
0 | 336 |
|
17079 | 337 |
fun pretty_gram (Syntax (tabs, _)) = |
0 | 338 |
let |
14904
7d8dc92fcb7f
removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents:
14798
diff
changeset
|
339 |
val {lexicon, prmodes, gram, prtabs, ...} = tabs; |
2913 | 340 |
val prmodes' = sort_strings (filter_out (equal "") prmodes); |
0 | 341 |
in |
8720 | 342 |
[pretty_strs_qs "lexicon:" (Scan.dest_lexicon lexicon), |
343 |
Pretty.big_list "prods:" (Parser.pretty_gram gram), |
|
344 |
pretty_strs_qs "print modes:" prmodes'] |
|
0 | 345 |
end; |
346 |
||
17079 | 347 |
fun pretty_trans (Syntax (tabs, _)) = |
0 | 348 |
let |
260 | 349 |
fun pretty_trtab name tab = |
5692 | 350 |
pretty_strs_qs name (Symtab.keys tab); |
0 | 351 |
|
260 | 352 |
fun pretty_ruletab name tab = |
5692 | 353 |
Pretty.big_list name (map Ast.pretty_rule (dest_ruletab tab)); |
0 | 354 |
|
14598
7009f59711e3
Replaced quote by Library.quote, since quote now refers to Symbol.quote
berghofe
parents:
14177
diff
changeset
|
355 |
fun pretty_tokentr (mode, trs) = Pretty.strs (Library.quote mode ^ ":" :: map fst trs); |
4703 | 356 |
|
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
357 |
val {consts, parse_ast_trtab, parse_ruletab, parse_trtab, print_trtab, |
4703 | 358 |
print_ruletab, print_ast_trtab, tokentrtab, ...} = tabs; |
0 | 359 |
in |
8720 | 360 |
[pretty_strs_qs "consts:" consts, |
361 |
pretty_trtab "parse_ast_translation:" parse_ast_trtab, |
|
362 |
pretty_ruletab "parse_rules:" parse_ruletab, |
|
363 |
pretty_trtab "parse_translation:" parse_trtab, |
|
364 |
pretty_trtab "print_translation:" print_trtab, |
|
365 |
pretty_ruletab "print_rules:" print_ruletab, |
|
366 |
pretty_trtab "print_ast_translation:" print_ast_trtab, |
|
367 |
Pretty.big_list "token_translation:" (map pretty_tokentr tokentrtab)] |
|
0 | 368 |
end; |
369 |
||
15759 | 370 |
in |
0 | 371 |
|
15759 | 372 |
fun print_gram syn = Pretty.writeln (Pretty.chunks (pretty_gram syn)); |
373 |
fun print_trans syn = Pretty.writeln (Pretty.chunks (pretty_trans syn)); |
|
374 |
fun print_syntax syn = Pretty.writeln (Pretty.chunks (pretty_gram syn @ pretty_trans syn)); |
|
0 | 375 |
|
15759 | 376 |
end; |
0 | 377 |
|
378 |
||
379 |
||
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
380 |
(** read **) |
18 | 381 |
|
260 | 382 |
(* read_ast *) |
383 |
||
882
b118d1ea0dfd
moved ambiguity_level from sign.ML to Syntax/syntax.ML
clasohm
parents:
865
diff
changeset
|
384 |
val ambiguity_level = ref 1; |
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
385 |
val ambiguity_is_error = ref false |
882
b118d1ea0dfd
moved ambiguity_level from sign.ML to Syntax/syntax.ML
clasohm
parents:
865
diff
changeset
|
386 |
|
18857 | 387 |
fun read_asts context is_logtype (Syntax (tabs, _)) xids root str = |
260 | 388 |
let |
14904
7d8dc92fcb7f
removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents:
14798
diff
changeset
|
389 |
val {lexicon, gram, parse_ast_trtab, ...} = tabs; |
7d8dc92fcb7f
removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents:
14798
diff
changeset
|
390 |
val root' = if root <> "prop" andalso is_logtype root then SynExt.logic else root; |
4703 | 391 |
val chars = Symbol.explode str; |
5692 | 392 |
val pts = Parser.parse gram root' (Lexicon.tokenize lexicon xids chars); |
330
2fda15dd1e0f
changed the way a grammar is generated to allow the new parser to work;
clasohm
parents:
260
diff
changeset
|
393 |
|
12292 | 394 |
fun show_pt pt = |
18857 | 395 |
Pretty.string_of (Ast.pretty_ast (hd (SynTrans.pts_to_asts context (K NONE) [pt]))); |
260 | 396 |
in |
16613
76e57e08dcb5
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15833
diff
changeset
|
397 |
conditional (length pts > ! ambiguity_level) (fn () => |
76e57e08dcb5
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15833
diff
changeset
|
398 |
if ! ambiguity_is_error then error ("Ambiguous input " ^ quote str) |
16661
507438b27f66
use tracing for potentially voluminous ambiguity output;
wenzelm
parents:
16613
diff
changeset
|
399 |
else (warning ("Ambiguous input " ^ quote str ^ "\n" ^ |
16716 | 400 |
"produces " ^ string_of_int (length pts) ^ " parse trees."); |
16669 | 401 |
List.app (warning o show_pt) pts)); |
18857 | 402 |
SynTrans.pts_to_asts context (lookup_tr parse_ast_trtab) pts |
260 | 403 |
end; |
404 |
||
405 |
||
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
406 |
(* read *) |
0 | 407 |
|
18857 | 408 |
fun read context is_logtype (syn as Syntax (tabs, _)) ty str = |
0 | 409 |
let |
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
410 |
val {parse_ruletab, parse_trtab, ...} = tabs; |
18857 | 411 |
val asts = read_asts context is_logtype syn false (SynExt.typ_to_nonterm ty) str; |
0 | 412 |
in |
18857 | 413 |
SynTrans.asts_to_terms context (lookup_tr parse_trtab) |
18931 | 414 |
(map (Ast.normalize_ast (Symtab.lookup_list parse_ruletab)) asts) |
0 | 415 |
end; |
416 |
||
417 |
||
237
a7d3e712767a
MAJOR INTERNAL CHANGE: extend and merge operations of syntax tables
wenzelm
parents:
175
diff
changeset
|
418 |
(* read types *) |
0 | 419 |
|
18857 | 420 |
fun read_typ context syn get_sort map_sort str = |
421 |
(case read context (K false) syn SynExt.typeT str of |
|
12316 | 422 |
[t] => TypeExt.typ_of_term (get_sort (TypeExt.raw_term_sorts t)) map_sort t |
8894 | 423 |
| _ => error "read_typ: ambiguous syntax"); |
144 | 424 |
|
425 |
||
8894 | 426 |
(* read sorts *) |
427 |
||
18857 | 428 |
fun read_sort context syn str = |
429 |
(case read context (K false) syn TypeExt.sortT str of |
|
8894 | 430 |
[t] => TypeExt.sort_of_term t |
431 |
| _ => error "read_sort: ambiguous syntax"); |
|
432 |
||
433 |
||
18 | 434 |
|
1158 | 435 |
(** prepare translation rules **) |
436 |
||
437 |
datatype 'a trrule = |
|
3526 | 438 |
ParseRule of 'a * 'a | |
439 |
PrintRule of 'a * 'a | |
|
440 |
ParsePrintRule of 'a * 'a; |
|
888
3a1de9454d13
improved read_xrules: patterns no longer read twice;
wenzelm
parents:
882
diff
changeset
|
441 |
|
4618 | 442 |
fun map_trrule f (ParseRule (x, y)) = ParseRule (f x, f y) |
443 |
| map_trrule f (PrintRule (x, y)) = PrintRule (f x, f y) |
|
444 |
| map_trrule f (ParsePrintRule (x, y)) = ParsePrintRule (f x, f y); |
|
1158 | 445 |
|
15531 | 446 |
fun parse_rule (ParseRule pats) = SOME pats |
447 |
| parse_rule (PrintRule _) = NONE |
|
448 |
| parse_rule (ParsePrintRule pats) = SOME pats; |
|
1158 | 449 |
|
15531 | 450 |
fun print_rule (ParseRule _) = NONE |
451 |
| print_rule (PrintRule pats) = SOME (swap pats) |
|
452 |
| print_rule (ParsePrintRule pats) = SOME (swap pats); |
|
1158 | 453 |
|
454 |
||
19262 | 455 |
local |
456 |
||
1158 | 457 |
fun check_rule (rule as (lhs, rhs)) = |
5692 | 458 |
(case Ast.rule_error rule of |
15531 | 459 |
SOME msg => |
1158 | 460 |
error ("Error in syntax translation rule: " ^ msg ^ "\n" ^ |
5692 | 461 |
Ast.str_of_ast lhs ^ " -> " ^ Ast.str_of_ast rhs) |
15531 | 462 |
| NONE => rule); |
888
3a1de9454d13
improved read_xrules: patterns no longer read twice;
wenzelm
parents:
882
diff
changeset
|
463 |
|
3a1de9454d13
improved read_xrules: patterns no longer read twice;
wenzelm
parents:
882
diff
changeset
|
464 |
|
18857 | 465 |
fun read_pattern context is_logtype syn (root, str) = |
18 | 466 |
let |
17079 | 467 |
val Syntax ({consts, ...}, _) = syn; |
18 | 468 |
|
5692 | 469 |
fun constify (ast as Ast.Constant _) = ast |
470 |
| constify (ast as Ast.Variable x) = |
|
20664 | 471 |
if member (op =) consts x orelse NameSpace.is_qualified x then Ast.Constant x |
3830 | 472 |
else ast |
5692 | 473 |
| constify (Ast.Appl asts) = Ast.Appl (map constify asts); |
18 | 474 |
in |
18857 | 475 |
(case read_asts context is_logtype syn true root str of |
888
3a1de9454d13
improved read_xrules: patterns no longer read twice;
wenzelm
parents:
882
diff
changeset
|
476 |
[ast] => constify ast |
3a1de9454d13
improved read_xrules: patterns no longer read twice;
wenzelm
parents:
882
diff
changeset
|
477 |
| _ => error ("Syntactically ambiguous input: " ^ quote str)) |
18678 | 478 |
end handle ERROR msg => |
479 |
cat_error msg ("The error(s) above occurred in translation pattern " ^ |
|
888
3a1de9454d13
improved read_xrules: patterns no longer read twice;
wenzelm
parents:
882
diff
changeset
|
480 |
quote str); |
0 | 481 |
|
1158 | 482 |
fun prep_rules rd_pat raw_rules = |
4618 | 483 |
let val rules = map (map_trrule rd_pat) raw_rules in |
19482
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19375
diff
changeset
|
484 |
(map check_rule (map_filter parse_rule rules), |
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
wenzelm
parents:
19375
diff
changeset
|
485 |
map check_rule (map_filter print_rule rules)) |
1158 | 486 |
end |
18 | 487 |
|
19262 | 488 |
in |
489 |
||
490 |
val cert_rules = prep_rules I; |
|
491 |
||
492 |
fun read_rules context is_logtype syn = |
|
493 |
prep_rules (read_pattern context is_logtype syn); |
|
494 |
||
495 |
end; |
|
496 |
||
18 | 497 |
|
498 |
||
3779 | 499 |
(** pretty terms, typs, sorts **) |
18 | 500 |
|
18857 | 501 |
fun pretty_t t_to_ast prt_t context (syn as Syntax (tabs, _)) curried t = |
0 | 502 |
let |
2700 | 503 |
val {print_trtab, print_ruletab, print_ast_trtab, tokentrtab, prtabs, ...} = tabs; |
18857 | 504 |
val ast = t_to_ast context (lookup_tr' print_trtab) t; |
0 | 505 |
in |
18857 | 506 |
prt_t context curried prtabs (lookup_tr' print_ast_trtab) |
6167
2f354020efc3
corrected output of symbols for several (probably not all) relevant functions
oheimb
parents:
5702
diff
changeset
|
507 |
(lookup_tokentr tokentrtab (! print_mode)) |
18931 | 508 |
(Ast.normalize_ast (Symtab.lookup_list print_ruletab) ast) |
0 | 509 |
end; |
510 |
||
19375
8198a4ffff24
pretty_term: late externing of consts (support authentic syntax);
wenzelm
parents:
19300
diff
changeset
|
511 |
val pretty_term = pretty_t Printer.term_to_ast o Printer.pretty_term_ast; |
18857 | 512 |
fun pretty_typ context syn = pretty_t Printer.typ_to_ast Printer.pretty_typ_ast context syn false; |
513 |
fun pretty_sort context syn = pretty_t Printer.sort_to_ast Printer.pretty_typ_ast context syn false; |
|
0 | 514 |
|
515 |
||
516 |
||
19262 | 517 |
(** modify syntax **) |
383
fcea89074e4c
added incremental extension functions: extend_log_types, extend_type_gram,
wenzelm
parents:
330
diff
changeset
|
518 |
|
14904
7d8dc92fcb7f
removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents:
14798
diff
changeset
|
519 |
fun ext_syntax' f is_logtype prmode decls = extend_syntax prmode (f is_logtype decls); |
7d8dc92fcb7f
removed separate logtypes field of syntax; removed test_read, simple_str_of_sort, simple_string_of_typ; provide default_mode;
wenzelm
parents:
14798
diff
changeset
|
520 |
fun ext_syntax f = ext_syntax' (K f) (K false) default_mode; |
383
fcea89074e4c
added incremental extension functions: extend_log_types, extend_type_gram,
wenzelm
parents:
330
diff
changeset
|
521 |
|
16613
76e57e08dcb5
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15833
diff
changeset
|
522 |
val extend_type_gram = ext_syntax Mixfix.syn_ext_types; |
76e57e08dcb5
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15833
diff
changeset
|
523 |
val extend_const_gram = ext_syntax' Mixfix.syn_ext_consts; |
76e57e08dcb5
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15833
diff
changeset
|
524 |
val extend_consts = ext_syntax SynExt.syn_ext_const_names; |
76e57e08dcb5
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15833
diff
changeset
|
525 |
val extend_trfuns = ext_syntax SynExt.syn_ext_trfuns; |
76e57e08dcb5
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15833
diff
changeset
|
526 |
val extend_advanced_trfuns = ext_syntax SynExt.syn_ext_advanced_trfuns; |
76e57e08dcb5
proper treatment of advanced trfuns: pass thy argument;
wenzelm
parents:
15833
diff
changeset
|
527 |
val extend_tokentrfuns = ext_syntax SynExt.syn_ext_tokentrfuns; |
5692 | 528 |
|
15755
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
529 |
fun remove_const_gram is_logtype prmode decls = |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
530 |
remove_syntax prmode (Mixfix.syn_ext_consts is_logtype decls); |
50ac97ebe7d8
expect translations functions to be stamped already;
wenzelm
parents:
15574
diff
changeset
|
531 |
|
19262 | 532 |
fun extend_trrules context is_logtype syn = |
533 |
ext_syntax SynExt.syn_ext_rules o read_rules context is_logtype syn; |
|
534 |
||
535 |
fun remove_trrules context is_logtype syn = |
|
536 |
remove_syntax default_mode o SynExt.syn_ext_rules o read_rules context is_logtype syn; |
|
537 |
||
538 |
val extend_trrules_i = ext_syntax SynExt.syn_ext_rules o cert_rules; |
|
539 |
val remove_trrules_i = remove_syntax default_mode o SynExt.syn_ext_rules o cert_rules; |
|
5692 | 540 |
|
541 |
||
15833
78109c7012ed
removed token_trans.ML (some content moved to syn_ext.ML);
wenzelm
parents:
15759
diff
changeset
|
542 |
(*export parts of internal Syntax structures*) |
78109c7012ed
removed token_trans.ML (some content moved to syn_ext.ML);
wenzelm
parents:
15759
diff
changeset
|
543 |
open Lexicon SynExt Ast Parser TypeExt SynTrans Mixfix Printer; |
2366 | 544 |
|
0 | 545 |
end; |
5692 | 546 |
|
547 |
structure BasicSyntax: BASIC_SYNTAX = Syntax; |
|
548 |
open BasicSyntax; |