src/Pure/Isar/args.ML
author wenzelm
Tue, 18 Mar 2014 11:13:38 +0100
changeset 56200 1f9951be72b5
parent 56063 38f13d055107
child 56201 dd2df97b379b
permissions -rw-r--r--
unused;
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
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
    36
  val name_inner_syntax: string parser
55828
42ac3cfb89f6 clarified language markup: added "delimited" property;
wenzelm
parents: 55745
diff changeset
    37
  val name_source_position: Symbol_Pos.source parser
30513
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    38
  val name: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    39
  val binding: binding parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    40
  val alt_name: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    41
  val symbol: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    42
  val liberal_name: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    43
  val var: indexname parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    44
  val internal_text: string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    45
  val internal_typ: typ parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    46
  val internal_term: term parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    47
  val internal_fact: thm list parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    48
  val internal_attribute: (morphism -> attribute) parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    49
  val named_text: (string -> string) -> string parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    50
  val named_typ: (string -> typ) -> typ parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    51
  val named_term: (string -> term) -> term parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    52
  val named_fact: (string -> thm list) -> thm list parser
42464
ae16b8abf1a8 proper binding/report of defined simprocs;
wenzelm
parents: 42360
diff changeset
    53
  val named_attribute:
ae16b8abf1a8 proper binding/report of defined simprocs;
wenzelm
parents: 42360
diff changeset
    54
    (string * Position.T -> morphism -> attribute) -> (morphism -> attribute) parser
30513
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    55
  val typ_abbrev: typ context_parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    56
  val typ: typ context_parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    57
  val term: term context_parser
55155
a1affe3eb3fd tuned signature;
wenzelm
parents: 55111
diff changeset
    58
  val term_pattern: term context_parser
30513
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    59
  val term_abbrev: term context_parser
1796b8ea88aa eliminated type Args.T;
wenzelm
parents: 30473
diff changeset
    60
  val prop: term context_parser
55951
c07d184aebe9 tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents: 55915
diff changeset
    61
  val type_name: {proper: bool, strict: bool} -> string context_parser
55954
a29aefc88c8d more uniform check_const/read_const;
wenzelm
parents: 55951
diff changeset
    62
  val const: {proper: bool, strict: bool} -> string context_parser
30514
9455ecc7796d simplified goal_spec: default to first goal;
wenzelm
parents: 30513
diff changeset
    63
  val goal_spec: ((int -> tactic) -> tactic) context_parser
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
    64
  val parse: Token.T list parser
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
    65
  val parse1: (string -> bool) -> Token.T list 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
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   152
fun token atom = Scan.ahead Parse.not_eof --| atom;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   153
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   154
val ident = token
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   155
  (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
   156
    Parse.type_ident || Parse.type_var || Parse.number);
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   157
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   158
val string = token (Parse.string || Parse.verbatim);
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   159
val alt_string = token Parse.alt_string;
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   160
val symbolic = token (Parse.keyword_with Token.ident_or_symbolic);
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   161
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   162
fun $$$ x =
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   163
  (ident || token Parse.keyword) :|-- (fn tok =>
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   164
    let val y = Token.content_of tok in
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   165
      if x = y
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   166
      then (Token.assign (SOME (Token.Literal Markup.quasi_keyword)) tok; Scan.succeed x)
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   167
      else Scan.fail
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   168
    end);
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   169
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   170
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   171
val named = ident || string;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   172
10035
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   173
val add = $$$ "add";
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   174
val del = $$$ "del";
8803
wenzelm
parents: 8687
diff changeset
   175
val colon = $$$ ":";
10035
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   176
val query = $$$ "?";
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   177
val bang = $$$ "!";
20111
ba1676dd3546 query/bang_colon: separate tokens;
wenzelm
parents: 19482
diff changeset
   178
val query_colon = $$$ "?" ^^ $$$ ":";
ba1676dd3546 query/bang_colon: separate tokens;
wenzelm
parents: 19482
diff changeset
   179
val bang_colon = $$$ "!" ^^ $$$ ":";
10035
c095955e7575 added common args keywords;
wenzelm
parents: 9952
diff changeset
   180
8803
wenzelm
parents: 8687
diff changeset
   181
fun parens scan = $$$ "(" |-- scan --| $$$ ")";
10150
a068c666c53e added "bracks";
wenzelm
parents: 10035
diff changeset
   182
fun bracks scan = $$$ "[" |-- scan --| $$$ "]";
53168
d998de7f0efc tuned signature;
wenzelm
parents: 53113
diff changeset
   183
fun mode s = Scan.optional (parens ($$$ s) >> K true) false;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   184
fun maybe scan = $$$ "_" >> K NONE || scan >> SOME;
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   185
55045
99056d23e05b cartouche within nested args (attributes, methods, etc.);
wenzelm
parents: 55033
diff changeset
   186
val cartouche = token Parse.cartouche;
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
   187
val cartouche_inner_syntax = cartouche >> Token.inner_syntax_of;
55045
99056d23e05b cartouche within nested args (attributes, methods, etc.);
wenzelm
parents: 55033
diff changeset
   188
