src/Pure/Isar/args.ML
author wenzelm
Wed, 09 Apr 2014 20:58:32 +0200
changeset 56500 90f17a04567d
parent 56499 7e0178c84994
child 57942 e5bec882fdd0
permissions -rw-r--r--
proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
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
    Author:     Markus Wenzel, TU Muenchen
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
     3
35013
f3d491658893 fixed spelling;
wenzelm
parents: 33550
diff changeset
     4
Parsing with implicit value assignment.  Concrete argument syntax of
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
     5
attributes, methods etc.
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
     6
*)
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
signature ARGS =
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
     9
sig
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    10
  type src
56029
8bedca4bd5a3 clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents: 56028
diff changeset
    11
  val src: xstring * Position.T -> Token.T list -> src
8bedca4bd5a3 clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents: 56028
diff changeset
    12
  val name_of_src: src -> string * Position.T
56033
513c2b0ea565 more markup;
wenzelm
parents: 56032
diff changeset
    13
  val range_of_src: src -> Position.T
56028
422024102d9d tuned signature;
wenzelm
parents: 56027
diff changeset
    14
  val unparse_src: src -> string list
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    15
  val pretty_src: Proof.context -> src -> Pretty.T
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    16
  val check_src: Proof.context -> 'a Name_Space.table -> src -> src * 'a
45290
f599ac41e7f5 tuned signature -- refined terminology;
wenzelm
parents: 44357
diff changeset
    17
  val transform_values: morphism -> src -> src
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
    18
  val init_assignable: src -> src
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    19
  val closure: src -> src
30513
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    20
  val context: Proof.context context_parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    21
  val theory: theory context_parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    22
  val $$$ : string -> string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    23
  val add: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    24
  val del: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    25
  val colon: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    26
  val query: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    27
  val bang: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    28
  val query_colon: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    29
  val bang_colon: string parser
53168
d998de7f0efc tuned signature;
wenzelm
parents: 53113
diff changeset
    30
  val parens: 'a parser -> 'a parser
d998de7f0efc tuned signature;
wenzelm
parents: 53113
diff changeset
    31
  val bracks: 'a parser -> 'a parser
d998de7f0efc tuned signature;
wenzelm
parents: 53113
diff changeset
    32
  val mode: string -> bool parser
30513
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    33
  val maybe: 'a parser -> 'a option parser
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
    34
  val cartouche_inner_syntax: string parser
55828
42ac3cfb89f6 clarified language markup: added "delimited" property;
wenzelm
parents: 55745
diff changeset
    35
  val cartouche_source_position: Symbol_Pos.source parser
56500
90f17a04567d proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents: 56499
diff changeset
    36
  val text_source_position: Symbol_Pos.source parser
90f17a04567d proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents: 56499
diff changeset
    37
  val text: string parser
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
    38
  val name_inner_syntax: string parser
55828
42ac3cfb89f6 clarified language markup: added "delimited" property;
wenzelm
parents: 55745
diff changeset
    39
  val name_source_position: Symbol_Pos.source parser
30513
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    40
  val name: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    41
  val binding: binding parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    42
  val alt_name: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    43
  val symbol: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    44
  val liberal_name: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    45
  val var: indexname parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    46
  val internal_text: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    47
  val internal_typ: typ parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    48
  val internal_term: term parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    49
  val internal_fact: thm list parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    50
  val internal_attribute: (morphism -> attribute) parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    51
  val named_text: (string -> string) -> string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    52
  val named_typ: (string -> typ) -> typ parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    53
  val named_term: (string -> term) -> term parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    54
  val named_fact: (string -> thm list) -> thm list parser
42464
ae16b8abf1a8 proper binding/report of defined simprocs;
wenzelm
parents: 42360
diff changeset
    55
  val named_attribute:
ae16b8abf1a8 proper binding/report of defined simprocs;
wenzelm
parents: 42360
diff changeset
    56
    (string * Position.T -> morphism -> attribute) -> (morphism -> attribute) parser
30513
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    57
  val typ_abbrev: typ context_parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    58
  val typ: typ context_parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    59
  val term: term context_parser
