src/Pure/Isar/auto_bind.ML
author wenzelm
Thu, 06 Jun 2024 22:26:40 +0200
changeset 80274 cff00b3dddf5
parent 62763 3e9a68bd30a7
child 81279 d2e39f0f9b40
permissions -rw-r--r--
clarified names;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6783
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/auto_bind.ML
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
     3
17349
03fafcdfdfa7 added cases, rule_contextN;
wenzelm
parents: 15531
diff changeset
     4
Automatic bindings of Isar text elements.
6783
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
     5
*)
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
     6
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
     7
signature AUTO_BIND =
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
     8
sig
9296
0d2b31e1ea1b export thesisN separately;
wenzelm
parents: 8807
diff changeset
     9
  val thesisN: string
17349
03fafcdfdfa7 added cases, rule_contextN;
wenzelm
parents: 15531
diff changeset
    10
  val thisN: string
60448
78f3c67bc35e support for 'consider' command;
wenzelm
parents: 60414
diff changeset
    11
  val thatN: string
21448
09c953c07008 added assmsN;
wenzelm
parents: 19075
diff changeset
    12
  val assmsN: string
60408
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60401
diff changeset
    13
  val abs_params: term -> term -> term
59970
e9f73d87d904 proper context for Object_Logic operations;
wenzelm
parents: 46219
diff changeset
    14
  val goal: Proof.context -> term list -> (indexname * term option) list
62763
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    15
  val dddot: indexname
59970
e9f73d87d904 proper context for Object_Logic operations;
wenzelm
parents: 46219
diff changeset
    16
  val facts: Proof.context -> term list -> (indexname * term option) list
60401
16cf5090d3a6 clarified term bindings;
wenzelm
parents: 59970
diff changeset
    17
  val no_facts: indexname list
6783
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
    18
end;
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
    19
33386
ff29d1549aca modernized structure AutoBind;
wenzelm
parents: 29606
diff changeset
    20
structure Auto_Bind: AUTO_BIND =
6783
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
    21
struct
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
    22
10359
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    23
(** bindings **)
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    24
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    25
val thesisN = "thesis";
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    26
val thisN = "this";
60448
78f3c67bc35e support for 'consider' command;
wenzelm
parents: 60414
diff changeset
    27
val thatN = "that";
21448
09c953c07008 added assmsN;
wenzelm
parents: 19075
diff changeset
    28
val assmsN = "assms";
10359
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    29
59970
e9f73d87d904 proper context for Object_Logic operations;
wenzelm
parents: 46219
diff changeset
    30
fun strip_judgment ctxt = Object_Logic.drop_judgment ctxt o Logic.strip_assums_concl;
11764
fd780dd6e0b4 use ObjectLogic;
wenzelm
parents: 10808
diff changeset
    31
60408
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60401
diff changeset
    32
fun abs_params prop = fold_rev Term.abs (Logic.strip_params prop);
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60401
diff changeset
    33
59970
e9f73d87d904 proper context for Object_Logic operations;
wenzelm
parents: 46219
diff changeset
    34
fun statement_binds ctxt name prop =
60408
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60401
diff changeset
    35
  [((name, 0), SOME (abs_params prop (strip_judgment ctxt prop)))];
10359
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    36
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    37
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    38
(* goal *)
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    39
59970
e9f73d87d904 proper context for Object_Logic operations;
wenzelm
parents: 46219
diff changeset
    40
fun goal ctxt [prop] = statement_binds ctxt thesisN prop
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    41
  | goal _ _ = [((thesisN, 0), NONE)];
10359
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    42
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    43
62763
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    44
(* dddot *)
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    45
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    46
val dddot = ("dddot", 0);
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    47
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    48
val _ =
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    49
  Theory.setup (Sign.parse_translation
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    50
    [("_DDDOT", fn _ => fn ts => Term.list_comb (Syntax.var dddot, ts))]);
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    51
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    52
10359
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    53
(* facts *)
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    54
59970
e9f73d87d904 proper context for Object_Logic operations;
wenzelm
parents: 46219
diff changeset
    55
fun get_arg ctxt prop =
e9f73d87d904 proper context for Object_Logic operations;
wenzelm
parents: 46219
diff changeset
    56
  (case strip_judgment ctxt prop of
60408
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60401
diff changeset
    57
    _ $ t => SOME (abs_params prop t)
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
    58
  | _ => NONE);
10359
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    59
60408
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60401
diff changeset
    60
fun facts ctxt props =
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60401
diff changeset
    61
  (case try List.last props of
1fd46ced2fa8 more uniform treatment of auto bindings vs. explicit user bindings;
wenzelm
parents: 60401
diff changeset
    62
    NONE => []
62763
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    63
  | SOME prop => [(dddot, get_arg ctxt prop)] @ statement_binds ctxt thisN prop);
10359
445e3b87f28b improved statement bindings for props;
wenzelm
parents: 9464
diff changeset
    64
62763
3e9a68bd30a7 clarified modules;
wenzelm
parents: 60449
diff changeset
    65
val no_facts = [dddot, (thisN, 0)];
10808
cc4a3ed7e70b added drop_judgment;
wenzelm
parents: 10377
diff changeset
    66
6783
9cf9c17d9e35 renamed object_logic.ML to Isar/auto_bind.ML and tuned this module;
wenzelm
parents:
diff changeset
    67
end;