src/Pure/Syntax/syn_trans.ML
changeset 42048 afd11ca8e018
parent 42045 fda09013c496
child 42053 006095137a81
equal deleted inserted replaced
42047:a7a4e04b5386 42048:afd11ca8e018
    53   include SYN_TRANS1
    53   include SYN_TRANS1
    54   val abs_tr': Proof.context -> term -> term
    54   val abs_tr': Proof.context -> term -> term
    55   val prop_tr': term -> term
    55   val prop_tr': term -> term
    56   val appl_ast_tr': Ast.ast * Ast.ast list -> Ast.ast
    56   val appl_ast_tr': Ast.ast * Ast.ast list -> Ast.ast
    57   val applC_ast_tr': Ast.ast * Ast.ast list -> Ast.ast
    57   val applC_ast_tr': Ast.ast * Ast.ast list -> Ast.ast
    58   val parsetree_to_ast: Proof.context ->
    58   val parsetree_to_ast: Proof.context -> bool ->
    59     (string -> (Proof.context -> Ast.ast list -> Ast.ast) option) -> Parser.parsetree -> Ast.ast
    59     (string -> (Proof.context -> Ast.ast list -> Ast.ast) option) -> Parser.parsetree -> Ast.ast
    60   val ast_to_term: Proof.context ->
    60   val ast_to_term: Proof.context ->
    61     (string -> (Proof.context -> term list -> term) option) -> Ast.ast -> term
    61     (string -> (Proof.context -> term list -> term) option) -> Ast.ast -> term
    62 end;
    62 end;
    63 
    63 
    96   | lambda_ast_tr (*"_lambda"*) asts = raise Ast.AST ("lambda_ast_tr", asts);
    96   | lambda_ast_tr (*"_lambda"*) asts = raise Ast.AST ("lambda_ast_tr", asts);
    97 
    97 
    98 val constrainAbsC = "_constrainAbs";
    98 val constrainAbsC = "_constrainAbs";
    99 
    99 
   100 fun absfree_proper (x, T, t) =
   100 fun absfree_proper (x, T, t) =
   101   if can Name.dest_internal x then error ("Illegal internal variable in abstraction: " ^ quote x)
   101   if can Name.dest_internal x
       
   102   then error ("Illegal internal variable in abstraction: " ^ quote x)
   102   else Term.absfree (x, T, t);
   103   else Term.absfree (x, T, t);
   103 
   104 
   104 fun abs_tr (*"_abs"*) [Free (x, T), t] = absfree_proper (x, T, t)
   105 fun abs_tr [Free (x, T), t] = absfree_proper (x, T, t)
   105   | abs_tr (*"_abs"*) [Const ("_idtdummy", T), t] = Term.absdummy (T, t)
   106   | abs_tr [Const ("_idtdummy", T), t] = Term.absdummy (T, t)
   106   | abs_tr (*"_abs"*) [Const ("_constrain", _) $ Free (x, T) $ tT, t] =
   107   | abs_tr [Const ("_constrain", _) $ x $ tT, t] = Lexicon.const constrainAbsC $ abs_tr [x, t] $ tT
   107       Lexicon.const constrainAbsC $ absfree_proper (x, T, t) $ tT
   108   | abs_tr ts = raise TERM ("abs_tr", ts);
   108   | abs_tr (*"_abs"*) [Const ("_constrain", _) $ Const ("_idtdummy", T) $ tT, t] =
       
   109       Lexicon.const constrainAbsC $ Term.absdummy (T, t) $ tT
       
   110   | abs_tr (*"_abs"*) ts = raise TERM ("abs_tr", ts);
       
   111 
   109 
   112 
   110 
   113 (* binder *)
   111 (* binder *)
   114 
   112 
   115 fun mk_binder_tr (syn, name) =
   113 fun mk_binder_tr (syn, name) =
   116   let
   114   let
   117     fun tr (Free (x, T), t) = Lexicon.const name $ absfree_proper (x, T, t)
   115     fun binder_tr [Const ("_idts", _) $ idt $ idts, t] = binder_tr [idt, binder_tr [idts, t]]
   118       | tr (Const ("_idtdummy", T), t) = Lexicon.const name $ Term.absdummy (T, t)
   116       | binder_tr [x, t] =
   119       | tr (Const ("_constrain", _) $ Free (x, T) $ tT, t) =
   117           let val abs = abs_tr [x, t] handle TERM _ => raise TERM ("binder_tr", [x, t])
   120           Lexicon.const name $ (Lexicon.const constrainAbsC $ absfree_proper (x, T, t) $ tT)
   118           in Lexicon.const name $ abs end
   121       | tr (Const ("_constrain", _) $ Const ("_idtdummy", T) $ tT, t) =
       
   122           Lexicon.const name $ (Lexicon.const constrainAbsC $ Term.absdummy (T, t) $ tT)
       
   123       | tr (Const ("_idts", _) $ idt $ idts, t) = tr (idt, tr (idts, t))
       
   124       | tr (t1, t2) = raise TERM ("binder_tr", [t1, t2]);
       
   125 
       
   126     fun binder_tr [idts, body] = tr (idts, body)
       
   127       | binder_tr ts = raise TERM ("binder_tr", ts);
   119       | binder_tr ts = raise TERM ("binder_tr", ts);
   128   in (syn, binder_tr) end;
   120   in (syn, binder_tr) end;
   129 
   121 
   130 
   122 
   131 (* type propositions *)
   123 (* type propositions *)
   531 
   523 
   532 
   524 
   533 
   525 
   534 (** parsetree_to_ast **)
   526 (** parsetree_to_ast **)
   535 
   527 
   536 fun parsetree_to_ast ctxt trf =
   528 fun parsetree_to_ast ctxt constrain_pos trf =
   537   let
   529   let
   538     fun trans a args =
   530     fun trans a args =
   539       (case trf a of
   531       (case trf a of
   540         NONE => Ast.mk_appl (Ast.Constant a) args
   532         NONE => Ast.mk_appl (Ast.Constant a) args
   541       | SOME f => f ctxt args);
   533       | SOME f => f ctxt args);
   542 
   534 
   543     fun ast_of (Parser.Node (a, pts)) = trans a (map ast_of pts)
   535     fun ast_of (Parser.Node ("_constrain_position", [pt as Parser.Tip tok])) =
       
   536           if constrain_pos then
       
   537             Ast.Appl [Ast.Constant "_constrain", ast_of pt,
       
   538               Ast.Variable (Lexicon.encode_position (Lexicon.pos_of_token tok))]
       
   539           else ast_of pt
       
   540       | ast_of (Parser.Node (a, pts)) = trans a (map ast_of pts)
   544       | ast_of (Parser.Tip tok) = Ast.Variable (Lexicon.str_of_token tok);
   541       | ast_of (Parser.Tip tok) = Ast.Variable (Lexicon.str_of_token tok);
   545   in ast_of end;
   542   in ast_of end;
   546 
   543 
   547 
   544 
   548 
   545