val cartouche_source_position = cartouche >> Token.source_position_of;
99056d23e05b cartouche within nested args (attributes, methods, etc.);
wenzelm
parents: 55033
diff changeset
   189
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
   190
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
   191
val name_source_position = named >> Token.source_position_of;
27882
eaa9fef9f4c1 Args.name_source(_position) for proper position information;
wenzelm
parents: 27819
diff changeset
   192
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   193
val name = named >> Token.content_of;
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   194
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
   195
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
   196
val symbol = symbolic >> Token.content_of;
17064
2fae6579fb2e added liberal_name;
wenzelm
parents: 16343
diff changeset
   197
val liberal_name = symbol || name;
8233
85169951d515 attrib: keyword_symid;
wenzelm
parents: 8089
diff changeset
   198
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   199
val var = (ident >> Token.content_of) :|-- (fn x =>
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   200
  (case Lexicon.read_variable x of SOME v => Scan.succeed v | NONE => Scan.fail));
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   201
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   202
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   203
(* values *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   204
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   205
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
   206
  (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
   207
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   208
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
   209
  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
   210
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   211
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
   212
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
   213
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
   214
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
   215
val internal_attribute = value (fn Token.Attribute att => att);
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   216
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   217
fun named_text intern = internal_text || named >> evaluate Token.Text (intern o Token.content_of);
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
   218
fun named_typ readT = internal_typ || named >> evaluate Token.Typ (readT o Token.inner_syntax_of);
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
   219
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
   220
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   221
fun named_fact get = internal_fact || named >> evaluate Token.Fact (get o Token.content_of) ||
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55045
diff changeset
   222
  alt_string >> evaluate Token.Fact (get o Token.inner_syntax_of);
42464
ae16b8abf1a8 proper binding/report of defined simprocs;
wenzelm
parents: 42360
diff changeset
   223
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   224
fun named_attribute att =
42464
ae16b8abf1a8 proper binding/report of defined simprocs;
wenzelm
parents: 42360
diff changeset
   225
  internal_attribute ||
55708
f4b114070675 tuned signature;
wenzelm
parents: 55698
diff changeset
   226
  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
   227
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   228
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   229
(* terms and types *)
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   230
42360
da8817d01e7c modernized structure Proof_Context;
wenzelm
parents: 40291
diff changeset
   231
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
   232
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
   233
val term = Scan.peek (named_term o Syntax.read_term o Context.proof_of);
55155
a1affe3eb3fd tuned signature;
wenzelm
parents: 55111
diff changeset
   234
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
   235
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
   236
val prop = Scan.peek (named_term o Syntax.read_prop o Context.proof_of);
18635
58bbff56a914 added generic syntax;
wenzelm
parents: 18037
diff changeset
   237
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   238
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   239
(* type and constant names *)
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   240
55951
c07d184aebe9 tuned signature -- more uniform check_type_name/read_type_name;
wenzelm
parents: 55915
diff changeset
   241
fun type_name flags =
56002
2028467b4df4 tuned signature;
wenzelm
parents: 55997
diff changeset
   242
  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
   243
  >> (fn Type (c, _) => c | TFree (a, _) => a | _ => "");
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   244
55954
a29aefc88c8d more uniform check_const/read_const;
wenzelm
parents: 55951
diff changeset
   245
fun const flags =
56002
2028467b4df4 tuned signature;
wenzelm
parents: 55997
diff changeset
   246
  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
   247
  >> (fn Const (c, _) => c | Free (x, _) => x | _ => "");
7553
af3a1fe87c42 added bang_facts;
wenzelm
parents: 6447
diff changeset
   248
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   249
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   250
(* improper method arguments *)
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   251
8536
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
   252
val from_to =
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   253
  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
   254
  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
   255
  Parse.nat >> (fn i => fn tac => tac i) ||
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   256
  $$$ "!" >> K ALLGOALS;
8536
de307f5bc89a goal_spec;
wenzelm
parents: 8282
diff changeset
   257
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   258
val goal = $$$ "[" |-- Parse.!!! (from_to --| $$$ "]");
30514
9455ecc7796d simplified goal_spec: default to first goal;
wenzelm
parents: 30513
diff changeset
   259
fun goal_spec x = Scan.lift (Scan.optional goal (fn tac => tac 1)) x;
8233
85169951d515 attrib: keyword_symid;
wenzelm
parents: 8089
diff changeset
   260
85169951d515 attrib: keyword_symid;
wenzelm
parents: 8089
diff changeset
   261
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   262
(* arguments within outer syntax *)
5878
769abc29bb8e several args parsers;
wenzelm
parents: 5822
diff changeset
   263
53113
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   264
val argument_kinds =
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   265
 [Token.Ident, Token.LongIdent, Token.SymIdent, Token.Var, Token.TypeIdent, Token.TypeVar,
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 53168
diff changeset
   266
  Token.Nat, Token.Float, Token.String, Token.AltString, Token.Cartouche, Token.Verbatim];
53113
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   267
27382
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   268
fun parse_args is_symid =
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   269
  let
53113
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   270
    fun argument blk =
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   271
      Parse.group (fn () => "argument")
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   272
        (Scan.one (fn tok =>
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   273
          let val kind = Token.kind_of tok in
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   274
            member (op =) argument_kinds kind orelse
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   275
            Token.keyword_with is_symid tok orelse
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   276
            (blk andalso Token.keyword_with (fn s => s = ",") tok)
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   277
          end));
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   278
27382
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   279
    fun args blk x = Scan.optional (args1 blk) [] x
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   280
    and args1 blk x =
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   281
      ((Scan.repeat1
53113
d9ba3417cb41 more careful parsing of nested argument tokens -- avoid Parse.RESET_VALUE on still uninterpreted material;
wenzelm
parents: 53112
diff changeset
   282
        (Scan.repeat1 (argument blk) ||
27382
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   283
          argsp "(" ")" ||
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   284
          argsp "[" "]")) >> flat) x
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   285
    and argsp l r x =
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   286
      (token (Parse.$$$ l) ::: Parse.!!! (args true @@@ (token (Parse.$$$ r) >> single))) x;
27382
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   287
  in (args, args1) end;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   288
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36950
diff changeset
   289
val parse = #1 (parse_args Token.ident_or_symbolic) false;
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   290
fun parse1 is_symid = #2 (parse_args is_symid) false;
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   291
27811
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   292
44bc67675210 unified Args.T with OuterLex.token;
wenzelm
parents: 27732
diff changeset
   293
(* attributes *)
27382
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   294
55997
9dc5ce83202c modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents: 55956
diff changeset
   295
fun attribs check =
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   296
  let
55997
9dc5ce83202c modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents: 55956
diff changeset
   297
    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
   298
    val attrib_name = internal_text || (symbolic || named) >> evaluate Token.Text intern;
56029
8bedca4bd5a3 clarified Args.src: more abstract type, position refers to name only;
wenzelm
parents: 56028
diff changeset
   299
    val attrib = Parse.position attrib_name -- Parse.!!! parse >> uncurry src;
36950
75b8f26f2f07 refer directly to structure Keyword and Parse;
wenzelm
parents: 36505
diff changeset
   300
  in $$$ "[" |-- Parse.!!! (Parse.list attrib --| $$$ "]") end;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   301
55997
9dc5ce83202c modernized Attrib.check_name/check_src similar to methods (see also a989bdaf8121);
wenzelm
parents: 55956
diff changeset
   302
fun opt_attribs check = Scan.optional (attribs check) [];
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   303
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   304
27382
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   305
b1285021424e tuned nested args parser;
wenzelm
parents: 27377
diff changeset
   306
(** syntax wrapper **)
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   307
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
   308
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
   309
  let
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   310
    val args1 = map Token.init_assignable args0;
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   311
    fun reported_text () =
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   312
      if Context_Position.is_visible_generic context then
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 56038
diff changeset
   313
        ((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
   314
        |> map (fn (p, m) => Position.reported_text p m "")
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   315
        |> implode
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   316
      else "";
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   317
  in
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   318
    (case Scan.error (Scan.finite' Token.stopper (Scan.option scan)) (context, args1) of
56037
wenzelm
parents: 56035
diff changeset
   319
      (SOME x, (context', [])) =>
wenzelm
parents: 56035
diff changeset
   320
        let val _ = Output.report (reported_text ())
wenzelm
parents: 56035
diff changeset
   321
        in (x, context') end
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   322
    | (_, (_, args2)) =>
56037
wenzelm
parents: 56035
diff changeset
   323
        let
wenzelm
parents: 56035
diff changeset
   324
          val print_name =
wenzelm
parents: 56035
diff changeset
   325
            (case output_info of
wenzelm
parents: 56035
diff changeset
   326
              NONE => quote name
56038
0e2dec666152 tuned messages -- in accordance to Isabelle/Scala;
wenzelm
parents: 56037
diff changeset
   327
            | SOME (kind, markup) => plain_words kind ^ " " ^ quote (Markup.markup markup name));
56037
wenzelm
parents: 56035
diff changeset
   328
          val print_args =
wenzelm
parents: 56035
diff changeset
   329
            if null args2 then "" else ":\n  " ^ space_implode " " (map Token.print args2);
wenzelm
parents: 56035
diff changeset
   330
        in
wenzelm
parents: 56035
diff changeset
   331
          error ("Bad arguments for " ^ print_name ^ Position.here pos ^ print_args ^
wenzelm
parents: 56035
diff changeset
   332
            Markup.markup_report (reported_text ()))
wenzelm
parents: 56035
diff changeset
   333
        end)
55914
c5b752d549e3 clarified init_assignable: make double-sure that initial values are reset;
wenzelm
parents: 55828
diff changeset
   334
  end;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15596
diff changeset
   335
56032
b034b9f0fa2a clarified Args.check_src: retain name space information for error output;
wenzelm
parents: 56029
diff changeset
   336
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
   337
5822
3f824514ad88 Concrete argument syntax (for attributes, methods etc.).
wenzelm
parents:
diff changeset
   338
end;