539 | mark Ts (t as t1 $ t2) = |
539 | mark Ts (t as t1 $ t2) = |
540 (if is_Const (Term.head_of t) orelse not (is_prop Ts t) then I else aprop) |
540 (if is_Const (Term.head_of t) orelse not (is_prop Ts t) then I else aprop) |
541 (mark Ts t1 $ mark Ts t2); |
541 (mark Ts t1 $ mark Ts t2); |
542 in mark [] tm end; |
542 in mark [] tm end; |
543 |
543 |
544 in |
544 fun prune_types ctxt tm = |
545 |
545 let |
546 fun term_to_ast idents is_syntax_const ctxt trf tm = |
|
547 let |
|
548 val show_types = Config.get ctxt show_types orelse Config.get ctxt show_sorts; |
|
549 val show_structs = Config.get ctxt show_structs; |
|
550 val show_free_types = Config.get ctxt show_free_types; |
546 val show_free_types = Config.get ctxt show_free_types; |
551 val show_markup = Config.get ctxt show_markup; |
547 |
552 |
548 fun prune (t_seen as (Const _, _)) = t_seen |
553 val {structs, fixes} = idents; |
549 | prune (t as Free (x, ty), seen) = |
554 |
|
555 fun prune_typs (t_seen as (Const _, _)) = t_seen |
|
556 | prune_typs (t as Free (x, ty), seen) = |
|
557 if ty = dummyT then (t, seen) |
550 if ty = dummyT then (t, seen) |
558 else if not show_free_types orelse member (op aconv) seen t then (Syntax.free x, seen) |
551 else if not show_free_types orelse member (op aconv) seen t then (Syntax.free x, seen) |
559 else (t, t :: seen) |
552 else (t, t :: seen) |
560 | prune_typs (t as Var (xi, ty), seen) = |
553 | prune (t as Var (xi, ty), seen) = |
561 if ty = dummyT then (t, seen) |
554 if ty = dummyT then (t, seen) |
562 else if not show_free_types orelse member (op aconv) seen t then (Syntax.var xi, seen) |
555 else if not show_free_types orelse member (op aconv) seen t then (Syntax.var xi, seen) |
563 else (t, t :: seen) |
556 else (t, t :: seen) |
564 | prune_typs (t_seen as (Bound _, _)) = t_seen |
557 | prune (t_seen as (Bound _, _)) = t_seen |
565 | prune_typs (Abs (x, ty, t), seen) = |
558 | prune (Abs (x, ty, t), seen) = |
566 let val (t', seen') = prune_typs (t, seen); |
559 let val (t', seen') = prune (t, seen); |
567 in (Abs (x, ty, t'), seen') end |
560 in (Abs (x, ty, t'), seen') end |
568 | prune_typs (t1 $ t2, seen) = |
561 | prune (t1 $ t2, seen) = |
569 let |
562 let |
570 val (t1', seen') = prune_typs (t1, seen); |
563 val (t1', seen') = prune (t1, seen); |
571 val (t2', seen'') = prune_typs (t2, seen'); |
564 val (t2', seen'') = prune (t2, seen'); |
572 in (t1' $ t2', seen'') end; |
565 in (t1' $ t2', seen'') end; |
573 |
566 in #1 (prune (tm, [])) end; |
574 fun mark_atoms ((t as Const (c, _)) $ u) = |
567 |
|
568 fun mark_atoms {structs, fixes} is_syntax_const ctxt tm = |
|
569 let |
|
570 val show_structs = Config.get ctxt show_structs; |
|
571 |
|
572 fun mark ((t as Const (c, _)) $ u) = |
575 if member (op =) Pure_Thy.token_markers c |
573 if member (op =) Pure_Thy.token_markers c |
576 then t $ u else mark_atoms t $ mark_atoms u |
574 then t $ u else mark t $ mark u |
577 | mark_atoms (t $ u) = mark_atoms t $ mark_atoms u |
575 | mark (t $ u) = mark t $ mark u |
578 | mark_atoms (Abs (x, T, t)) = Abs (x, T, mark_atoms t) |
576 | mark (Abs (x, T, t)) = Abs (x, T, mark t) |
579 | mark_atoms (t as Const (c, T)) = |
577 | mark (t as Const (c, T)) = |
580 if is_syntax_const c then t |
578 if is_syntax_const c then t |
581 else Const (Lexicon.mark_const c, T) |
579 else Const (Lexicon.mark_const c, T) |
582 | mark_atoms (t as Free (x, T)) = |
580 | mark (t as Free (x, T)) = |
583 let val i = find_index (fn s => s = x) structs + 1 in |
581 let val i = find_index (fn s => s = x) structs + 1 in |
584 if i = 0 andalso member (op =) fixes x then |
582 if i = 0 andalso member (op =) fixes x then |
585 Const (Lexicon.mark_fixed x, T) |
583 Const (Lexicon.mark_fixed x, T) |
586 else if i = 1 andalso not show_structs then |
584 else if i = 1 andalso not show_structs then |
587 Syntax.const "_struct" $ Syntax.const "_indexdefault" |
585 Syntax.const "_struct" $ Syntax.const "_indexdefault" |
588 else Syntax.const "_free" $ t |
586 else Syntax.const "_free" $ t |
589 end |
587 end |
590 | mark_atoms (t as Var (xi, T)) = |
588 | mark (t as Var (xi, T)) = |
591 if xi = Syntax_Ext.dddot_indexname then Const ("_DDDOT", T) |
589 if xi = Syntax_Ext.dddot_indexname then Const ("_DDDOT", T) |
592 else Syntax.const "_var" $ t |
590 else Syntax.const "_var" $ t |
593 | mark_atoms a = a; |
591 | mark a = a; |
|
592 in mark tm end; |
|
593 |
|
594 in |
|
595 |
|
596 fun term_to_ast idents is_syntax_const ctxt trf tm = |
|
597 let |
|
598 val show_types = Config.get ctxt show_types orelse Config.get ctxt show_sorts; |
|
599 val show_markup = Config.get ctxt show_markup; |
594 |
600 |
595 fun ast_of tm = |
601 fun ast_of tm = |
596 (case strip_comb tm of |
602 (case strip_comb tm of |
597 (t as Abs _, ts) => Ast.mk_appl (ast_of (Syntax_Trans.abs_tr' ctxt t)) (map ast_of ts) |
603 (t as Abs _, ts) => Ast.mk_appl (ast_of (Syntax_Trans.abs_tr' ctxt t)) (map ast_of ts) |
598 | ((c as Const ("_free", _)), Free (x, T) :: ts) => |
604 | ((c as Const ("_free", _)), Free (x, T) :: ts) => |