src/FOL/ex/NewLocaleSetup.thy
author ballarin
Thu, 11 Dec 2008 17:56:34 +0100
changeset 29210 4025459e3f83
parent 29034 3dc51c01f9f3
child 29211 ab99da3854af
permissions -rw-r--r--
Interpretation in theories: first version with equations.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     1
(*  Title:      FOL/ex/NewLocaleSetup.thy
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     2
    Author:     Clemens Ballarin, TU Muenchen
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     3
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     4
Testing environment for locale expressions --- experimental.
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     5
*)
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     6
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     7
theory NewLocaleSetup
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     8
imports FOL
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
     9
begin
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    10
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    11
ML {*
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    12
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    13
local
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    14
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    15
structure P = OuterParse and K = OuterKeyword;
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    16
val opt_bang = Scan.optional (P.$$$ "!" >> K true) false;
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    17
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    18
val locale_val =
29033
721529248e31 Enable keyword 'structure' in for clause of locale expression.
ballarin
parents: 29018
diff changeset
    19
  SpecParse.locale_expression --
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    20
    Scan.optional (P.$$$ "+" |-- P.!!! (Scan.repeat1 SpecParse.context_element)) [] ||
28887
6f28fa3bc430 Expression types cleaned up.
ballarin
parents: 28873
diff changeset
    21
  Scan.repeat1 SpecParse.context_element >> pair ([], []);
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    22
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    23
in
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    24
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    25
val _ =
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    26
  OuterSyntax.command "locale" "define named proof context" K.thy_decl
28887
6f28fa3bc430 Expression types cleaned up.
ballarin
parents: 28873
diff changeset
    27
    (P.name -- Scan.optional (P.$$$ "=" |-- P.!!! locale_val) (([], []), []) -- P.opt_begin
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    28
      >> (fn ((name, (expr, elems)), begin) =>
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    29
          (begin ? Toplevel.print) o Toplevel.begin_local_theory begin
29028
b5dad96c755a When adding locales, delay notes until local theory is built.
ballarin
parents: 29018
diff changeset
    30
            (Expression.add_locale_cmd name name expr elems #>
b5dad96c755a When adding locales, delay notes until local theory is built.
ballarin
parents: 29018
diff changeset
    31
              (fn ((target, notes), ctxt) => TheoryTarget.begin target ctxt |>
b5dad96c755a When adding locales, delay notes until local theory is built.
ballarin
parents: 29018
diff changeset
    32
                fold (fn (kind, facts) => LocalTheory.notes kind facts #> snd) notes))));
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    33
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    34
val _ =
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    35
  OuterSyntax.improper_command "print_locales" "print locales of this theory" K.diag
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    36
    (Scan.succeed (Toplevel.no_timing o (Toplevel.unknown_theory o
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    37
  Toplevel.keep (NewLocale.print_locales o Toplevel.theory_of))));
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    38
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    39
val _ = OuterSyntax.improper_command "print_locale" "print named locale in this theory" K.diag
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    40
  (opt_bang -- P.xname >> (Toplevel.no_timing oo (fn (show_facts, name) =>
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    41
   Toplevel.unknown_theory o Toplevel.keep (fn state =>
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    42
     NewLocale.print_locale (Toplevel.theory_of state) show_facts name))));
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    43
28993
829e684b02ef Interpretation in theories including interaction with subclass relation.
ballarin
parents: 28902
diff changeset
    44
val _ =
829e684b02ef Interpretation in theories including interaction with subclass relation.
ballarin
parents: 28902
diff changeset
    45
  OuterSyntax.command "interpretation"
29018
17538bdef546 Interpretation in proof contexts.
ballarin
parents: 28993
diff changeset
    46
    "prove interpretation of locale expression in theory" K.thy_goal
29210
4025459e3f83 Interpretation in theories: first version with equations.
ballarin
parents: 29034
diff changeset
    47
    (P.!!! SpecParse.locale_expression --
4025459e3f83 Interpretation in theories: first version with equations.
ballarin
parents: 29034
diff changeset
    48
      Scan.optional (P.$$$ "where" |-- P.and_list1 (P.alt_string >> Facts.Fact ||
4025459e3f83 Interpretation in theories: first version with equations.
ballarin
parents: 29034
diff changeset
    49
    P.position P.xname -- Scan.option Attrib.thm_sel >> Facts.Named)) []
4025459e3f83 Interpretation in theories: first version with equations.
ballarin
parents: 29034
diff changeset
    50
        >> (fn (expr, mixin) => Toplevel.print o
4025459e3f83 Interpretation in theories: first version with equations.
ballarin
parents: 29034
diff changeset
    51
            Toplevel.theory_to_proof (Expression.interpretation_cmd expr mixin)));
28993
829e684b02ef Interpretation in theories including interaction with subclass relation.
ballarin
parents: 28902
diff changeset
    52
29018
17538bdef546 Interpretation in proof contexts.
ballarin
parents: 28993
diff changeset
    53
val _ =
17538bdef546 Interpretation in proof contexts.
ballarin
parents: 28993
diff changeset
    54
  OuterSyntax.command "interpret"
17538bdef546 Interpretation in proof contexts.
ballarin
parents: 28993
diff changeset
    55
    "prove interpretation of locale expression in proof context"
17538bdef546 Interpretation in proof contexts.
ballarin
parents: 28993
diff changeset
    56
    (K.tag_proof K.prf_goal)
29033
721529248e31 Enable keyword 'structure' in for clause of locale expression.
ballarin
parents: 29018
diff changeset
    57
    (P.!!! SpecParse.locale_expression
29018
17538bdef546 Interpretation in proof contexts.
ballarin
parents: 28993
diff changeset
    58
        >> (fn expr => Toplevel.print o
17538bdef546 Interpretation in proof contexts.
ballarin
parents: 28993
diff changeset
    59
            Toplevel.proof' (fn int => Expression.interpret_cmd expr int)));
17538bdef546 Interpretation in proof contexts.
ballarin
parents: 28993
diff changeset
    60
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    61
end
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    62
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    63
*}
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    64
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    65
end