discontinued special treatment of structure Syntax_Ext (formerly Syn_Ext);
clarified Syntax.root;
--- a/doc-src/Codegen/Thy/Setup.thy Fri Apr 08 14:20:57 2011 +0200
+++ b/doc-src/Codegen/Thy/Setup.thy Fri Apr 08 15:02:11 2011 +0200
@@ -10,8 +10,8 @@
setup {*
let
val typ = Simple_Syntax.read_typ;
- val typeT = Syntax.typeT;
- val spropT = Syntax.spropT;
+ val typeT = Syntax_Ext.typeT;
+ val spropT = Syntax_Ext.spropT;
in
Sign.del_modesyntax_i (Symbol.xsymbolsN, false) [
("_constrain", typ "logic => type => logic", Mixfix ("_\<Colon>_", [4, 0], 3)),
--- a/src/HOL/Boogie/Tools/boogie_loader.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/HOL/Boogie/Tools/boogie_loader.ML Fri Apr 08 15:02:11 2011 +0200
@@ -51,7 +51,7 @@
fun mk_syntax name i =
let
- val syn = Syntax.escape name
+ val syn = Syntax_Ext.escape name
val args = space_implode ",/ " (replicate i "_")
in
if i = 0 then Mixfix (syn, [], 1000)
--- a/src/HOL/Imperative_HOL/Overview.thy Fri Apr 08 14:20:57 2011 +0200
+++ b/src/HOL/Imperative_HOL/Overview.thy Fri Apr 08 15:02:11 2011 +0200
@@ -11,8 +11,8 @@
setup {*
let
val typ = Simple_Syntax.read_typ;
- val typeT = Syntax.typeT;
- val spropT = Syntax.spropT;
+ val typeT = Syntax_Ext.typeT;
+ val spropT = Syntax_Ext.spropT;
in
Sign.del_modesyntax_i (Symbol.xsymbolsN, false) [
("_constrain", typ "logic => type => logic", Mixfix ("_\<Colon>_", [4, 0], 3)),
--- a/src/HOL/Import/proof_kernel.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/HOL/Import/proof_kernel.ML Fri Apr 08 15:02:11 2011 +0200
@@ -182,7 +182,7 @@
fun mk_syn thy c =
if Syntax.is_identifier c andalso not (Syntax.is_keyword (Sign.syn_of thy) c) then NoSyn
- else Delimfix (Syntax.escape c)
+ else Delimfix (Syntax_Ext.escape c)
fun quotename c =
if Syntax.is_identifier c andalso not (Keyword.is_keyword c) then c else quote c
--- a/src/HOL/Library/OptionalSugar.thy Fri Apr 08 14:20:57 2011 +0200
+++ b/src/HOL/Library/OptionalSugar.thy Fri Apr 08 15:02:11 2011 +0200
@@ -51,8 +51,8 @@
setup {*
let
val typ = Simple_Syntax.read_typ;
- val typeT = Syntax.typeT;
- val spropT = Syntax.spropT;
+ val typeT = Syntax_Ext.typeT;
+ val spropT = Syntax_Ext.spropT;
in
Sign.del_modesyntax_i (Symbol.xsymbolsN, false) [
("_constrain", typ "logic => type => logic", Mixfix ("_\<Colon>_", [4, 0], 3)),
--- a/src/Pure/IsaMakefile Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/IsaMakefile Fri Apr 08 15:02:11 2011 +0200
@@ -184,8 +184,8 @@
Syntax/parser.ML \
Syntax/printer.ML \
Syntax/simple_syntax.ML \
- Syntax/syn_ext.ML \
Syntax/syntax.ML \
+ Syntax/syntax_ext.ML \
Syntax/syntax_phases.ML \
Syntax/syntax_trans.ML \
Syntax/term_position.ML \
--- a/src/Pure/Isar/auto_bind.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/Isar/auto_bind.ML Fri Apr 08 15:02:11 2011 +0200
@@ -45,8 +45,8 @@
fun facts _ [] = []
| facts thy props =
let val prop = List.last props
- in [(Syntax.dddot_indexname, get_arg thy prop)] @ statement_binds thy thisN prop end;
+ in [(Syntax_Ext.dddot_indexname, get_arg thy prop)] @ statement_binds thy thisN prop end;
-val no_facts = [(Syntax.dddot_indexname, NONE), ((thisN, 0), NONE)];
+val no_facts = [(Syntax_Ext.dddot_indexname, NONE), ((thisN, 0), NONE)];
end;
--- a/src/Pure/ML-Systems/polyml_common.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/ML-Systems/polyml_common.ML Fri Apr 08 15:02:11 2011 +0200
@@ -23,8 +23,6 @@
(** ML system and platform related **)
-val forget_structure = PolyML.Compiler.forgetStructure;
-
val _ = PolyML.Compiler.forgetValue "isSome";
val _ = PolyML.Compiler.forgetValue "getOpt";
val _ = PolyML.Compiler.forgetValue "valOf";
--- a/src/Pure/ML-Systems/smlnj.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/ML-Systems/smlnj.ML Fri Apr 08 15:02:11 2011 +0200
@@ -103,8 +103,6 @@
val txt = Exn.release (Exn.capture TextIO.inputAll instream before TextIO.closeIn instream);
in use_text context (1, name) verbose txt end;
-fun forget_structure _ = ();
-
(* toplevel pretty printing *)
--- a/src/Pure/ROOT.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/ROOT.ML Fri Apr 08 15:02:11 2011 +0200
@@ -122,7 +122,7 @@
use "Syntax/lexicon.ML";
use "Syntax/simple_syntax.ML";
use "Syntax/ast.ML";
-use "Syntax/syn_ext.ML";
+use "Syntax/syntax_ext.ML";
use "Syntax/parser.ML";
use "Syntax/syntax_trans.ML";
use "Syntax/mixfix.ML";
--- a/src/Pure/Syntax/local_syntax.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/Syntax/local_syntax.ML Fri Apr 08 15:02:11 2011 +0200
@@ -61,8 +61,8 @@
val (atrs, trs, trs', atrs') = Syntax_Trans.struct_trfuns structs;
val local_syntax = thy_syntax
|> Syntax.update_trfuns
- (map Syntax.mk_trfun atrs, map Syntax.mk_trfun trs,
- map Syntax.mk_trfun trs', map Syntax.mk_trfun atrs')
+ (map Syntax_Ext.mk_trfun atrs, map Syntax_Ext.mk_trfun trs,
+ map Syntax_Ext.mk_trfun trs', map Syntax_Ext.mk_trfun atrs')
|> fold update_gram (AList.coalesce (op =) (rev (map snd mixfixes)));
in make_syntax (thy_syntax, local_syntax, mode, mixfixes, idents) end;
--- a/src/Pure/Syntax/mixfix.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/Syntax/mixfix.ML Fri Apr 08 15:02:11 2011 +0200
@@ -25,8 +25,8 @@
val mixfixT: mixfix -> typ
val make_type: int -> typ
val binder_name: string -> string
- val syn_ext_types: (string * typ * mixfix) list -> Syn_Ext.syn_ext
- val syn_ext_consts: (string -> bool) -> (string * typ * mixfix) list -> Syn_Ext.syn_ext
+ val syn_ext_types: (string * typ * mixfix) list -> Syntax_Ext.syn_ext
+ val syn_ext_consts: (string -> bool) -> (string * typ * mixfix) list -> Syntax_Ext.syn_ext
end;
structure Mixfix: MIXFIX =
@@ -74,11 +74,11 @@
(* syntax specifications *)
fun mixfix_args NoSyn = 0
- | mixfix_args (Mixfix (sy, _, _)) = Syn_Ext.mfix_args sy
- | mixfix_args (Delimfix sy) = Syn_Ext.mfix_args sy
- | mixfix_args (Infix (sy, _)) = 2 + Syn_Ext.mfix_args sy
- | mixfix_args (Infixl (sy, _)) = 2 + Syn_Ext.mfix_args sy
- | mixfix_args (Infixr (sy, _)) = 2 + Syn_Ext.mfix_args sy
+ | mixfix_args (Mixfix (sy, _, _)) = Syntax_Ext.mfix_args sy
+ | mixfix_args (Delimfix sy) = Syntax_Ext.mfix_args sy
+ | mixfix_args (Infix (sy, _)) = 2 + Syntax_Ext.mfix_args sy
+ | mixfix_args (Infixl (sy, _)) = 2 + Syntax_Ext.mfix_args sy
+ | mixfix_args (Infixr (sy, _)) = 2 + Syntax_Ext.mfix_args sy
| mixfix_args (Binder _) = 1
| mixfix_args Structure = 0;
@@ -88,29 +88,29 @@
(* syn_ext_types *)
-fun make_type n = replicate n Syn_Ext.typeT ---> Syn_Ext.typeT;
+fun make_type n = replicate n Syntax_Ext.typeT ---> Syntax_Ext.typeT;
fun syn_ext_types type_decls =
let
- fun mk_infix sy ty t p1 p2 p3 = Syn_Ext.Mfix ("(_ " ^ sy ^ "/ _)", ty, t, [p1, p2], p3);
+ fun mk_infix sy ty t p1 p2 p3 = Syntax_Ext.Mfix ("(_ " ^ sy ^ "/ _)", ty, t, [p1, p2], p3);
fun mfix_of (_, _, NoSyn) = NONE
- | mfix_of (t, ty, Mixfix (sy, ps, p)) = SOME (Syn_Ext.Mfix (sy, ty, t, ps, p))
- | mfix_of (t, ty, Delimfix sy) = SOME (Syn_Ext.Mfix (sy, ty, t, [], Syn_Ext.max_pri))
+ | mfix_of (t, ty, Mixfix (sy, ps, p)) = SOME (Syntax_Ext.Mfix (sy, ty, t, ps, p))
+ | mfix_of (t, ty, Delimfix sy) = SOME (Syntax_Ext.Mfix (sy, ty, t, [], Syntax_Ext.max_pri))
| mfix_of (t, ty, Infix (sy, p)) = SOME (mk_infix sy ty t (p + 1) (p + 1) p)
| mfix_of (t, ty, Infixl (sy, p)) = SOME (mk_infix sy ty t p (p + 1) p)
| mfix_of (t, ty, Infixr (sy, p)) = SOME (mk_infix sy ty t (p + 1) p p)
| mfix_of (t, _, _) = error ("Bad mixfix declaration for " ^ quote t);
- fun check_args (_, ty, _) (SOME (mfix as Syn_Ext.Mfix (sy, _, _, _, _))) =
- if length (Term.binder_types ty) = Syn_Ext.mfix_args sy then ()
- else Syn_Ext.err_in_mfix "Bad number of type constructor arguments" mfix
+ fun check_args (_, ty, _) (SOME (mfix as Syntax_Ext.Mfix (sy, _, _, _, _))) =
+ if length (Term.binder_types ty) = Syntax_Ext.mfix_args sy then ()
+ else Syntax_Ext.err_in_mfix "Bad number of type constructor arguments" mfix
| check_args _ NONE = ();
val mfix = map mfix_of type_decls;
val _ = map2 check_args type_decls mfix;
val xconsts = map #1 type_decls;
- in Syn_Ext.syn_ext (map_filter I mfix) xconsts ([], [], [], []) ([], []) end;
+ in Syntax_Ext.syn_ext (map_filter I mfix) xconsts ([], [], [], []) ([], []) end;
(* syn_ext_consts *)
@@ -121,21 +121,21 @@
fun syn_ext_consts is_logtype const_decls =
let
fun mk_infix sy ty c p1 p2 p3 =
- [Syn_Ext.Mfix ("op " ^ sy, ty, c, [], Syn_Ext.max_pri),
- Syn_Ext.Mfix ("(_ " ^ sy ^ "/ _)", ty, c, [p1, p2], p3)];
+ [Syntax_Ext.Mfix ("op " ^ sy, ty, c, [], Syntax_Ext.max_pri),
+ Syntax_Ext.Mfix ("(_ " ^ sy ^ "/ _)", ty, c, [p1, p2], p3)];
fun binder_typ _ (Type ("fun", [Type ("fun", [_, ty2]), ty3])) =
[Type ("idts", []), ty2] ---> ty3
| binder_typ c _ = error ("Bad type of binder: " ^ quote c);
fun mfix_of (_, _, NoSyn) = []
- | mfix_of (c, ty, Mixfix (sy, ps, p)) = [Syn_Ext.Mfix (sy, ty, c, ps, p)]
- | mfix_of (c, ty, Delimfix sy) = [Syn_Ext.Mfix (sy, ty, c, [], Syn_Ext.max_pri)]
+ | mfix_of (c, ty, Mixfix (sy, ps, p)) = [Syntax_Ext.Mfix (sy, ty, c, ps, p)]
+ | mfix_of (c, ty, Delimfix sy) = [Syntax_Ext.Mfix (sy, ty, c, [], Syntax_Ext.max_pri)]
| mfix_of (c, ty, Infix (sy, p)) = mk_infix sy ty c (p + 1) (p + 1) p
| mfix_of (c, ty, Infixl (sy, p)) = mk_infix sy ty c p (p + 1) p
| mfix_of (c, ty, Infixr (sy, p)) = mk_infix sy ty c (p + 1) p p
| mfix_of (c, ty, Binder (sy, p, q)) =
- [Syn_Ext.Mfix ("(3" ^ sy ^ "_./ _)", binder_typ c ty, (binder_name c), [0, p], q)]
+ [Syntax_Ext.Mfix ("(3" ^ sy ^ "_./ _)", binder_typ c ty, (binder_name c), [0, p], q)]
| mfix_of (c, _, _) = error ("Bad mixfix declaration for " ^ quote c);
fun binder (c, _, Binder _) = SOME (binder_name c, c)
@@ -145,12 +145,12 @@
val xconsts = map #1 const_decls;
val binders = map_filter binder const_decls;
val binder_trs = binders
- |> map (Syn_Ext.stamp_trfun binder_stamp o apsnd K o Syntax_Trans.mk_binder_tr);
+ |> map (Syntax_Ext.stamp_trfun binder_stamp o apsnd K o Syntax_Trans.mk_binder_tr);
val binder_trs' = binders
- |> map (Syn_Ext.stamp_trfun binder_stamp o
+ |> map (Syntax_Ext.stamp_trfun binder_stamp o
apsnd (K o Syntax_Trans.non_typed_tr') o Syntax_Trans.mk_binder_tr' o swap);
in
- Syn_Ext.syn_ext' true is_logtype
+ Syntax_Ext.syn_ext' true is_logtype
mfix xconsts ([], binder_trs, binder_trs', []) ([], [])
end;
--- a/src/Pure/Syntax/parser.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/Syntax/parser.ML Fri Apr 08 15:02:11 2011 +0200
@@ -8,7 +8,7 @@
sig
type gram
val empty_gram: gram
- val extend_gram: Syn_Ext.xprod list -> gram -> gram
+ val extend_gram: Syntax_Ext.xprod list -> gram -> gram
val merge_gram: gram * gram -> gram
val pretty_gram: gram -> Pretty.T list
datatype parsetree =
@@ -468,10 +468,10 @@
delimiters and predefined terms are stored as terminals,
nonterminals are converted to integer tags*)
fun symb_of [] nt_count tags result = (nt_count, tags, rev result)
- | symb_of (Syn_Ext.Delim s :: ss) nt_count tags result =
+ | symb_of (Syntax_Ext.Delim s :: ss) nt_count tags result =
symb_of ss nt_count tags
(Terminal (Lexicon.Token (Lexicon.Literal, s, Position.no_range)) :: result)
- | symb_of (Syn_Ext.Argument (s, p) :: ss) nt_count tags result =
+ | symb_of (Syntax_Ext.Argument (s, p) :: ss) nt_count tags result =
let
val (nt_count', tags', new_symb) =
(case Lexicon.predef_term s of
@@ -485,7 +485,7 @@
(*Convert list of productions by invoking symb_of for each of them*)
fun prod_of [] nt_count prod_count tags result =
(nt_count, prod_count, tags, result)
- | prod_of (Syn_Ext.XProd (lhs, xsymbs, const, pri) :: ps)
+ | prod_of (Syntax_Ext.XProd (lhs, xsymbs, const, pri) :: ps)
nt_count prod_count tags result =
let
val (nt_count', tags', lhs_tag) = get_tag nt_count tags lhs;
--- a/src/Pure/Syntax/printer.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/Syntax/printer.ML Fri Apr 08 15:02:11 2011 +0200
@@ -30,8 +30,8 @@
include PRINTER0
type prtabs
val empty_prtabs: prtabs
- val update_prtabs: string -> Syn_Ext.xprod list -> prtabs -> prtabs
- val remove_prtabs: string -> Syn_Ext.xprod list -> prtabs -> prtabs
+ val update_prtabs: string -> Syntax_Ext.xprod list -> prtabs -> prtabs
+ val remove_prtabs: string -> Syntax_Ext.xprod list -> prtabs -> prtabs
val merge_prtabs: prtabs -> prtabs -> prtabs
val pretty_term_ast: bool -> Proof.context -> prtabs ->
(string -> Proof.context -> Ast.ast list -> Ast.ast) ->
@@ -93,29 +93,29 @@
(* xprod_to_fmt *)
-fun xprod_to_fmt (Syn_Ext.XProd (_, _, "", _)) = NONE
- | xprod_to_fmt (Syn_Ext.XProd (_, xsymbs, const, pri)) =
+fun xprod_to_fmt (Syntax_Ext.XProd (_, _, "", _)) = NONE
+ | xprod_to_fmt (Syntax_Ext.XProd (_, xsymbs, const, pri)) =
let
fun arg (s, p) =
(if s = "type" then TypArg else Arg)
- (if Lexicon.is_terminal s then Syn_Ext.max_pri else p);
+ (if Lexicon.is_terminal s then Syntax_Ext.max_pri else p);
- fun xsyms_to_syms (Syn_Ext.Delim s :: xsyms) =
+ fun xsyms_to_syms (Syntax_Ext.Delim s :: xsyms) =
apfst (cons (String s)) (xsyms_to_syms xsyms)
- | xsyms_to_syms (Syn_Ext.Argument s_p :: xsyms) =
+ | xsyms_to_syms (Syntax_Ext.Argument s_p :: xsyms) =
apfst (cons (arg s_p)) (xsyms_to_syms xsyms)
- | xsyms_to_syms (Syn_Ext.Space s :: xsyms) =
+ | xsyms_to_syms (Syntax_Ext.Space s :: xsyms) =
apfst (cons (Space s)) (xsyms_to_syms xsyms)
- | xsyms_to_syms (Syn_Ext.Bg i :: xsyms) =
+ | xsyms_to_syms (Syntax_Ext.Bg i :: xsyms) =
let
val (bsyms, xsyms') = xsyms_to_syms xsyms;
val (syms, xsyms'') = xsyms_to_syms xsyms';
in
(Block (i, bsyms) :: syms, xsyms'')
end
- | xsyms_to_syms (Syn_Ext.Brk i :: xsyms) =
+ | xsyms_to_syms (Syntax_Ext.Brk i :: xsyms) =
apfst (cons (Break i)) (xsyms_to_syms xsyms)
- | xsyms_to_syms (Syn_Ext.En :: xsyms) = ([], xsyms)
+ | xsyms_to_syms (Syntax_Ext.En :: xsyms) = ([], xsyms)
| xsyms_to_syms [] = ([], []);
fun nargs (Arg _ :: syms) = nargs syms + 1
@@ -145,7 +145,7 @@
fun remove_prtabs mode xprods prtabs =
let
val tab = mode_tab prtabs mode;
- val fmts = map_filter (fn xprod as Syn_Ext.XProd (_, _, c, _) =>
+ val fmts = map_filter (fn xprod as Syntax_Ext.XProd (_, _, c, _) =>
if null (Symtab.lookup_list tab c) then NONE
else xprod_to_fmt xprod) xprods;
val tab' = fold (Symtab.remove_list (op =)) fmts tab;
@@ -210,10 +210,12 @@
val T = if i < 0 then Pretty.fbrk else Pretty.brk i;
in (T :: Ts, args') end
- and parT m (pr, args, p, p': int) = #1 (synT m
- (if p > p' orelse (show_brackets andalso p' <> Syn_Ext.max_pri andalso not (is_chain pr))
- then [Block (1, Space "(" :: pr @ [Space ")"])]
- else pr, args))
+ and parT m (pr, args, p, p': int) =
+ #1 (synT m
+ (if p > p' orelse
+ (show_brackets andalso p' <> Syntax_Ext.max_pri andalso not (is_chain pr))
+ then [Block (1, Space "(" :: pr @ [Space ")"])]
+ else pr, args))
and atomT a = Pretty.marks_str (markup_extern a)
--- a/src/Pure/Syntax/syn_ext.ML Fri Apr 08 14:20:57 2011 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,389 +0,0 @@
-(* Title: Pure/Syntax/syn_ext.ML
- Author: Markus Wenzel and Carsten Clasohm, TU Muenchen
-
-Syntax extension (internal interface).
-*)
-
-signature SYN_EXT0 =
-sig
- val dddot_indexname: indexname
- val typeT: typ
- val spropT: typ
- val default_root: string Config.T
- val max_pri: int
- val stamp_trfun: stamp -> string * 'a -> string * ('a * stamp)
- val mk_trfun: string * 'a -> string * ('a * stamp)
- val eq_trfun: ('a * stamp) * ('a * stamp) -> bool
- val escape: string -> string
- val token_markers: string list
-end;
-
-signature SYN_EXT =
-sig
- include SYN_EXT0
- val logic: string
- val args: string
- val cargs: string
- val any: string
- val sprop: string
- datatype mfix = Mfix of string * typ * string * int list * int
- val err_in_mfix: string -> mfix -> 'a
- val typ_to_nonterm: typ -> string
- datatype xsymb =
- Delim of string |
- Argument of string * int |
- Space of string |
- Bg of int | Brk of int | En
- datatype xprod = XProd of string * xsymb list * string * int
- val chain_pri: int
- val delims_of: xprod list -> string list list
- datatype syn_ext =
- Syn_Ext of {
- xprods: xprod list,
- consts: string list,
- parse_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list,
- parse_rules: (Ast.ast * Ast.ast) list,
- parse_translation: (string * ((Proof.context -> term list -> term) * stamp)) list,
- print_translation: (string * ((Proof.context -> typ -> term list -> term) * stamp)) list,
- print_rules: (Ast.ast * Ast.ast) list,
- print_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list}
- val mfix_delims: string -> string list
- val mfix_args: string -> int
- val syn_ext': bool -> (string -> bool) -> mfix list ->
- string list -> (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
- (string * ((Proof.context -> term list -> term) * stamp)) list *
- (string * ((Proof.context -> typ -> term list -> term) * stamp)) list *
- (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list ->
- (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
- val syn_ext: mfix list -> string list ->
- (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
- (string * ((Proof.context -> term list -> term) * stamp)) list *
- (string * ((Proof.context -> typ -> term list -> term) * stamp)) list *
- (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list ->
- (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
- val syn_ext_const_names: string list -> syn_ext
- val syn_ext_rules: (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
- val syn_ext_trfuns:
- (string * ((Ast.ast list -> Ast.ast) * stamp)) list *
- (string * ((term list -> term) * stamp)) list *
- (string * ((typ -> term list -> term) * stamp)) list *
- (string * ((Ast.ast list -> Ast.ast) * stamp)) list -> syn_ext
- val syn_ext_advanced_trfuns:
- (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
- (string * ((Proof.context -> term list -> term) * stamp)) list *
- (string * ((Proof.context -> typ -> term list -> term) * stamp)) list *
- (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list -> syn_ext
- val pure_ext: syn_ext
-end;
-
-structure Syn_Ext: SYN_EXT =
-struct
-
-
-(** misc definitions **)
-
-val dddot_indexname = ("dddot", 0);
-
-
-(* syntactic categories *)
-
-val logic = "logic";
-val logicT = Type (logic, []);
-
-val args = "args";
-val cargs = "cargs";
-
-val typeT = Type ("type", []);
-
-val sprop = "#prop";
-val spropT = Type (sprop, []);
-
-val any = "any";
-val anyT = Type (any, []);
-
-val default_root =
- Config.string (Config.declare "Syntax.default_root" (K (Config.String any)));
-
-
-
-(** datatype xprod **)
-
-(*Delim s: delimiter s
- Argument (s, p): nonterminal s requiring priority >= p, or valued token
- Space s: some white space for printing
- Bg, Brk, En: blocks and breaks for pretty printing*)
-
-datatype xsymb =
- Delim of string |
- Argument of string * int |
- Space of string |
- Bg of int | Brk of int | En;
-
-fun is_delim (Delim _) = true
- | is_delim _ = false;
-
-fun is_terminal (Delim _) = true
- | is_terminal (Argument (s, _)) = Lexicon.is_terminal s
- | is_terminal _ = false;
-
-fun is_argument (Argument _) = true
- | is_argument _ = false;
-
-fun is_index (Argument ("index", _)) = true
- | is_index _ = false;
-
-val index = Argument ("index", 1000);
-
-
-(*XProd (lhs, syms, c, p):
- lhs: name of nonterminal on the lhs of the production
- syms: list of symbols on the rhs of the production
- c: head of parse tree
- p: priority of this production*)
-
-datatype xprod = XProd of string * xsymb list * string * int;
-
-val max_pri = 1000; (*maximum legal priority*)
-val chain_pri = ~1; (*dummy for chain productions*)
-
-fun delims_of xprods =
- fold (fn XProd (_, xsymbs, _, _) =>
- fold (fn Delim s => insert (op =) s | _ => I) xsymbs) xprods []
- |> map Symbol.explode;
-
-
-
-(** datatype mfix **)
-
-(*Mfix (sy, ty, c, ps, p):
- sy: rhs of production as symbolic string
- ty: type description of production
- c: head of parse tree
- ps: priorities of arguments in sy
- p: priority of production*)
-
-datatype mfix = Mfix of string * typ * string * int list * int;
-
-fun err_in_mfix msg (Mfix (sy, _, const, _, _)) =
- cat_error msg ("in mixfix annotation " ^ quote sy ^ " for " ^ quote const);
-
-
-(* typ_to_nonterm *)
-
-fun typ_to_nt _ (Type (c, _)) = c
- | typ_to_nt default _ = default;
-
-(*get nonterminal for rhs*)
-val typ_to_nonterm = typ_to_nt any;
-
-(*get nonterminal for lhs*)
-val typ_to_nonterm1 = typ_to_nt logic;
-
-
-(* read mixfix annotations *)
-
-local
-
-val is_meta = member (op =) ["(", ")", "/", "_", "\\<index>"];
-
-val scan_delim_char =
- $$ "'" |-- Scan.one ((not o Symbol.is_blank) andf Symbol.is_regular) ||
- Scan.one ((not o is_meta) andf (not o Symbol.is_blank) andf Symbol.is_regular);
-
-fun read_int ["0", "0"] = ~1
- | read_int cs = #1 (Library.read_int cs);
-
-val scan_sym =
- $$ "_" >> K (Argument ("", 0)) ||
- $$ "\\<index>" >> K index ||
- $$ "(" |-- Scan.many Symbol.is_digit >> (Bg o read_int) ||
- $$ ")" >> K En ||
- $$ "/" -- $$ "/" >> K (Brk ~1) ||
- $$ "/" |-- Scan.many Symbol.is_blank >> (Brk o length) ||
- Scan.many1 Symbol.is_blank >> (Space o implode) ||
- Scan.repeat1 scan_delim_char >> (Delim o implode);
-
-val scan_symb =
- scan_sym >> SOME ||
- $$ "'" -- Scan.one Symbol.is_blank >> K NONE;
-
-val scan_symbs = Scan.repeat scan_symb --| Scan.ahead (~$$ "'");
-val read_symbs = map_filter I o the o Scan.read Symbol.stopper scan_symbs;
-
-fun unique_index xsymbs =
- if length (filter is_index xsymbs) <= 1 then xsymbs
- else error "Duplicate index arguments (\\<index>)";
-
-in
-
-val read_mfix = unique_index o read_symbs o Symbol.explode;
-
-fun mfix_delims sy = fold_rev (fn Delim s => cons s | _ => I) (read_mfix sy) [];
-val mfix_args = length o filter is_argument o read_mfix;
-
-val escape = implode o map (fn s => if is_meta s then "'" ^ s else s) o Symbol.explode;
-
-end;
-
-
-(* mfix_to_xprod *)
-
-fun mfix_to_xprod convert is_logtype (mfix as Mfix (sy, typ, const, pris, pri)) =
- let
- fun check_pri p =
- if p >= 0 andalso p <= max_pri then ()
- else err_in_mfix ("Precedence out of range: " ^ string_of_int p) mfix;
-
- fun blocks_ok [] 0 = true
- | blocks_ok [] _ = false
- | blocks_ok (Bg _ :: syms) n = blocks_ok syms (n + 1)
- | blocks_ok (En :: _) 0 = false
- | blocks_ok (En :: syms) n = blocks_ok syms (n - 1)
- | blocks_ok (_ :: syms) n = blocks_ok syms n;
-
- fun check_blocks syms =
- if blocks_ok syms 0 then ()
- else err_in_mfix "Unbalanced block parentheses" mfix;
-
-
- val cons_fst = apfst o cons;
-
- fun add_args [] ty [] = ([], typ_to_nonterm1 ty)
- | add_args [] _ _ = err_in_mfix "Too many precedences" mfix
- | add_args ((arg as Argument ("index", _)) :: syms) ty ps =
- cons_fst arg (add_args syms ty ps)
- | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) [] =
- cons_fst (Argument (typ_to_nonterm ty, 0)) (add_args syms tys [])
- | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) (p :: ps) =
- cons_fst (Argument (typ_to_nonterm ty, p)) (add_args syms tys ps)
- | add_args (Argument _ :: _) _ _ =
- err_in_mfix "More arguments than in corresponding type" mfix
- | add_args (sym :: syms) ty ps = cons_fst sym (add_args syms ty ps);
-
- fun rem_pri (Argument (s, _)) = Argument (s, chain_pri)
- | rem_pri sym = sym;
-
- fun logify_types (a as (Argument (s, p))) =
- if s <> "prop" andalso is_logtype s then Argument (logic, p) else a
- | logify_types a = a;
-
-
- val raw_symbs = read_mfix sy handle ERROR msg => err_in_mfix msg mfix;
- val args = filter (fn Argument _ => true | _ => false) raw_symbs;
- val (const', typ', parse_rules) =
- if not (exists is_index args) then (const, typ, [])
- else
- let
- val indexed_const =
- if const <> "" then const ^ "_indexed"
- else err_in_mfix "Missing constant name for indexed syntax" mfix;
- val rangeT = Term.range_type typ handle Match =>
- err_in_mfix "Missing structure argument for indexed syntax" mfix;
-
- val xs = map Ast.Variable (Name.invent_list [] "xa" (length args - 1));
- val (xs1, xs2) = chop (find_index is_index args) xs;
- val i = Ast.Variable "i";
- val lhs = Ast.mk_appl (Ast.Constant indexed_const)
- (xs1 @ [Ast.mk_appl (Ast.Constant "_index") [i]] @ xs2);
- val rhs = Ast.mk_appl (Ast.Constant const) (i :: xs);
- in (indexed_const, rangeT, [(lhs, rhs)]) end;
-
- val (symbs, lhs) = add_args raw_symbs typ' pris;
-
- val copy_prod =
- (lhs = "prop" orelse lhs = "logic")
- andalso const <> ""
- andalso not (null symbs)
- andalso not (exists is_delim symbs);
- val lhs' =
- if convert andalso not copy_prod then
- (if lhs = "prop" then sprop else if is_logtype lhs then logic else lhs)
- else lhs;
- val symbs' = map logify_types symbs;
- val xprod = XProd (lhs', symbs', const', pri);
-
- val _ = (List.app check_pri pris; check_pri pri; check_blocks symbs');
- val xprod' =
- if Lexicon.is_terminal lhs' then err_in_mfix ("Illegal lhs: " ^ lhs') mfix
- else if const <> "" then xprod
- else if length (filter is_argument symbs') <> 1 then
- err_in_mfix "Copy production must have exactly one argument" mfix
- else if exists is_terminal symbs' then xprod
- else XProd (lhs', map rem_pri symbs', "", chain_pri);
-
- in (xprod', parse_rules) end;
-
-
-
-(** datatype syn_ext **)
-
-datatype syn_ext =
- Syn_Ext of {
- xprods: xprod list,
- consts: string list,
- parse_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list,
- parse_rules: (Ast.ast * Ast.ast) list,
- parse_translation: (string * ((Proof.context -> term list -> term) * stamp)) list,
- print_translation: (string * ((Proof.context -> typ -> term list -> term) * stamp)) list,
- print_rules: (Ast.ast * Ast.ast) list,
- print_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list};
-
-
-(* syn_ext *)
-
-fun syn_ext' convert is_logtype mfixes consts trfuns (parse_rules, print_rules) =
- let
- val (parse_ast_translation, parse_translation, print_translation,
- print_ast_translation) = trfuns;
-
- val (xprods, parse_rules') = map (mfix_to_xprod convert is_logtype) mfixes
- |> split_list |> apsnd (rev o flat);
- val mfix_consts =
- distinct (op =) (map (fn Mfix x => #3 x) mfixes @ map (fn XProd x => #3 x) xprods);
- in
- Syn_Ext {
- xprods = xprods,
- consts = union (op =) consts mfix_consts,
- parse_ast_translation = parse_ast_translation,
- parse_rules = parse_rules' @ parse_rules,
- parse_translation = parse_translation,
- print_translation = print_translation,
- print_rules = map swap parse_rules' @ print_rules,
- print_ast_translation = print_ast_translation}
- end;
-
-
-val syn_ext = syn_ext' true (K false);
-
-fun syn_ext_const_names cs = syn_ext [] cs ([], [], [], []) ([], []);
-fun syn_ext_rules rules = syn_ext [] [] ([], [], [], []) rules;
-fun syn_ext_advanced_trfuns trfuns = syn_ext [] [] trfuns ([], []);
-
-fun syn_ext_trfuns (atrs, trs, tr's, atr's) =
- let fun simple (name, (f, s)) = (name, (K f, s)) in
- syn_ext_advanced_trfuns (map simple atrs, map simple trs, map simple tr's, map simple atr's)
- end;
-
-fun stamp_trfun s (c, f) = (c, (f, s));
-fun mk_trfun tr = stamp_trfun (stamp ()) tr;
-fun eq_trfun ((_, s1: stamp), (_, s2)) = s1 = s2;
-
-
-(* pure_ext *)
-
-val token_markers =
- ["_tfree", "_tvar", "_free", "_bound", "_var", "_numeral", "_inner_string"];
-
-val pure_ext = syn_ext' false (K false)
- [Mfix ("_", spropT --> propT, "", [0], 0),
- Mfix ("_", logicT --> anyT, "", [0], 0),
- Mfix ("_", spropT --> anyT, "", [0], 0),
- Mfix ("'(_')", logicT --> logicT, "", [0], max_pri),
- Mfix ("'(_')", spropT --> spropT, "", [0], max_pri),
- Mfix ("_::_", [logicT, typeT] ---> logicT, "_constrain", [4, 0], 3),
- Mfix ("_::_", [spropT, typeT] ---> spropT, "_constrain", [4, 0], 3)]
- token_markers
- ([], [], [], [])
- ([], []);
-
-end;
--- a/src/Pure/Syntax/syntax.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/Syntax/syntax.ML Fri Apr 08 15:02:11 2011 +0200
@@ -13,8 +13,9 @@
signature SYNTAX =
sig
include LEXICON0
- include SYN_EXT0
include PRINTER0
+ val max_pri: int
+ val root: string Config.T
val positions_raw: Config.raw
val positions: bool Config.T
val ambiguity_enabled: bool Config.T
@@ -146,10 +147,15 @@
structure Syntax: SYNTAX =
struct
+val max_pri = Syntax_Ext.max_pri;
+
+
(** inner syntax operations **)
(* configuration options *)
+val root = Config.string (Config.declare "syntax_root" (K (Config.String Syntax_Ext.any)));
+
val positions_raw = Config.declare "syntax_positions" (fn _ => Config.Bool true);
val positions = Config.bool positions_raw;
@@ -403,12 +409,12 @@
fun lookup_tr tab c = Option.map fst (Symtab.lookup tab c);
-fun remove_trtab trfuns = fold (Symtab.remove Syn_Ext.eq_trfun) trfuns;
+fun remove_trtab trfuns = fold (Symtab.remove Syntax_Ext.eq_trfun) trfuns;
fun update_trtab name trfuns tab = fold Symtab.update_new trfuns (remove_trtab trfuns tab)
handle Symtab.DUP c => err_dup_trfun name c;
-fun merge_trtabs name tab1 tab2 = Symtab.merge Syn_Ext.eq_trfun (tab1, tab2)
+fun merge_trtabs name tab1 tab2 = Symtab.merge Syntax_Ext.eq_trfun (tab1, tab2)
handle Symtab.DUP c => err_dup_trfun name c;
@@ -428,9 +434,9 @@
| app_first (f :: fs) = f ctxt args handle Match => app_first fs;
in app_first fns end;
-fun update_tr'tab trfuns = fold_rev (Symtab.update_list Syn_Ext.eq_trfun) trfuns;
-fun remove_tr'tab trfuns = fold (Symtab.remove_list Syn_Ext.eq_trfun) trfuns;
-fun merge_tr'tabs tab1 tab2 = Symtab.merge_list Syn_Ext.eq_trfun (tab1, tab2);
+fun update_tr'tab trfuns = fold_rev (Symtab.update_list Syntax_Ext.eq_trfun) trfuns;
+fun remove_tr'tab trfuns = fold (Symtab.remove_list Syntax_Ext.eq_trfun) trfuns;
+fun merge_tr'tabs tab1 tab2 = Symtab.merge_list Syntax_Ext.eq_trfun (tab1, tab2);
@@ -450,7 +456,7 @@
datatype syntax =
Syntax of {
- input: Syn_Ext.xprod list,
+ input: Syntax_Ext.xprod list,
lexicon: Scan.lexicon,
gram: Parser.gram,
consts: string list,
@@ -508,7 +514,7 @@
let
val {input, lexicon, gram, consts = consts1, prmodes, parse_ast_trtab, parse_ruletab,
parse_trtab, print_trtab, print_ruletab, print_ast_trtab, prtabs} = tabs;
- val Syn_Ext.Syn_Ext {xprods, consts = consts2, parse_ast_translation,
+ val Syntax_Ext.Syn_Ext {xprods, consts = consts2, parse_ast_translation,
parse_rules, parse_translation, print_translation, print_rules,
print_ast_translation} = syn_ext;
val new_xprods =
@@ -517,7 +523,7 @@
in
Syntax
({input = new_xprods @ input,
- lexicon = fold Scan.extend_lexicon (Syn_Ext.delims_of new_xprods) lexicon,
+ lexicon = fold Scan.extend_lexicon (Syntax_Ext.delims_of new_xprods) lexicon,
gram = Parser.extend_gram new_xprods gram,
consts = Library.merge (op =) (consts1, filter_out Lexicon.is_marked consts2),
prmodes = insert (op =) mode prmodes,
@@ -536,7 +542,7 @@
fun remove_syntax (mode, inout) syn_ext (Syntax (tabs, _)) =
let
- val Syn_Ext.Syn_Ext {xprods, consts = _, parse_ast_translation, parse_rules,
+ val Syntax_Ext.Syn_Ext {xprods, consts = _, parse_ast_translation, parse_rules,
parse_translation, print_translation, print_rules, print_ast_translation} = syn_ext;
val {input, lexicon, gram, consts, prmodes, parse_ast_trtab, parse_ruletab,
parse_trtab, print_trtab, print_ruletab, print_ast_trtab, prtabs} = tabs;
@@ -546,7 +552,7 @@
in
Syntax
({input = input',
- lexicon = if changed then Scan.make_lexicon (Syn_Ext.delims_of input') else lexicon,
+ lexicon = if changed then Scan.make_lexicon (Syntax_Ext.delims_of input') else lexicon,
gram = if changed then Parser.extend_gram input' Parser.empty_gram else gram,
consts = consts,
prmodes = prmodes,
@@ -593,12 +599,12 @@
(* basic syntax *)
-val basic_syntax = update_syntax mode_default Syn_Ext.pure_ext empty_syntax;
+val basic_syntax = update_syntax mode_default Syntax_Ext.pure_ext empty_syntax;
val basic_nonterms =
- (Lexicon.terminals @ [Syn_Ext.logic, "type", "types", "sort", "classes",
- Syn_Ext.args, Syn_Ext.cargs, "pttrn", "pttrns", "idt", "idts", "aprop",
- "asms", Syn_Ext.any, Syn_Ext.sprop, "num_const", "float_const", "index",
+ (Lexicon.terminals @ [Syntax_Ext.logic, "type", "types", "sort", "classes",
+ Syntax_Ext.args, Syntax_Ext.cargs, "pttrn", "pttrns", "idt", "idts", "aprop",
+ "asms", Syntax_Ext.any, Syntax_Ext.sprop, "num_const", "float_const", "index",
"struct", "id_position", "longid_position", "type_name", "class_name"]);
@@ -708,8 +714,8 @@
fun ext_syntax f decls = update_syntax mode_default (f decls);
-val update_trfuns = ext_syntax Syn_Ext.syn_ext_trfuns;
-val update_advanced_trfuns = ext_syntax Syn_Ext.syn_ext_advanced_trfuns;
+val update_trfuns = ext_syntax Syntax_Ext.syn_ext_trfuns;
+val update_advanced_trfuns = ext_syntax Syntax_Ext.syn_ext_advanced_trfuns;
fun update_type_gram add prmode decls =
(if add then update_syntax else remove_syntax) prmode (Mixfix.syn_ext_types decls);
@@ -717,13 +723,13 @@
fun update_const_gram add is_logtype prmode decls =
(if add then update_syntax else remove_syntax) prmode (Mixfix.syn_ext_consts is_logtype decls);
-val update_trrules = ext_syntax Syn_Ext.syn_ext_rules o check_rules;
-val remove_trrules = remove_syntax mode_default o Syn_Ext.syn_ext_rules o check_rules;
+val update_trrules = ext_syntax Syntax_Ext.syn_ext_rules o check_rules;
+val remove_trrules = remove_syntax mode_default o Syntax_Ext.syn_ext_rules o check_rules;
(*export parts of internal Syntax structures*)
val syntax_tokenize = tokenize;
-open Lexicon Syn_Ext Printer;
+open Lexicon Printer;
val tokenize = syntax_tokenize;
end;
@@ -731,5 +737,3 @@
structure Basic_Syntax: BASIC_SYNTAX = Syntax;
open Basic_Syntax;
-forget_structure "Syn_Ext";
-
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Pure/Syntax/syntax_ext.ML Fri Apr 08 15:02:11 2011 +0200
@@ -0,0 +1,380 @@
+(* Title: Pure/Syntax/syntax_ext.ML
+ Author: Markus Wenzel and Carsten Clasohm, TU Muenchen
+
+Syntax extension.
+*)
+
+signature SYNTAX_EXT =
+sig
+ val dddot_indexname: indexname
+ val logic: string
+ val args: string
+ val cargs: string
+ val typeT: typ
+ val any: string
+ val sprop: string
+ val spropT: typ
+ val max_pri: int
+ datatype mfix = Mfix of string * typ * string * int list * int
+ val err_in_mfix: string -> mfix -> 'a
+ val typ_to_nonterm: typ -> string
+ datatype xsymb =
+ Delim of string |
+ Argument of string * int |
+ Space of string |
+ Bg of int | Brk of int | En
+ datatype xprod = XProd of string * xsymb list * string * int
+ val chain_pri: int
+ val delims_of: xprod list -> string list list
+ datatype syn_ext =
+ Syn_Ext of {
+ xprods: xprod list,
+ consts: string list,
+ parse_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list,
+ parse_rules: (Ast.ast * Ast.ast) list,
+ parse_translation: (string * ((Proof.context -> term list -> term) * stamp)) list,
+ print_translation: (string * ((Proof.context -> typ -> term list -> term) * stamp)) list,
+ print_rules: (Ast.ast * Ast.ast) list,
+ print_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list}
+ val mfix_delims: string -> string list
+ val mfix_args: string -> int
+ val escape: string -> string
+ val syn_ext': bool -> (string -> bool) -> mfix list ->
+ string list -> (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
+ (string * ((Proof.context -> term list -> term) * stamp)) list *
+ (string * ((Proof.context -> typ -> term list -> term) * stamp)) list *
+ (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list ->
+ (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
+ val syn_ext: mfix list -> string list ->
+ (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
+ (string * ((Proof.context -> term list -> term) * stamp)) list *
+ (string * ((Proof.context -> typ -> term list -> term) * stamp)) list *
+ (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list ->
+ (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
+ val syn_ext_const_names: string list -> syn_ext
+ val syn_ext_rules: (Ast.ast * Ast.ast) list * (Ast.ast * Ast.ast) list -> syn_ext
+ val syn_ext_trfuns:
+ (string * ((Ast.ast list -> Ast.ast) * stamp)) list *
+ (string * ((term list -> term) * stamp)) list *
+ (string * ((typ -> term list -> term) * stamp)) list *
+ (string * ((Ast.ast list -> Ast.ast) * stamp)) list -> syn_ext
+ val syn_ext_advanced_trfuns:
+ (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list *
+ (string * ((Proof.context -> term list -> term) * stamp)) list *
+ (string * ((Proof.context -> typ -> term list -> term) * stamp)) list *
+ (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list -> syn_ext
+ val stamp_trfun: stamp -> string * 'a -> string * ('a * stamp)
+ val mk_trfun: string * 'a -> string * ('a * stamp)
+ val eq_trfun: ('a * stamp) * ('a * stamp) -> bool
+ val token_markers: string list
+ val pure_ext: syn_ext
+end;
+
+structure Syntax_Ext: SYNTAX_EXT =
+struct
+
+
+(** misc definitions **)
+
+val dddot_indexname = ("dddot", 0);
+
+
+(* syntactic categories *)
+
+val logic = "logic";
+val logicT = Type (logic, []);
+
+val args = "args";
+val cargs = "cargs";
+
+val typeT = Type ("type", []);
+
+val sprop = "#prop";
+val spropT = Type (sprop, []);
+
+val any = "any";
+val anyT = Type (any, []);
+
+
+
+(** datatype xprod **)
+
+(*Delim s: delimiter s
+ Argument (s, p): nonterminal s requiring priority >= p, or valued token
+ Space s: some white space for printing
+ Bg, Brk, En: blocks and breaks for pretty printing*)
+
+datatype xsymb =
+ Delim of string |
+ Argument of string * int |
+ Space of string |
+ Bg of int | Brk of int | En;
+
+fun is_delim (Delim _) = true
+ | is_delim _ = false;
+
+fun is_terminal (Delim _) = true
+ | is_terminal (Argument (s, _)) = Lexicon.is_terminal s
+ | is_terminal _ = false;
+
+fun is_argument (Argument _) = true
+ | is_argument _ = false;
+
+fun is_index (Argument ("index", _)) = true
+ | is_index _ = false;
+
+val index = Argument ("index", 1000);
+
+
+(*XProd (lhs, syms, c, p):
+ lhs: name of nonterminal on the lhs of the production
+ syms: list of symbols on the rhs of the production
+ c: head of parse tree
+ p: priority of this production*)
+
+datatype xprod = XProd of string * xsymb list * string * int;
+
+val max_pri = 1000; (*maximum legal priority*)
+val chain_pri = ~1; (*dummy for chain productions*)
+
+fun delims_of xprods =
+ fold (fn XProd (_, xsymbs, _, _) =>
+ fold (fn Delim s => insert (op =) s | _ => I) xsymbs) xprods []
+ |> map Symbol.explode;
+
+
+
+(** datatype mfix **)
+
+(*Mfix (sy, ty, c, ps, p):
+ sy: rhs of production as symbolic string
+ ty: type description of production
+ c: head of parse tree
+ ps: priorities of arguments in sy
+ p: priority of production*)
+
+datatype mfix = Mfix of string * typ * string * int list * int;
+
+fun err_in_mfix msg (Mfix (sy, _, const, _, _)) =
+ cat_error msg ("in mixfix annotation " ^ quote sy ^ " for " ^ quote const);
+
+
+(* typ_to_nonterm *)
+
+fun typ_to_nt _ (Type (c, _)) = c
+ | typ_to_nt default _ = default;
+
+(*get nonterminal for rhs*)
+val typ_to_nonterm = typ_to_nt any;
+
+(*get nonterminal for lhs*)
+val typ_to_nonterm1 = typ_to_nt logic;
+
+
+(* read mixfix annotations *)
+
+local
+
+val is_meta = member (op =) ["(", ")", "/", "_", "\\<index>"];
+
+val scan_delim_char =
+ $$ "'" |-- Scan.one ((not o Symbol.is_blank) andf Symbol.is_regular) ||
+ Scan.one ((not o is_meta) andf (not o Symbol.is_blank) andf Symbol.is_regular);
+
+fun read_int ["0", "0"] = ~1
+ | read_int cs = #1 (Library.read_int cs);
+
+val scan_sym =
+ $$ "_" >> K (Argument ("", 0)) ||
+ $$ "\\<index>" >> K index ||
+ $$ "(" |-- Scan.many Symbol.is_digit >> (Bg o read_int) ||
+ $$ ")" >> K En ||
+ $$ "/" -- $$ "/" >> K (Brk ~1) ||
+ $$ "/" |-- Scan.many Symbol.is_blank >> (Brk o length) ||
+ Scan.many1 Symbol.is_blank >> (Space o implode) ||
+ Scan.repeat1 scan_delim_char >> (Delim o implode);
+
+val scan_symb =
+ scan_sym >> SOME ||
+ $$ "'" -- Scan.one Symbol.is_blank >> K NONE;
+
+val scan_symbs = Scan.repeat scan_symb --| Scan.ahead (~$$ "'");
+val read_symbs = map_filter I o the o Scan.read Symbol.stopper scan_symbs;
+
+fun unique_index xsymbs =
+ if length (filter is_index xsymbs) <= 1 then xsymbs
+ else error "Duplicate index arguments (\\<index>)";
+
+in
+
+val read_mfix = unique_index o read_symbs o Symbol.explode;
+
+fun mfix_delims sy = fold_rev (fn Delim s => cons s | _ => I) (read_mfix sy) [];
+val mfix_args = length o filter is_argument o read_mfix;
+
+val escape = implode o map (fn s => if is_meta s then "'" ^ s else s) o Symbol.explode;
+
+end;
+
+
+(* mfix_to_xprod *)
+
+fun mfix_to_xprod convert is_logtype (mfix as Mfix (sy, typ, const, pris, pri)) =
+ let
+ fun check_pri p =
+ if p >= 0 andalso p <= max_pri then ()
+ else err_in_mfix ("Precedence out of range: " ^ string_of_int p) mfix;
+
+ fun blocks_ok [] 0 = true
+ | blocks_ok [] _ = false
+ | blocks_ok (Bg _ :: syms) n = blocks_ok syms (n + 1)
+ | blocks_ok (En :: _) 0 = false
+ | blocks_ok (En :: syms) n = blocks_ok syms (n - 1)
+ | blocks_ok (_ :: syms) n = blocks_ok syms n;
+
+ fun check_blocks syms =
+ if blocks_ok syms 0 then ()
+ else err_in_mfix "Unbalanced block parentheses" mfix;
+
+
+ val cons_fst = apfst o cons;
+
+ fun add_args [] ty [] = ([], typ_to_nonterm1 ty)
+ | add_args [] _ _ = err_in_mfix "Too many precedences" mfix
+ | add_args ((arg as Argument ("index", _)) :: syms) ty ps =
+ cons_fst arg (add_args syms ty ps)
+ | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) [] =
+ cons_fst (Argument (typ_to_nonterm ty, 0)) (add_args syms tys [])
+ | add_args (Argument _ :: syms) (Type ("fun", [ty, tys])) (p :: ps) =
+ cons_fst (Argument (typ_to_nonterm ty, p)) (add_args syms tys ps)
+ | add_args (Argument _ :: _) _ _ =
+ err_in_mfix "More arguments than in corresponding type" mfix
+ | add_args (sym :: syms) ty ps = cons_fst sym (add_args syms ty ps);
+
+ fun rem_pri (Argument (s, _)) = Argument (s, chain_pri)
+ | rem_pri sym = sym;
+
+ fun logify_types (a as (Argument (s, p))) =
+ if s <> "prop" andalso is_logtype s then Argument (logic, p) else a
+ | logify_types a = a;
+
+
+ val raw_symbs = read_mfix sy handle ERROR msg => err_in_mfix msg mfix;
+ val args = filter (fn Argument _ => true | _ => false) raw_symbs;
+ val (const', typ', parse_rules) =
+ if not (exists is_index args) then (const, typ, [])
+ else
+ let
+ val indexed_const =
+ if const <> "" then const ^ "_indexed"
+ else err_in_mfix "Missing constant name for indexed syntax" mfix;
+ val rangeT = Term.range_type typ handle Match =>
+ err_in_mfix "Missing structure argument for indexed syntax" mfix;
+
+ val xs = map Ast.Variable (Name.invent_list [] "xa" (length args - 1));
+ val (xs1, xs2) = chop (find_index is_index args) xs;
+ val i = Ast.Variable "i";
+ val lhs = Ast.mk_appl (Ast.Constant indexed_const)
+ (xs1 @ [Ast.mk_appl (Ast.Constant "_index") [i]] @ xs2);
+ val rhs = Ast.mk_appl (Ast.Constant const) (i :: xs);
+ in (indexed_const, rangeT, [(lhs, rhs)]) end;
+
+ val (symbs, lhs) = add_args raw_symbs typ' pris;
+
+ val copy_prod =
+ (lhs = "prop" orelse lhs = "logic")
+ andalso const <> ""
+ andalso not (null symbs)
+ andalso not (exists is_delim symbs);
+ val lhs' =
+ if convert andalso not copy_prod then
+ (if lhs = "prop" then sprop else if is_logtype lhs then logic else lhs)
+ else lhs;
+ val symbs' = map logify_types symbs;
+ val xprod = XProd (lhs', symbs', const', pri);
+
+ val _ = (List.app check_pri pris; check_pri pri; check_blocks symbs');
+ val xprod' =
+ if Lexicon.is_terminal lhs' then err_in_mfix ("Illegal lhs: " ^ lhs') mfix
+ else if const <> "" then xprod
+ else if length (filter is_argument symbs') <> 1 then
+ err_in_mfix "Copy production must have exactly one argument" mfix
+ else if exists is_terminal symbs' then xprod
+ else XProd (lhs', map rem_pri symbs', "", chain_pri);
+
+ in (xprod', parse_rules) end;
+
+
+
+(** datatype syn_ext **)
+
+datatype syn_ext =
+ Syn_Ext of {
+ xprods: xprod list,
+ consts: string list,
+ parse_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list,
+ parse_rules: (Ast.ast * Ast.ast) list,
+ parse_translation: (string * ((Proof.context -> term list -> term) * stamp)) list,
+ print_translation: (string * ((Proof.context -> typ -> term list -> term) * stamp)) list,
+ print_rules: (Ast.ast * Ast.ast) list,
+ print_ast_translation: (string * ((Proof.context -> Ast.ast list -> Ast.ast) * stamp)) list};
+
+
+(* syn_ext *)
+
+fun syn_ext' convert is_logtype mfixes consts trfuns (parse_rules, print_rules) =
+ let
+ val (parse_ast_translation, parse_translation, print_translation,
+ print_ast_translation) = trfuns;
+
+ val (xprods, parse_rules') = map (mfix_to_xprod convert is_logtype) mfixes
+ |> split_list |> apsnd (rev o flat);
+ val mfix_consts =
+ distinct (op =) (map (fn Mfix x => #3 x) mfixes @ map (fn XProd x => #3 x) xprods);
+ in
+ Syn_Ext {
+ xprods = xprods,
+ consts = union (op =) consts mfix_consts,
+ parse_ast_translation = parse_ast_translation,
+ parse_rules = parse_rules' @ parse_rules,
+ parse_translation = parse_translation,
+ print_translation = print_translation,
+ print_rules = map swap parse_rules' @ print_rules,
+ print_ast_translation = print_ast_translation}
+ end;
+
+
+val syn_ext = syn_ext' true (K false);
+
+fun syn_ext_const_names cs = syn_ext [] cs ([], [], [], []) ([], []);
+fun syn_ext_rules rules = syn_ext [] [] ([], [], [], []) rules;
+fun syn_ext_advanced_trfuns trfuns = syn_ext [] [] trfuns ([], []);
+
+fun syn_ext_trfuns (atrs, trs, tr's, atr's) =
+ let fun simple (name, (f, s)) = (name, (K f, s)) in
+ syn_ext_advanced_trfuns (map simple atrs, map simple trs, map simple tr's, map simple atr's)
+ end;
+
+fun stamp_trfun s (c, f) = (c, (f, s));
+fun mk_trfun tr = stamp_trfun (stamp ()) tr;
+fun eq_trfun ((_, s1: stamp), (_, s2)) = s1 = s2;
+
+
+(* pure_ext *)
+
+val token_markers =
+ ["_tfree", "_tvar", "_free", "_bound", "_var", "_numeral", "_inner_string"];
+
+val pure_ext = syn_ext' false (K false)
+ [Mfix ("_", spropT --> propT, "", [0], 0),
+ Mfix ("_", logicT --> anyT, "", [0], 0),
+ Mfix ("_", spropT --> anyT, "", [0], 0),
+ Mfix ("'(_')", logicT --> logicT, "", [0], max_pri),
+ Mfix ("'(_')", spropT --> spropT, "", [0], max_pri),
+ Mfix ("_::_", [logicT, typeT] ---> logicT, "_constrain", [4, 0], 3),
+ Mfix ("_::_", [spropT, typeT] ---> spropT, "_constrain", [4, 0], 3)]
+ token_markers
+ ([], [], [], [])
+ ([], []);
+
+end;
--- a/src/Pure/Syntax/syntax_phases.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/Syntax/syntax_phases.ML Fri Apr 08 15:02:11 2011 +0200
@@ -330,7 +330,7 @@
val (markup, kind, root, constrain) =
if is_prop
then (Markup.prop, "proposition", "prop", Type.constraint propT)
- else (Markup.term, "term", Config.get ctxt Syntax.default_root, I);
+ else (Markup.term, "term", Config.get ctxt Syntax.root, I);
val (syms, pos) = Syntax.parse_token ctxt markup text;
in
let
@@ -491,7 +491,7 @@
val {structs, fixes} = idents;
fun mark_atoms ((t as Const (c, _)) $ u) =
- if member (op =) Syntax.token_markers c
+ if member (op =) Syntax_Ext.token_markers c
then t $ u else mark_atoms t $ mark_atoms u
| mark_atoms (t $ u) = mark_atoms t $ mark_atoms u
| mark_atoms (Abs (x, T, t)) = Abs (x, T, mark_atoms t)
@@ -507,7 +507,7 @@
else Lexicon.const "_free" $ t
end
| mark_atoms (t as Var (xi, T)) =
- if xi = Syntax.dddot_indexname then Const ("_DDDOT", T)
+ if xi = Syntax_Ext.dddot_indexname then Const ("_DDDOT", T)
else Lexicon.const "_var" $ t
| mark_atoms a = a;
--- a/src/Pure/Syntax/syntax_trans.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/Syntax/syntax_trans.ML Fri Apr 08 15:02:11 2011 +0200
@@ -185,7 +185,7 @@
(* dddot *)
-fun dddot_tr ts = Term.list_comb (Lexicon.var Syn_Ext.dddot_indexname, ts);
+fun dddot_tr ts = Term.list_comb (Lexicon.var Syntax_Ext.dddot_indexname, ts);
(* quote / antiquote *)
--- a/src/Pure/pure_thy.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/pure_thy.ML Fri Apr 08 15:02:11 2011 +0200
@@ -19,8 +19,8 @@
val tycon = Syntax.mark_type;
val const = Syntax.mark_const;
-val typeT = Syntax.typeT;
-val spropT = Syntax.spropT;
+val typeT = Syntax_Ext.typeT;
+val spropT = Syntax_Ext.spropT;
(* application syntax variants *)
--- a/src/Pure/sign.ML Fri Apr 08 14:20:57 2011 +0200
+++ b/src/Pure/sign.ML Fri Apr 08 15:02:11 2011 +0200
@@ -468,7 +468,7 @@
local
-fun mk trs = map Syntax.mk_trfun trs;
+fun mk trs = map Syntax_Ext.mk_trfun trs;
fun gen_add_trfuns ext non_typed (atrs, trs, tr's, atr's) =
map_syn (ext (mk atrs, mk trs, mk (map (apsnd non_typed) tr's), mk atr's));