55155
a1affe3eb3fd tuned signature;
wenzelm
parents: 55111
diff changeset
    60
  val term_pattern: term context_parser
30513
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    61
  val term_abbrev: term context_parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    62
  val prop: term context_parser
55951
c07d184aebe9 tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents: 55915
diff changeset
    63
  val type_name: {proper: bool, strict: bool} -> string context_parser
55954
a29aefc88c8d more uniform check_const/read_const;
wenzelm
parents: 55951
diff changeset
    64
  val const: {proper: bool, strict: bool} -> string context_parser
30514
9455ecc7796d simplified goal_spec: default to first goal;
wenzelm
parents: 30513
diff changeset
    65
  val goal_spec: ((int -> tactic) -> tactic) context_parser
55997
9dc5ce83202c modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents: 55956
diff changeset
    66
  val attribs: (xstring * Position.T -> string) -> src list parser
9dc5ce83202c modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents: 55956
diff changeset
    67
  val opt_attribs: (xstring * Position.T -> string) -> src list parser
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    68
  val syntax_generic: 'a context_parser -> src -> Context.generic -> 'a * Context.generic
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    69
  val syntax: 'a context_parser -> src -> Proof.context -> 'a * Proof.context
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    70
end;
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    71
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    72
structure Args: ARGS =
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    73
struct
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
    74
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    75
(** datatype src **)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    76
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    77
datatype src =
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    78
  Src of
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    79
   {name: string * Position.T,
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    80
    args: Token.T list,
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    81
    output_info: (string * Markup.T) option};
56029
8bedca4bd5a3 clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents: 56028
diff changeset
    82
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    83
fun src name args = Src {name = name, args = args, output_info = NONE};
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
    84
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    85
fun name_of_src (Src {name, ...}) = name;
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    86
56033
513c2b0ea565 more markup;
wenzelm
parents: 56032
diff changeset
    87
fun range_of_src (Src {name = (_, pos), args, ...}) =
513c2b0ea565 more markup;
wenzelm
parents: 56032
diff changeset
    88
  if null args then pos
