src/FOL/ex/NewLocaleSetup.thy
author ballarin
Fri, 05 Dec 2008 11:26:07 +0100
changeset 28993 829e684b02ef
parent 28902 2019bcc9d8bf
child 29018 17538bdef546
permissions -rw-r--r--
Interpretation in theories including interaction with subclass relation.
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 =
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    19
  Expression.parse_expression --
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
28902
2019bcc9d8bf Ahere to modern naming conventions; proper treatment of internal vs external names.
ballarin
parents: 28887
diff changeset
    30
            (Expression.add_locale_cmd name name expr elems #-> TheoryTarget.begin)));
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    31
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    32
val _ =
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    33
  OuterSyntax.improper_command "print_locales" "print locales of this theory" K.diag
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    34
    (Scan.succeed (Toplevel.no_timing o (Toplevel.unknown_theory o
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    35
  Toplevel.keep (NewLocale.print_locales o Toplevel.theory_of))));
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    36
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    37
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
    38
  (opt_bang -- P.xname >> (Toplevel.no_timing oo (fn (show_facts, name) =>
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    39
   Toplevel.unknown_theory o Toplevel.keep (fn state =>
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    40
     NewLocale.print_locale (Toplevel.theory_of state) show_facts name))));
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    41
28993
829e684b02ef Interpretation in theories including interaction with subclass relation.
ballarin
parents: 28902
diff changeset
    42
val _ =
829e684b02ef Interpretation in theories including interaction with subclass relation.
ballarin
parents: 28902
diff changeset
    43
  OuterSyntax.command "interpretation"
829e684b02ef Interpretation in theories including interaction with subclass relation.
ballarin
parents: 28902
diff changeset
    44
    "prove and register interpretation of locale expression in theory" K.thy_goal
829e684b02ef Interpretation in theories including interaction with subclass relation.
ballarin
parents: 28902
diff changeset
    45
    (P.!!! Expression.parse_expression
829e684b02ef Interpretation in theories including interaction with subclass relation.
ballarin
parents: 28902
diff changeset
    46
        >> (fn expr => Toplevel.print o
829e684b02ef Interpretation in theories including interaction with subclass relation.
ballarin
parents: 28902
diff changeset
    47
            Toplevel.theory_to_proof (Expression.interpretation_cmd expr)));
829e684b02ef Interpretation in theories including interaction with subclass relation.
ballarin
parents: 28902
diff changeset
    48
28873
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    49
end
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    50
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    51
*}
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    52
2058a6b0eb20 Regression tests for new locale implementation.
ballarin
parents:
diff changeset
    53
end