src/Pure/Isar/args.ML
author wenzelm
Sat, 21 Jan 2006 23:02:14 +0100
changeset 18728 6790126ab5f6
parent 18635 58bbff56a914
child 18998 10c251f29847
permissions -rw-r--r--
simplified type attribute;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/args.ML
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
     4
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
     5
Concrete argument syntax of attributes, methods etc. -- with special
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
     6
support for embedded values and static binding.
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
     7
*)
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
     8
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
     9
signature ARGS =
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    10
sig
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18635
diff changeset
    11
  datatype value =
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18635
diff changeset
    12
    Name of string | Typ of typ | Term of term | Fact of thm list | Attribute of attribute
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    13
  type T
9748
67486cf2f8f6 added string_of;
wenzelm
parents: 9538
diff changeset
    14
  val string_of: T -> string
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    15
  val mk_ident: string * Position.T -> T
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    16
  val mk_string: string * Position.T -> T
18037
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
    17
  val mk_alt_string: string * Position.T -> T
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    18
  val mk_keyword: string * Position.T -> T
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    19
  val mk_name: string -> T
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    20
  val mk_typ: typ -> T
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    21
  val mk_term: term -> T
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    22
  val mk_fact: thm list -> T
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18635
diff changeset
    23
  val mk_attribute: attribute -> T
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    24
  val stopper: T * (T -> bool)
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    25
  val not_eof: T -> bool
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    26
  type src
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    27
  val src: (string * T list) * Position.T -> src
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    28
  val dest_src: src -> (string * T list) * Position.T
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    29
  val map_name: (string -> string) -> src -> src
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    30
  val map_values: (string -> string) -> (typ -> typ) -> (term -> term) -> (thm -> thm)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    31
    -> src -> src
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    32
  val assignable: src -> src
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    33
  val assign: value option -> T -> unit
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    34
  val closure: src -> src
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
    35
  val position: (T list -> 'a * 'b) -> T list -> ('a * Position.T) * 'b
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
    36
  val !!! : (T list -> 'a) -> T list -> 'a
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    37
  val $$$ : string -> T list -> string * T list
10035
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
    38
  val add: T list -> string * T list
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
    39
  val del: T list -> string * T list
8803
wenzelm
parents: 8687
diff changeset
    40
  val colon: T list -> string * T list
10035
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
    41
  val query: T list -> string * T list
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
    42
  val bang: T list -> string * T list
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
    43
  val query_colon: T list -> string * T list
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
    44
  val bang_colon: T list -> string * T list
8803
wenzelm
parents: 8687
diff changeset
    45
  val parens: (T list -> 'a * T list) -> T list -> 'a * T list
10150
a068c666c53e added "bracks";
wenzelm
parents: 10035
diff changeset
    46
  val bracks: (T list -> 'a * T list) -> T list -> 'a * T list
9809
58e9d55a9f88 added mode parser;
wenzelm
parents: 9748
diff changeset
    47
  val mode: string -> 'a * T list -> bool * ('a * T list)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    48
  val maybe: (T list -> 'a * T list) -> T list -> 'a option * T list
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    49
  val name: T list -> string * T list
18037
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
    50
  val alt_name: T list -> string * T list
16140
fc51e61d45fb added symbol scanner;
wenzelm
parents: 15987
diff changeset
    51
  val symbol: T list -> string * T list
17064
2fae6579fb2e added liberal_name;
wenzelm
parents: 16343
diff changeset
    52
  val liberal_name: T list -> string * T list
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
    53
  val nat: T list -> int * T list
9538
3af720af9cd9 added int;
wenzelm
parents: 9504
diff changeset
    54
  val int: T list -> int * T list
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
    55
  val var: T list -> indexname * T list
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    56
  val list: (T list -> 'a * T list) -> T list -> 'a list * T list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    57
  val list1: (T list -> 'a * T list) -> T list -> 'a list * T list
6447
83d8dabdae9a lifted enum;
wenzelm
parents: 5934
diff changeset
    58
  val enum: string -> ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list)
83d8dabdae9a lifted enum;
wenzelm
parents: 5934
diff changeset
    59
  val enum1: string -> ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list)
83d8dabdae9a lifted enum;
wenzelm
parents: 5934
diff changeset
    60
  val and_list: ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list)
83d8dabdae9a lifted enum;
wenzelm
parents: 5934
diff changeset
    61
  val and_list1: ('a * T list -> 'b * ('a * T list)) -> 'a * T list -> 'b list * ('a * T list)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    62
  val ahead: T list -> T * T list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    63
  val internal_name: T list -> string * T list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    64
  val internal_typ: T list -> typ * T list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    65
  val internal_term: T list -> term * T list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    66
  val internal_fact: T list -> thm list * T list
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18635
diff changeset
    67
  val internal_attribute: T list -> attribute * T list
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    68
  val named_name: (string -> string) -> T list -> string * T list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    69
  val named_typ: (string -> typ) -> T list -> typ * T list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    70
  val named_term: (string -> term) -> T list -> term * T list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    71
  val named_fact: (string -> thm list) -> T list -> thm list * T list
16343
7c7120469f0d renamed global/local_typ_raw to global/local_typ_abbrev;
wenzelm
parents: 16140
diff changeset
    72
  val global_typ_abbrev: theory * T list -> typ * (theory * T list)
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
    73
  val global_typ: theory * T list -> typ * (theory * T list)
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
    74
  val global_term: theory * T list -> term * (theory * T list)
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
    75
  val global_prop: theory * T list -> term * (theory * T list)
16343
7c7120469f0d renamed global/local_typ_raw to global/local_typ_abbrev;
wenzelm
parents: 16140
diff changeset
    76
  val local_typ_abbrev: ProofContext.context * T list -> typ * (ProofContext.context * T list)
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    77
  val local_typ: ProofContext.context * T list -> typ * (ProofContext.context * T list)
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    78
  val local_term: ProofContext.context * T list -> term * (ProofContext.context * T list)
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    79
  val local_prop: ProofContext.context * T list -> term * (ProofContext.context * T list)
18635
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
    80
  val typ_abbrev: Context.generic * T list -> typ * (Context.generic * T list)
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
    81
  val typ: Context.generic * T list -> typ * (Context.generic * T list)
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
    82
  val term: Context.generic * T list -> term * (Context.generic * T list)
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
    83
  val prop: Context.generic * T list -> term * (Context.generic * T list)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    84
  val global_tyname: theory * T list -> string * (theory * T list)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    85
  val global_const: theory * T list -> string * (theory * T list)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    86
  val local_tyname: ProofContext.context * T list -> string * (ProofContext.context * T list)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    87
  val local_const: ProofContext.context * T list -> string * (ProofContext.context * T list)
18635
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
    88
  val tyname: Context.generic * T list -> string * (Context.generic * T list)
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
    89
  val const: Context.generic * T list -> string * (Context.generic * T list)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    90
  val thm_sel: T list -> PureThy.interval list * T list
15596
8665d08085df First version of global registration command.
ballarin
parents: 15570
diff changeset
    91
  val bang_facts: ProofContext.context * T list -> thm list * (ProofContext.context * T list)
8536
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
    92
  val goal_spec: ((int -> tactic) -> tactic) -> ('a * T list)
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
    93
    -> ((int -> tactic) -> tactic) * ('a * T list)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    94
  val attribs: (string -> string) -> T list -> src list * T list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    95
  val opt_attribs: (string -> string) -> T list -> src list * T list
8282
58a33fd5b30c tuned syntax wrapper;
wenzelm
parents: 8233
diff changeset
    96
  val syntax: string -> ('a * T list -> 'b * ('a * T list)) -> src -> 'a -> 'a * 'b
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    97
  val pretty_src: ProofContext.context -> src -> Pretty.T
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    98
  val pretty_attribs: ProofContext.context -> src list -> Pretty.T list
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    99
end;
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   100
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   101
structure Args: ARGS =
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   102
struct
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   103
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   104
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   105
(** datatype T **)
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   106
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   107
(*An argument token is a symbol (with raw string value), together with
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   108
  an optional assigned internal value.  Note that an assignable ref
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   109
  designates an intermediate state of internalization -- it is NOT
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   110
  meant to persist.*)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   111
18037
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
   112
datatype kind = Ident | String | AltString | Keyword | EOF;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   113
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   114
type symbol = kind * string * Position.T;
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   115
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   116
datatype value =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   117
  Name of string |
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   118
  Typ of typ |
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   119
  Term of term |
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   120
  Fact of thm list |
18728
6790126ab5f6 simplified type attribute;
wenzelm
parents: 18635
diff changeset
   121
  Attribute of attribute;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   122
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   123
datatype slot =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   124
  Empty |
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   125
  Value of value option |
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   126
  Assignable of value option ref;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   127
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   128
datatype T = Arg of symbol * slot;
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   129
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   130
fun string_of (Arg ((Ident, x, _), _)) = x
18037
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
   131
  | string_of (Arg ((String, x, _), _)) = quote x
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
   132
  | string_of (Arg ((AltString, x, _), _)) = enclose "`" "`" x
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   133
  | string_of (Arg ((Keyword, x, _), _)) = x
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   134
  | string_of (Arg ((EOF, _, _), _)) = "";
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   135
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   136
fun sym_of (Arg ((_, x, _), _)) = x;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   137
fun pos_of (Arg ((_, _, pos), _)) = pos;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   138
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   139
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   140
(* basic constructors *)
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   141
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   142
fun mk_symbol k (x, p) = Arg ((k, x, p), Empty);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   143
fun mk_value k v = Arg ((Keyword, k, Position.none), Value (SOME v));
9748
67486cf2f8f6 added string_of;
wenzelm
parents: 9538
diff changeset
   144
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   145
val mk_ident = mk_symbol Ident;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   146
val mk_string = mk_symbol String;
18037
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
   147
val mk_alt_string = mk_symbol AltString;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   148
val mk_keyword = mk_symbol Keyword;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   149
val mk_name = mk_value "<name>" o Name;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   150
val mk_typ = mk_value "<typ>" o Typ;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   151
val mk_term = mk_value "<term>" o Term;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   152
val mk_fact = mk_value "<fact>" o Fact;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   153
val mk_attribute = mk_value "<attribute>" o Attribute;
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   154
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   155
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   156
(* eof *)
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   157
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   158
val eof = mk_symbol EOF ("", Position.none);
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   159
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   160
fun is_eof (Arg ((EOF, _, _), _)) = true
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   161
  | is_eof _ = false;
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   162
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   163
val stopper = (eof, is_eof);
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   164
val not_eof = not o is_eof;
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   165
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   166
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   167
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   168
(** datatype src **)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   169
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   170
datatype src = Src of (string * T list) * Position.T;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   171
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   172
val src = Src;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   173
fun dest_src (Src src) = src;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   174
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   175
fun map_name f (Src ((s, args), pos)) = Src ((f s, args), pos);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   176
fun map_args f (Src ((s, args), pos)) = Src ((s, map f args), pos);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   177
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   178
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   179
(* values *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   180
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   181
fun map_value f (Arg (s, Value (SOME v))) = Arg (s, Value (SOME (f v)))
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   182
  | map_value _ arg = arg;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   183
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   184
fun map_values f g h i = map_args (map_value
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   185
  (fn Name s => Name (f s)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   186
    | Typ T => Typ (g T)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   187
    | Term t => Term (h t)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   188
    | Fact ths => Fact (map i ths)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   189
    | Attribute att => Attribute att));
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   190
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   191
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   192
(* static binding *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   193
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   194
(*1st stage: make empty slots assignable*)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   195
val assignable =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   196
  map_args (fn Arg (s, Empty) => Arg (s, Assignable (ref NONE)) | arg => arg);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   197
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   198
(*2nd stage: assign values as side-effect of scanning*)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   199
fun assign v (arg as Arg (_, Assignable r)) = r := v
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   200
  | assign _ _ = ();
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   201
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   202
val ahead = Scan.ahead (Scan.one not_eof);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   203
fun touch scan = ahead -- scan >> (fn (arg, y) => (assign NONE arg; y));
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   204
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   205
(*3rd stage: static closure of final values*)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   206
val closure =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   207
  map_args (fn Arg (s, Assignable (ref v)) => Arg (s, Value v) | arg => arg);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   208
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   209
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   210
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   211
(** scanners **)
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   212
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   213
(* position *)
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   214
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   215
fun position scan =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   216
  (Scan.ahead (Scan.one not_eof) >> pos_of) -- scan >> Library.swap;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   217
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   218
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   219
(* cut *)
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   220
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   221
fun !!! scan =
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   222
  let
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   223
    fun get_pos [] = " (past end-of-text!)"
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   224
      | get_pos (arg :: _) = Position.str_of (pos_of arg);
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   225
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   226
    fun err (args, NONE) = "Argument syntax error" ^ get_pos args
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   227
      | err (args, SOME msg) = "Argument syntax error" ^ get_pos args ^ ": " ^ msg;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   228
  in Scan.!! err scan end;
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   229
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   230
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   231
(* basic *)
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   232
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   233
fun some_ident f =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   234
  touch (Scan.some (fn Arg ((Ident, x, _), _) => f x | _ => NONE));
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   235
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   236
val named =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   237
  touch (Scan.one (fn Arg ((k, _, _), _) => k = Ident orelse k = String));
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   238
18037
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
   239
val alt_string =
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
   240
  touch (Scan.one (fn Arg ((k, _, _), _) => k = AltString));
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
   241
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   242
val symbolic =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   243
  touch (Scan.one (fn Arg ((k, x, _), _) => k = Keyword andalso OuterLex.is_sid x));
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   244
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   245
fun &&& x =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   246
  touch (Scan.one (fn Arg ((k, y, _), _) => k = Keyword andalso x = y));
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   247
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   248
fun $$$ x =
16140
fc51e61d45fb added symbol scanner;
wenzelm
parents: 15987
diff changeset
   249
  touch (Scan.one (fn Arg ((k, y, _), _) => (k = Ident orelse k = Keyword) andalso x = y))
fc51e61d45fb added symbol scanner;
wenzelm
parents: 15987
diff changeset
   250
  >> sym_of;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   251
10035
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   252
val add = $$$ "add";
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   253
val del = $$$ "del";
8803
wenzelm
parents: 8687
diff changeset
   254
val colon = $$$ ":";
10035
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   255
val query = $$$ "?";
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   256
val bang = $$$ "!";
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   257
val query_colon = $$$ "?:";
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   258
val bang_colon = $$$ "!:";
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   259
8803
wenzelm
parents: 8687
diff changeset
   260
fun parens scan = $$$ "(" |-- scan --| $$$ ")";
10150
a068c666c53e added "bracks";
wenzelm
parents: 10035
diff changeset
   261
fun bracks scan = $$$ "[" |-- scan --| $$$ "]";
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   262
fun mode s = Scan.lift (Scan.optional (parens ($$$ s) >> K true) false);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   263
fun maybe scan = $$$ "_" >> K NONE || scan >> SOME;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   264
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   265
val name = named >> sym_of;
18037
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
   266
val alt_name = alt_string >> sym_of;
16140
fc51e61d45fb added symbol scanner;
wenzelm
parents: 15987
diff changeset
   267
val symbol = symbolic >> sym_of;
17064
2fae6579fb2e added liberal_name;
wenzelm
parents: 16343
diff changeset
   268
val liberal_name = symbol || name;
8233
85169951d515 attrib: keyword_symid;
wenzelm
parents: 8089
diff changeset
   269
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   270
val nat = some_ident Syntax.read_nat;
9538
3af720af9cd9 added int;
wenzelm
parents: 9504
diff changeset
   271
val int = Scan.optional ($$$ "-" >> K ~1) 1 -- nat >> op *;
15987
35ec4802c66c Syntax.read_variable;
wenzelm
parents: 15726
diff changeset
   272
val var = some_ident Syntax.read_variable;
14563
wenzelm
parents: 14174
diff changeset
   273
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   274
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   275
(* enumerations *)
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   276
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   277
fun list1 scan = scan -- Scan.repeat ($$$ "," |-- scan) >> op ::;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   278
fun list scan = list1 scan || Scan.succeed [];
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   279
6447
83d8dabdae9a lifted enum;
wenzelm
parents: 5934
diff changeset
   280
fun enum1 sep scan = scan -- Scan.repeat (Scan.lift ($$$ sep) |-- scan) >> op ::;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   281
fun enum sep scan = enum1 sep scan || Scan.succeed [];
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   282
6447
83d8dabdae9a lifted enum;
wenzelm
parents: 5934
diff changeset
   283
fun and_list1 scan = enum1 "and" scan;
83d8dabdae9a lifted enum;
wenzelm
parents: 5934
diff changeset
   284
fun and_list scan = enum "and" scan;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   285
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   286
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   287
(* values *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   288
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   289
fun value dest = Scan.some  (*no touch here*)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   290
  (fn Arg (_, Value (SOME v)) => (SOME (dest v) handle Match => NONE)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   291
    | Arg _ => NONE);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   292
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   293
fun evaluate mk eval arg =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   294
  let val x = eval (sym_of arg) in (assign (SOME (mk x)) arg; x) end;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   295
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   296
val internal_name = value (fn Name s => s);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   297
val internal_typ = value (fn Typ T => T);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   298
val internal_term = value (fn Term t => t);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   299
val internal_fact = value (fn Fact ths => ths);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   300
val internal_attribute = value (fn Attribute att => att);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   301
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   302
fun named_name intern = internal_name || named >> evaluate Name intern;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   303
fun named_typ readT = internal_typ || named >> evaluate Typ readT;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   304
fun named_term read = internal_term || named >> evaluate Term read;
18037
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17104
diff changeset
   305
fun named_fact get = internal_fact || (alt_string || named) >> evaluate Fact get;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   306
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   307
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   308
(* terms and types *)
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   309
16343
7c7120469f0d renamed global/local_typ_raw to global/local_typ_abbrev;
wenzelm
parents: 16140
diff changeset
   310
val global_typ_abbrev = Scan.peek (named_typ o ProofContext.read_typ_abbrev o ProofContext.init);
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   311
val global_typ = Scan.peek (named_typ o ProofContext.read_typ o ProofContext.init);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   312
val global_term = Scan.peek (named_term o ProofContext.read_term o ProofContext.init);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   313
val global_prop = Scan.peek (named_term o ProofContext.read_prop o ProofContext.init);
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   314
16343
7c7120469f0d renamed global/local_typ_raw to global/local_typ_abbrev;
wenzelm
parents: 16140
diff changeset
   315
val local_typ_abbrev = Scan.peek (named_typ o ProofContext.read_typ_abbrev);
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   316
val local_typ = Scan.peek (named_typ o ProofContext.read_typ);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   317
val local_term = Scan.peek (named_term o ProofContext.read_term);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   318
val local_prop = Scan.peek (named_term o ProofContext.read_prop);
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   319
18635
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   320
val typ_abbrev = Scan.peek (named_typ o ProofContext.read_typ_abbrev o Context.proof_of);
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   321
val typ = Scan.peek (named_typ o ProofContext.read_typ o Context.proof_of);
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   322
val term = Scan.peek (named_term o ProofContext.read_term o Context.proof_of);
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   323
val prop = Scan.peek (named_term o ProofContext.read_prop o Context.proof_of);
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   324
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   325
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   326
(* type and constant names *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   327
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   328
val dest_tyname = fn Type (c, _) => c | TFree (a, _) => a | _ => "";
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   329
val dest_const = fn Const (c, _) => c | Free (x, _) => x | _ => "";
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   330
17104
89d5bbb2f746 removed obsolete Theory.sign_of;
wenzelm
parents: 17064
diff changeset
   331
val global_tyname = Scan.peek (named_typ o Sign.read_tyname) >> dest_tyname;
89d5bbb2f746 removed obsolete Theory.sign_of;
wenzelm
parents: 17064
diff changeset
   332
val global_const = Scan.peek (named_term o Sign.read_const) >> dest_const;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   333
val local_tyname = Scan.peek (named_typ o ProofContext.read_tyname) >> dest_tyname;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   334
val local_const = Scan.peek (named_term o ProofContext.read_const) >> dest_const;
18635
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   335
val tyname =
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   336
  Scan.peek (named_typ o Context.cases Sign.read_tyname ProofContext.read_tyname) >> dest_tyname;
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   337
val const =
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   338
  Scan.peek (named_term o Context.cases Sign.read_const ProofContext.read_const) >> dest_const;
7553
af3a1fe87c42 added bang_facts;
wenzelm
parents: 6447
diff changeset
   339
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   340
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   341
(* misc *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   342
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   343
val thm_sel = parens (list1
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   344
 (nat --| $$$ "-" -- nat >> PureThy.FromTo ||
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   345
  nat --| $$$ "-" >> PureThy.From ||
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   346
  nat >> PureThy.Single));
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   347
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   348
val bang_facts = Scan.peek (fn ctxt =>
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   349
  $$$ "!" >> K (ProofContext.prems_of ctxt) || Scan.succeed []);
7553
af3a1fe87c42 added bang_facts;
wenzelm
parents: 6447
diff changeset
   350
af3a1fe87c42 added bang_facts;
wenzelm
parents: 6447
diff changeset
   351
8536
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
   352
(* goal specification *)
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
   353
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
   354
(* range *)
8233
85169951d515 attrib: keyword_symid;
wenzelm
parents: 8089
diff changeset
   355
8536
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
   356
val from_to =
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   357
  nat -- ($$$ "-" |-- nat) >> (fn (i, j) => fn tac => Seq.INTERVAL tac i j) ||
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   358
  nat --| $$$ "-" >> (fn i => fn tac => fn st => Seq.INTERVAL tac i (Thm.nprems_of st) st) ||
8549
851d39c10d9f goal_spec: [!];
wenzelm
parents: 8536
diff changeset
   359
  nat >> (fn i => fn tac => tac i) ||
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   360
  $$$ "!" >> K ALLGOALS;
8536
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
   361
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   362
val goal = $$$ "[" |-- !!! (from_to --| $$$ "]");
8536
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
   363
fun goal_spec def = Scan.lift (Scan.optional goal def);
8233
85169951d515 attrib: keyword_symid;
wenzelm
parents: 8089
diff changeset
   364
85169951d515 attrib: keyword_symid;
wenzelm
parents: 8089
diff changeset
   365
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   366
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   367
(* attribs *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   368
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   369
local
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   370
9126
ca8c6793dca5 removed obsolete "{}";
wenzelm
parents: 8896
diff changeset
   371
val exclude = explode "()[],";
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   372
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   373
fun atomic blk = touch (Scan.one (fn Arg ((k, x, _), _) =>
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   374
    k <> Keyword orelse not (x mem exclude) orelse blk andalso x = ","));
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   375
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   376
fun args blk x = Scan.optional (args1 blk) [] x
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   377
and args1 blk x =
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   378
  ((Scan.repeat1
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   379
    (Scan.repeat1 (atomic blk) ||
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   380
      argsp "(" ")" ||
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   381
      argsp "[" "]")) >> List.concat) x
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   382
and argsp l r x =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   383
  (Scan.trace (&&& l -- !!! (args true -- &&& r)) >> #2) x;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   384
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   385
in
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   386
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   387
fun attribs intern =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   388
  let
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   389
    val attrib_name = internal_name || (symbolic || named) >> evaluate Name intern;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   390
    val attrib = position (attrib_name -- !!! (args false)) >> src;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   391
  in $$$ "[" |-- !!! (list attrib --| $$$ "]") end;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   392
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   393
fun opt_attribs intern = Scan.optional (attribs intern) [];
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   394
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   395
end;
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   396
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   397
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   398
(* syntax interface *)
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   399
8282
58a33fd5b30c tuned syntax wrapper;
wenzelm
parents: 8233
diff changeset
   400
fun syntax kind scan (src as Src ((s, args), pos)) st =
9901
09a142decdda avoid handle_error (better msgs);
wenzelm
parents: 9809
diff changeset
   401
  (case Scan.error (Scan.finite' stopper (Scan.option scan)) (st, args) of
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 14981
diff changeset
   402
    (SOME x, (st', [])) => (st', x)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   403
  | (_, (_, args')) =>
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   404
      error (kind ^ " " ^ quote s ^ Position.str_of pos ^ ": bad arguments\n  " ^
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   405
        space_implode " " (map string_of args')));
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   406
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   407
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   408
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   409
(** pretty printing **)
6447
83d8dabdae9a lifted enum;
wenzelm
parents: 5934
diff changeset
   410
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   411
fun pretty_src ctxt src =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   412
  let
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   413
    fun prt (Arg (_, Value (SOME (Name s)))) = Pretty.str (quote s)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   414
      | prt (Arg (_, Value (SOME (Typ T)))) = ProofContext.pretty_typ ctxt T
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   415
      | prt (Arg (_, Value (SOME (Term t)))) = ProofContext.pretty_term ctxt t
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   416
      | prt (Arg (_, Value (SOME (Fact ths)))) = ProofContext.pretty_thms ctxt ths
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   417
      | prt arg = Pretty.str (string_of arg);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   418
    val (s, args) = #1 (dest_src src);
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   419
  in Pretty.block (Pretty.breaks (Pretty.str s :: map prt args)) end;
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   420
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   421
fun pretty_attribs _ [] = []
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   422
  | pretty_attribs ctxt srcs =
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   423
      [Pretty.enclose "[" "]" (Pretty.commas (map (pretty_src ctxt) srcs))];
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   424
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   425
end;