513c2b0ea565 more markup;
wenzelm
parents: 56032
diff changeset
    89
  else Position.set_range (pos, #2 (Token.range_of args));
513c2b0ea565 more markup;
wenzelm
parents: 56032
diff changeset
    90
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    91
fun unparse_src (Src {args, ...}) = map Token.unparse args;
56029
8bedca4bd5a3 clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents: 56028
diff changeset
    92
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
    93
fun pretty_src ctxt src =
21030
8b21407de526 moved pretty_attribs to attrib.ML;
wenzelm
parents: 20664
diff changeset
    94
  let
56037
wenzelm
parents: 56035
diff changeset
    95
    val Src {name = (name, _), args, output_info} = src;
wenzelm
parents: 56035
diff changeset
    96
    val prt_name =
wenzelm
parents: 56035
diff changeset
    97
      (case output_info of
wenzelm
parents: 56035
diff changeset
    98
        NONE => Pretty.str name
wenzelm
parents: 56035
diff changeset
    99
      | SOME (_, markup) => Pretty.mark_str (markup, name));
32091
30e2ffbba718 proper context for Display.pretty_thm etc. or old-style versions Display.pretty_thm_global, Display.pretty_thm_without_context etc.;
wenzelm
parents: 30573
diff changeset
   100
    val prt_thm = Pretty.backquote o Display.pretty_thm ctxt;
56037
wenzelm
parents: 56035
diff changeset
   101
    fun prt_arg arg =
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   102
      (case Token.get_value arg of
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   103
        SOME (Token.Literal markup) =>
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   104
          let val x = Token.content_of arg
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   105
          in Pretty.mark_str (Token.keyword_markup markup x, x) end
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   106
      | SOME (Token.Text s) => Pretty.str (quote s)
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   107
      | SOME (Token.Typ T) => Syntax.pretty_typ ctxt T
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   108
      | SOME (Token.Term t) => Syntax.pretty_term ctxt t
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   109
      | SOME (Token.Fact ths) => Pretty.enclose "(" ")" (Pretty.breaks (map prt_thm ths))
55915
607948c90bf0 suppress short abbreviations more uniformly, for outer and quasi-outer syntax;
wenzelm
parents: 55914
diff changeset
   110
      | _ => Pretty.mark_str (Token.markup arg, Token.unparse arg));
56037
wenzelm
parents: 56035
diff changeset
   111
  in Pretty.block (Pretty.breaks (prt_name :: map prt_arg args)) end;
21030
8b21407de526 moved pretty_attribs to attrib.ML;
wenzelm
parents: 20664
diff changeset
   112
56029
8bedca4bd5a3 clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents: 56028
diff changeset
   113
8bedca4bd5a3 clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents: 56028
diff changeset
   114
(* check *)
8bedca4bd5a3 clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents: 56028
diff changeset
   115
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   116
fun check_src ctxt table (Src {name = (xname, pos), args, output_info = _}) =
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
   117
  let
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
   118
    val (name, x) = Name_Space.check (Context.Proof ctxt) table (xname, pos);
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
   119
    val space = Name_Space.space_of_table table;
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
   120
    val kind = Name_Space.kind_of space;
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
   121
    val markup = Name_Space.markup space name;
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
   122
  in (Src {name = (name, pos), args = args, output_info = SOME (kind, markup)}, x) end;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   123
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   124
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   125
(* values *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   126
56037
wenzelm
parents: 56035
diff changeset
   127
fun map_args f (Src {name, args, output_info}) =
wenzelm
parents: 56035
diff changeset
   128
  Src {name = name, args = map f args, output_info = output_info};
wenzelm
parents: 56035
diff changeset
   129
45290
f599ac41e7f5 tuned signature -- refined terminology;
wenzelm
parents: 44357
diff changeset
   130
fun transform_values phi = map_args (Token.map_value
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   131
  (fn Token.Typ T => Token.Typ (Morphism.typ phi T)
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   132
    | Token.Term t => Token.Term (Morphism.term phi t)
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   133
    | Token.Fact ths => Token.Fact (Morphism.fact phi ths)
53112
04d8af9ff64b proper exhaustive match (cf. e9beabf045ab);
wenzelm
parents: 48992
diff changeset
   134
    | Token.Attribute att => Token.Attribute (Morphism.transform phi att)
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   135
    | tok => tok));
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   136
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   137
val init_assignable = map_args Token.init_assignable;
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   138
val closure = map_args Token.closure;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   139
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   140
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   141
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   142
(** argument scanners **)
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   143
27371
f89aa7bd4602 added context/theory scanner;
wenzelm
parents: 27234
diff changeset
   144
(* context *)
f89aa7bd4602 added context/theory scanner;
wenzelm
parents: 27234
diff changeset
   145
f89aa7bd4602 added context/theory scanner;
wenzelm
parents: 27234
diff changeset
   146
fun context x = (Scan.state >> Context.proof_of) x;
f89aa7bd4602 added context/theory scanner;
wenzelm
parents: 27234
diff changeset
   147
fun theory x = (Scan.state >> Context.theory_of) x;
f89aa7bd4602 added context/theory scanner;
wenzelm
parents: 27234
diff changeset
   148
f89aa7bd4602 added context/theory scanner;
wenzelm
parents: 27234
diff changeset
   149
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   150
(* basic *)
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   151
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56200
diff changeset
   152
val ident = Parse.token
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   153
  (Parse.short_ident || Parse.long_ident || Parse.sym_ident || Parse.term_var ||
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   154
    Parse.type_ident || Parse.type_var || Parse.number);
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   155
56500
90f17a04567d proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents: 56499
diff changeset
   156
val string = Parse.token Parse.string;
56499
7e0178c84994 allow text cartouches in regular outer syntax categories "text" and "altstring";
wenzelm
parents: 56333
diff changeset
   157
val alt_string = Parse.token (Parse.alt_string || Parse.cartouche);
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56200
diff changeset
   158
val symbolic = Parse.token (Parse.keyword_with Token.ident_or_symbolic);
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   159
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   160
fun $$$ x =
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56200
diff changeset
   161
  (ident || Parse.token Parse.keyword) :|-- (fn tok =>
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   162
    let val y = Token.content_of tok in
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   163
      if x = y
56202
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
   164
      then (Token.assign (SOME (Token.Literal (false, Markup.quasi_keyword))) tok; Scan.succeed x)
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   165
      else Scan.fail
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   166
    end);
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   167
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   168
val named = ident || string;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   169
10035
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   170
val add = $$$ "add";
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   171
val del = $$$ "del";
8803
wenzelm
parents: 8687
diff changeset
   172
val colon = $$$ ":";
10035
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   173
val query = $$$ "?";
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   174
val bang = $$$ "!";
20111
ba1676dd3546 query/bang_colon: separate tokens;
wenzelm
parents: 19482
diff changeset
   175
val query_colon = $$$ "?" ^^ $$$ ":";
ba1676dd3546 query/bang_colon: separate tokens;
wenzelm
parents: 19482
diff changeset
   176
val bang_colon = $$$ "!" ^^ $$$ ":";
10035
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   177
8803
wenzelm
parents: 8687
diff changeset
   178
fun parens scan = $$$ "(" |-- scan --| $$$ ")";
10150
a068c666c53e added "bracks";
wenzelm
parents: 10035
diff changeset
   179
fun bracks scan = $$$ "[" |-- scan --| $$$ "]";
53168
d998de7f0efc tuned signature;
wenzelm
parents: 53113
diff changeset
   180
fun mode s = Scan.optional (parens ($$$ s) >> K true) false;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   181
fun maybe scan = $$$ "_" >> K NONE || scan >> SOME;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   182
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56200
diff changeset
   183
val cartouche = Parse.token Parse.cartouche;
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
   184
val cartouche_inner_syntax = cartouche >> Token.inner_syntax_of;
55045
99056d23e05b cartouche within nested args (attributes, methods, etc.);
wenzelm
parents: 55033
diff changeset
   185
val cartouche_source_position = cartouche >> Token.source_position_of;
99056d23e05b cartouche within nested args (attributes, methods, etc.);
wenzelm
parents: 55033
diff changeset
   186
56500
90f17a04567d proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents: 56499
diff changeset
   187
val text_token = named || Parse.token (Parse.verbatim || Parse.cartouche);
90f17a04567d proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents: 56499
diff changeset
   188
val text_source_position = text_token >> Token.source_position_of;
90f17a04567d proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents: 56499
diff changeset
   189
val text = text_token >> Token.content_of;
90f17a04567d proper Args.name vs. Args.text as documented (in contrast to adhoc union in 75aaee32893d, which had to cope with more limited Args.T);
wenzelm
parents: 56499
diff changeset
   190
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
   191
val name_inner_syntax = named >> Token.inner_syntax_of;
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   192
val name_source_position = named >> Token.source_position_of;
27882
eaa9fef9f4c1 Args.name_source(_position) for proper position information;
wenzelm
parents: 27819
diff changeset
   193
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   194
val name = named >> Token.content_of;
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   195
val binding = Parse.position name >> Binding.make;
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   196
val alt_name = alt_string >> Token.content_of;
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   197
val symbol = symbolic >> Token.content_of;
17064
2fae6579fb2e added liberal_name;
wenzelm
parents: 16343
diff changeset
   198
val liberal_name = symbol || name;
8233
85169951d515 attrib: keyword_symid;
wenzelm
parents: 8089
diff changeset
   199
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   200
val var = (ident >> Token.content_of) :|-- (fn x =>
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   201
  (case Lexicon.read_variable x of SOME v => Scan.succeed v | NONE => Scan.fail));
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   202
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   203
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   204
(* values *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   205
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   206
fun value dest = Scan.some (fn arg =>
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   207
  (case Token.get_value arg of SOME v => (SOME (dest v) handle Match => NONE) | NONE => NONE));
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   208
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   209
fun evaluate mk eval arg =
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   210
  let val x = eval arg in (Token.assign (SOME (mk x)) arg; x) end;
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   211
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   212
val internal_text = value (fn Token.Text s => s);
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   213
val internal_typ = value (fn Token.Typ T => T);
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   214
val internal_term = value (fn Token.Term t => t);
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   215
val internal_fact = value (fn Token.Fact ths => ths);
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   216
val internal_attribute = value (fn Token.Attribute att => att);
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   217
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   218
fun named_text intern = internal_text || named >> evaluate Token.Text (intern o Token.content_of);
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
   219
fun named_typ readT = internal_typ || named >> evaluate Token.Typ (readT o Token.inner_syntax_of);
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
   220
fun named_term read = internal_term || named >> evaluate Token.Term (read o Token.inner_syntax_of);
42464
ae16b8abf1a8 proper binding/report of defined simprocs;
wenzelm
parents: 42360
diff changeset
   221
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   222
fun named_fact get = internal_fact || named >> evaluate Token.Fact (get o Token.content_of) ||
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
   223
  alt_string >> evaluate Token.Fact (get o Token.inner_syntax_of);
42464
ae16b8abf1a8 proper binding/report of defined simprocs;
wenzelm
parents: 42360
diff changeset
   224
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   225
fun named_attribute att =
42464
ae16b8abf1a8 proper binding/report of defined simprocs;
wenzelm
parents: 42360
diff changeset
   226
  internal_attribute ||
55708
f4b114070675 tuned signature;
wenzelm
parents: 55698
diff changeset
   227
  named >> evaluate Token.Attribute (fn tok => att (Token.content_of tok, Token.pos_of tok));
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   228
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   229
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   230
(* terms and types *)
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   231
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 40291
diff changeset
   232
val typ_abbrev = Scan.peek (named_typ o Proof_Context.read_typ_abbrev o Context.proof_of);
25331
73072178e0ce Syntax.read_typ;
wenzelm
parents: 25323
diff changeset
   233
val typ = Scan.peek (named_typ o Syntax.read_typ o Context.proof_of);
24508
c8b82fec6447 replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents: 24244
diff changeset
   234
val term = Scan.peek (named_term o Syntax.read_term o Context.proof_of);
55155
a1affe3eb3fd tuned signature;
wenzelm
parents: 55111
diff changeset
   235
val term_pattern = Scan.peek (named_term o Proof_Context.read_term_pattern o Context.proof_of);
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 40291
diff changeset
   236
val term_abbrev = Scan.peek (named_term o Proof_Context.read_term_abbrev o Context.proof_of);
24508
c8b82fec6447 replaced ProofContext.read_term/prop by general Syntax.read_term/prop;
wenzelm
parents: 24244
diff changeset
   237
val prop = Scan.peek (named_term o Syntax.read_prop o Context.proof_of);
18635
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   238
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   239
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   240
(* type and constant names *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   241
55951
c07d184aebe9 tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents: 55915
diff changeset
   242
fun type_name flags =
56002
2028467b4df4 tuned signature;
wenzelm
parents: 55997
diff changeset
   243
  Scan.peek (named_typ o Proof_Context.read_type_name flags o Context.proof_of)
18998
10c251f29847 Context.generic is canonical state of parsers;
wenzelm
parents: 18728
diff changeset
   244
  >> (fn Type (c, _) => c | TFree (a, _) => a | _ => "");
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   245
55954
a29aefc88c8d more uniform check_const/read_const;
wenzelm
parents: 55951
diff changeset
   246
fun const flags =
56002
2028467b4df4 tuned signature;
wenzelm
parents: 55997
diff changeset
   247
  Scan.peek (named_term o Proof_Context.read_const flags o Context.proof_of)
18998
10c251f29847 Context.generic is canonical state of parsers;
wenzelm
parents: 18728
diff changeset
   248
  >> (fn Const (c, _) => c | Free (x, _) => x | _ => "");
7553
af3a1fe87c42 added bang_facts;
wenzelm
parents: 6447
diff changeset
   249
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   250
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   251
(* improper method arguments *)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   252
8536
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
   253
val from_to =
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   254
  Parse.nat -- ($$$ "-" |-- Parse.nat) >> (fn (i, j) => fn tac => Seq.INTERVAL tac i j) ||
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   255
  Parse.nat --| $$$ "-" >> (fn i => fn tac => fn st => Seq.INTERVAL tac i (Thm.nprems_of st) st) ||
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   256
  Parse.nat >> (fn i => fn tac => tac i) ||
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   257
  $$$ "!" >> K ALLGOALS;
8536
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
   258
56202
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
   259
val goal = Parse.keyword_improper "[" |-- Parse.!!! (from_to --| Parse.keyword_improper "]");
30514
9455ecc7796d simplified goal_spec: default to first goal;
wenzelm
parents: 30513
diff changeset
   260
fun goal_spec x = Scan.lift (Scan.optional goal (fn tac => tac 1)) x;
8233
85169951d515 attrib: keyword_symid;
wenzelm
parents: 8089
diff changeset
   261
85169951d515 attrib: keyword_symid;
wenzelm
parents: 8089
diff changeset
   262
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   263
(* attributes *)
27382
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   264
55997
9dc5ce83202c modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents: 55956
diff changeset
   265
fun attribs check =
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   266
  let
55997
9dc5ce83202c modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents: 55956
diff changeset
   267
    fun intern tok = check (Token.content_of tok, Token.pos_of tok);
9dc5ce83202c modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents: 55956
diff changeset
   268
    val attrib_name = internal_text || (symbolic || named) >> evaluate Token.Text intern;
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56200
diff changeset
   269
    val attrib = Parse.position attrib_name -- Parse.!!! Parse.args >> uncurry src;
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   270
  in $$$ "[" |-- Parse.!!! (Parse.list attrib --| $$$ "]") end;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   271
55997
9dc5ce83202c modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents: 55956
diff changeset
   272
fun opt_attribs check = Scan.optional (attribs check) [];
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   273
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   274
27382
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   275
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   276
(** syntax wrapper **)
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   277
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
   278
fun syntax_generic scan (Src {name = (name, pos), args = args0, output_info}) context =
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   279
  let
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   280
    val args1 = map Token.init_assignable args0;
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   281
    fun reported_text () =
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   282
      if Context_Position.is_visible_generic context then
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   283
        ((pos, Markup.operator) :: maps (Token.reports_of_value o Token.closure) args1)
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   284
        |> map (fn (p, m) => Position.reported_text p m "")
56333
38f1422ef473 support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents: 56202
diff changeset
   285
      else [];
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   286
  in
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   287
    (case Scan.error (Scan.finite' Token.stopper (Scan.option scan)) (context, args1) of
56037
wenzelm
parents: 56035
diff changeset
   288
      (SOME x, (context', [])) =>
wenzelm
parents: 56035
diff changeset
   289
        let val _ = Output.report (reported_text ())
wenzelm
parents: 56035
diff changeset
   290
        in (x, context') end
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   291
    | (_, (_, args2)) =>
56037
wenzelm
parents: 56035
diff changeset
   292
        let
wenzelm
parents: 56035
diff changeset
   293
          val print_name =
wenzelm
parents: 56035
diff changeset
   294
            (case output_info of
wenzelm
parents: 56035
diff changeset
   295
              NONE => quote name
56038
0e2dec666152 tuned messages -- in accordance to Isabelle/Scala;
wenzelm
parents: 56037
diff changeset
   296
            | SOME (kind, markup) => plain_words kind ^ " " ^ quote (Markup.markup markup name));
56037
wenzelm
parents: 56035
diff changeset
   297
          val print_args =
wenzelm
parents: 56035
diff changeset
   298
            if null args2 then "" else ":\n  " ^ space_implode " " (map Token.print args2);
wenzelm
parents: 56035
diff changeset
   299
        in
wenzelm
parents: 56035
diff changeset
   300
          error ("Bad arguments for " ^ print_name ^ Position.here pos ^ print_args ^
56333
38f1422ef473 support bulk messages consisting of small string segments, which are more healthy to the Poly/ML RTS and might prevent spurious GC crashes such as MTGCProcessMarkPointers::ScanAddressesInObject;
wenzelm
parents: 56202
diff changeset
   301
            Markup.markup_report (implode (reported_text ())))
56037
wenzelm
parents: 56035
diff changeset
   302
        end)
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   303
  end;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   304
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
   305
fun syntax scan src = apsnd Context.the_proof o syntax_generic scan src o Context.Proof;
18998
10c251f29847 Context.generic is canonical state of parsers;
wenzelm
parents: 18728
diff changeset
   306
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   307
end;