src/Pure/Syntax/printer.ML
changeset 14696 e862cc138e9c
parent 14176 716fec31f9ea
child 14783 e7f7ed4c06f2
equal deleted inserted replaced
14695:9c78044b99c3 14696:e862cc138e9c
   109   | mark_freevars (t as Var (xi, T)) =
   109   | mark_freevars (t as Var (xi, T)) =
   110       if xi = SynExt.dddot_indexname then Const ("_DDDOT", T)
   110       if xi = SynExt.dddot_indexname then Const ("_DDDOT", T)
   111       else Lexicon.const "_var" $ t
   111       else Lexicon.const "_var" $ t
   112   | mark_freevars a = a;
   112   | mark_freevars a = a;
   113 
   113 
   114 fun ast_of_term trf show_const_types no_freeTs show_types show_sorts tm =
   114 fun ast_of_term trf show_all_types no_freeTs show_types show_sorts tm =
   115   let
   115   let
   116     fun prune_typs (t_seen as (Const _, _)) = t_seen
   116     fun prune_typs (t_seen as (Const _, _)) = t_seen
   117       | prune_typs (t as Free (x, ty), seen) =
   117       | prune_typs (t as Free (x, ty), seen) =
   118           if ty = dummyT then (t, seen)
   118           if ty = dummyT then (t, seen)
   119           else if no_freeTs orelse t mem seen then (Lexicon.free x, seen)
   119           else if no_freeTs orelse t mem seen then (Lexicon.free x, seen)
   140       | ((c as Const ("_bound", _)), Free (x, T) :: ts) =>
   140       | ((c as Const ("_bound", _)), Free (x, T) :: ts) =>
   141           Ast.mk_appl (constrain (c $ Lexicon.free x) T) (map ast_of ts)
   141           Ast.mk_appl (constrain (c $ Lexicon.free x) T) (map ast_of ts)
   142       | ((c as Const ("_var", _)), Var (xi, T) :: ts) =>
   142       | ((c as Const ("_var", _)), Var (xi, T) :: ts) =>
   143           Ast.mk_appl (constrain (c $ Lexicon.var xi) T) (map ast_of ts)
   143           Ast.mk_appl (constrain (c $ Lexicon.var xi) T) (map ast_of ts)
   144       | (c' as Const (c, T), ts) =>
   144       | (c' as Const (c, T), ts) =>
   145 	if show_const_types
   145           if show_all_types
   146 	then Ast.mk_appl (constrain c' T) (map ast_of ts)
   146           then Ast.mk_appl (constrain c' T) (map ast_of ts)
   147 	else trans c T ts
   147           else trans c T ts
   148       | (t, ts) => Ast.mk_appl (simple_ast_of t) (map ast_of ts))
   148       | (t, ts) => Ast.mk_appl (simple_ast_of t) (map ast_of ts))
   149 
   149 
   150     and trans a T args =
   150     and trans a T args =
   151       ast_of (apply_trans "print translation" a (apply_typed show_sorts T (trf a)) args)
   151       ast_of (apply_trans "print translation" a (apply_typed show_sorts T (trf a)) args)
   152         handle Match => Ast.mk_appl (Ast.Constant a) (map ast_of args)
   152         handle Match => Ast.mk_appl (Ast.Constant a) (map ast_of args)
   163     |> mark_freevars
   163     |> mark_freevars
   164     |> ast_of
   164     |> ast_of
   165   end;
   165   end;
   166 
   166 
   167 fun term_to_ast trf tm =
   167 fun term_to_ast trf tm =
   168   ast_of_term trf (! show_all_types) (! show_no_free_types) (! show_types orelse ! show_sorts orelse ! show_all_types)
   168   ast_of_term trf (! show_all_types) (! show_no_free_types)
   169     (! show_sorts) tm;
   169     (! show_types orelse ! show_sorts orelse ! show_all_types) (! show_sorts) tm;
   170 
   170 
   171 
   171 
   172 
   172 
   173 (** type prtabs **)
   173 (** type prtabs **)
   174 
   174 
   329                 astT (appT (splitT n ([c], args)), p)
   329                 astT (appT (splitT n ([c], args)), p)
   330               else prnt (prnps, tbs);
   330               else prnt (prnps, tbs);
   331       in
   331       in
   332         (case token_trans a args of     (*try token translation function*)
   332         (case token_trans a args of     (*try token translation function*)
   333           Some s_len => [Pretty.raw_str s_len]
   333           Some s_len => [Pretty.raw_str s_len]
   334         | None =>			(*try print translation functions*)
   334         | None =>                       (*try print translation functions*)
   335             astT (trans a (trf a) args, p) handle Match => prnt ([], tabs))
   335             astT (trans a (trf a) args, p) handle Match => prnt ([], tabs))
   336       end
   336       end
   337 
   337 
   338     and astT (c as Ast.Constant a, p) = combT (c, a, [], p)
   338     and astT (c as Ast.Constant a, p) = combT (c, a, [], p)
   339       | astT (Ast.Variable x, _) = [Pretty.str x]
   339       | astT (Ast.Variable x, _) = [Pretty.str x]