src/Pure/Isar/term_syntax.ML
changeset 21730 88d8b4052792
parent 21706 e811cf937c64
equal deleted inserted replaced
21729:7b3ccdae9212 21730:88d8b4052792
     6 *)
     6 *)
     7 
     7 
     8 signature TERM_SYNTAX =
     8 signature TERM_SYNTAX =
     9 sig
     9 sig
    10   val notation: Syntax.mode -> (term * mixfix) list -> local_theory -> local_theory
    10   val notation: Syntax.mode -> (term * mixfix) list -> local_theory -> local_theory
    11   val abbrevs: Syntax.mode -> ((bstring * mixfix) * term) list -> local_theory -> local_theory
    11   val abbrev: Syntax.mode -> (bstring * mixfix) * term -> local_theory -> local_theory
    12 end;
    12 end;
    13 
    13 
    14 structure TermSyntax: TERM_SYNTAX =
    14 structure TermSyntax: TERM_SYNTAX =
    15 struct
    15 struct
    16 
    16 
    43           if rhs aconv rhs' then target_notation prmode [(Const lhs, mx)] Morphism.identity
    43           if rhs aconv rhs' then target_notation prmode [(Const lhs, mx)] Morphism.identity
    44           else I)
    44           else I)
    45     else I
    45     else I
    46   end;
    46   end;
    47 
    47 
    48 fun abbrevs prmode raw_args lthy =
    48 fun abbrev prmode raw_arg lthy =
    49   let
    49   let
    50     val is_local = is_none o Sign.const_constraint (ProofContext.theory_of lthy);
    50     val is_local = is_none o Sign.const_constraint (ProofContext.theory_of lthy);
    51     val local_term = Term.exists_subterm (fn Const (c, _) => is_local c | _ => false);
    51     val local_term = Term.exists_subterm (fn Const (c, _) => is_local c | _ => false);
    52     val input_only = (#1 Syntax.input_mode, #2 prmode);
    52     val input_only = (#1 Syntax.input_mode, #2 prmode);
    53     val expand = ProofContext.cert_term (ProofContext.expand_abbrevs true lthy);
    53     val expand = ProofContext.cert_term (ProofContext.set_expand_abbrevs true lthy);
    54     val args = raw_args |> map (morph_abbrev (LocalTheory.target_morphism lthy) #>
    54     val arg = raw_arg |> (morph_abbrev (LocalTheory.target_morphism lthy) #>
    55       (fn (lhs, rhs) =>  (*avoid dynamic references to local names*)
    55       (fn (lhs, rhs) =>  (*avoid dynamic references to local names*)
    56         if local_term rhs then (input_only, (lhs, expand rhs))
    56         if local_term rhs then (input_only, (lhs, expand rhs))
    57         else (prmode, (lhs, rhs))));
    57         else (prmode, (lhs, rhs))));
    58   in LocalTheory.term_syntax (fn phi => fold (fn arg => target_abbrev arg phi) args) lthy end;
    58   in LocalTheory.term_syntax (fn phi => target_abbrev arg phi) lthy end;
    59 
    59 
    60 end;
    60 end;