src/Pure/Isar/parse.ML
author wenzelm
Thu, 06 Jun 2024 12:42:42 +0200
changeset 80267 ea908185a597
parent 78819 b8775a63cb35
permissions -rw-r--r--
more operations;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
36949
080e85d46108 renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents: 35838
diff changeset
     1
(*  Title:      Pure/Isar/parse.ML
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     2
    Author:     Markus Wenzel, TU Muenchen
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     3
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     4
Generic parsers for Isabelle/Isar outer syntax.
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     5
*)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     6
36949
080e85d46108 renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents: 35838
diff changeset
     7
signature PARSE =
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     8
sig
44357
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 43947
diff changeset
     9
  val group: (unit -> string) -> (Token.T list -> 'a) -> Token.T list -> 'a
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
    10
  val !!! : (Token.T list -> 'a) -> Token.T list -> 'a
78819
b8775a63cb35 proper cut for Parse.enum1' and its derivatives (see also 769abc29bb8e);
wenzelm
parents: 78818
diff changeset
    11
  val !!!! : (Context.generic * Token.src -> 'a) -> Context.generic * Token.src -> 'a
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
    12
  val not_eof: Token.T parser
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
    13
  val token: 'a parser -> Token.T parser
59029
c907cbe36713 more careful ML source positions, for improved PIDE markup;
wenzelm
parents: 58908
diff changeset
    14
  val range: 'a parser -> ('a * Position.range) parser
42326
e2d22eb4aeb9 some position reports for 'translations';
wenzelm
parents: 42300
diff changeset
    15
  val position: 'a parser -> ('a * Position.T) parser
59809
87641097d0f3 tuned signature;
wenzelm
parents: 59784
diff changeset
    16
  val input: 'a parser -> Input.source parser
42326
e2d22eb4aeb9 some position reports for 'translations';
wenzelm
parents: 42300
diff changeset
    17
  val inner_syntax: 'a parser -> string parser
67136
1368cfa92b7a tuned signature;
wenzelm
parents: 63806
diff changeset
    18
  val command: string parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    19
  val keyword: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    20
  val short_ident: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    21
  val long_ident: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    22
  val sym_ident: string parser
60629
d4e97fcdf83e allow to specify suffix of goal parameters;
wenzelm
parents: 60448
diff changeset
    23
  val dots: string parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    24
  val minus: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    25
  val term_var: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    26
  val type_ident: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    27
  val type_var: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    28
  val number: string parser
40290
47f572aff50a support for floating-point tokens in outer syntax (coinciding with inner syntax version);
wenzelm
parents: 36959
diff changeset
    29
  val float_number: string parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    30
  val string: string parser
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
    31
  val string_position: (string * Position.T) parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    32
  val alt_string: string parser
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 51988
diff changeset
    33
  val cartouche: string parser
74373
6e4093927dbb outer syntax: support for control-cartouche tokens;
wenzelm
parents: 73689
diff changeset
    34
  val control: Antiquote.control parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    35
  val eof: string parser
67136
1368cfa92b7a tuned signature;
wenzelm
parents: 63806
diff changeset
    36
  val command_name: string -> string parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    37
  val keyword_with: (string -> bool) -> string parser
56202
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
    38
  val keyword_markup: bool * Markup.T -> string -> string parser
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
    39
  val keyword_improper: string -> string parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    40
  val $$$ : string -> string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    41
  val reserved: string -> string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    42
  val underscore: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    43
  val maybe: 'a parser -> 'a option parser
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
    44
  val maybe_position: ('a * Position.T) parser -> ('a option * Position.T) parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    45
  val opt_keyword: string -> bool parser
59917
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59809
diff changeset
    46
  val opt_bang: bool parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    47
  val begin: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    48
  val opt_begin: bool parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    49
  val nat: int parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    50
  val int: int parser
40290
47f572aff50a support for floating-point tokens in outer syntax (coinciding with inner syntax version);
wenzelm
parents: 36959
diff changeset
    51
  val real: real parser
55764
wenzelm
parents: 55708
diff changeset
    52
  val enum_positions: string -> 'a parser -> ('a list * Position.T list) parser
wenzelm
parents: 55708
diff changeset
    53
  val enum1_positions: string -> 'a parser -> ('a list * Position.T list) parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    54
  val enum: string -> 'a parser -> 'a list parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    55
  val enum1: string -> 'a parser -> 'a list parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    56
  val and_list: 'a parser -> 'a list parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    57
  val and_list1: 'a parser -> 'a list parser
30511
5c628a39b7cb pervasive types 'a parser and 'a context_parser;
wenzelm
parents: 30339
diff changeset
    58
  val enum': string -> 'a context_parser -> 'a list context_parser
5c628a39b7cb pervasive types 'a parser and 'a context_parser;
wenzelm
parents: 30339
diff changeset
    59
  val enum1': string -> 'a context_parser -> 'a list context_parser
5c628a39b7cb pervasive types 'a parser and 'a context_parser;
wenzelm
parents: 30339
diff changeset
    60
  val and_list': 'a context_parser -> 'a list context_parser
5c628a39b7cb pervasive types 'a parser and 'a context_parser;
wenzelm
parents: 30339
diff changeset
    61
  val and_list1': 'a context_parser -> 'a list context_parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    62
  val list: 'a parser -> 'a list parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    63
  val list1: 'a parser -> 'a list parser
63120
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
    64
  val name: string parser
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
    65
  val name_range: (string * Position.range) parser
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
    66
  val name_position: (string * Position.T) parser
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29310
diff changeset
    67
  val binding: binding parser
63120
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
    68
  val embedded: string parser
74563
042041c0ebeb clarified modules;
wenzelm
parents: 74562
diff changeset
    69
  val embedded_inner_syntax: string parser
70205
3293471cf176 tuned signature;
wenzelm
parents: 70047
diff changeset
    70
  val embedded_input: Input.source parser
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
    71
  val embedded_position: (string * Position.T) parser
72840
6b96464066a0 tuned signature --- more operations;
wenzelm
parents: 70205
diff changeset
    72
  val path_input: Input.source parser
48881
46e053eda5dd clarified Parse.path vs. Parse.explode -- prefer errors in proper transaction context;
wenzelm
parents: 46922
diff changeset
    73
  val path: string parser
70047
96fe857a7a6f clarified signature: more explicit operations for corresponding Isar commands;
wenzelm
parents: 69891
diff changeset
    74
  val path_binding: (string * Position.T) parser
76614
ac08b6e3b9e3 clarified signature;
wenzelm
parents: 75986
diff changeset
    75
  val in_path: string -> Input.source parser
ac08b6e3b9e3 clarified signature;
wenzelm
parents: 75986
diff changeset
    76
  val in_path_parens: string -> Input.source parser
75986
27d98da31985 support 'chapter_definition' with description for presentation purposes;
wenzelm
parents: 74887
diff changeset
    77
  val chapter_name: (string * Position.T) parser
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
    78
  val session_name: (string * Position.T) parser
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
    79
  val theory_name: (string * Position.T) parser
62969
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 62965
diff changeset
    80
  val liberal_name: string parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    81
  val parname: string parser
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29310
diff changeset
    82
  val parbinding: binding parser
46922
3717f3878714 source positions for locale and class expressions;
wenzelm
parents: 45596
diff changeset
    83
  val class: string parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    84
  val sort: string parser
46922
3717f3878714 source positions for locale and class expressions;
wenzelm
parents: 45596
diff changeset
    85
  val type_const: string parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    86
  val arity: (string * string list * string) parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    87
  val multi_arity: (string list * string list * string) parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    88
  val type_args: string list parser
35838
c8bd075c4de8 support type arguments with sort constraints;
wenzelm
parents: 35351
diff changeset
    89
  val type_args_constrained: (string * string option) list parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    90
  val typ: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    91
  val mixfix: mixfix parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    92
  val mixfix': mixfix parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    93
  val opt_mixfix: mixfix parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    94
  val opt_mixfix': mixfix parser
62856
3f97aa4580c6 tuned -- more explicit sections;
wenzelm
parents: 62760
diff changeset
    95
  val syntax_mode: Syntax.mode parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
    96
  val where_: string parser
42299
06e93f257d0e tuned signature;
wenzelm
parents: 42297
diff changeset
    97
  val const_decl: (string * string * mixfix) parser
30339
3fc32dd7a647 added const_binding;
wenzelm
parents: 30223
diff changeset
    98
  val const_binding: (binding * string * mixfix) parser
60448
78f3c67bc35e support for 'consider' command;
wenzelm
parents: 59990
diff changeset
    99
  val params: (binding * string option * mixfix) list parser
63285
e9c777bfd78c clarified syntax;
wenzelm
parents: 63230
diff changeset
   100
  val vars: (binding * string option * mixfix) list parser
29581
b3b33e0298eb binding is alias for Binding.T
haftmann
parents: 29310
diff changeset
   101
  val for_fixes: (binding * string option * mixfix) list parser
59064
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents: 59029
diff changeset
   102
  val ML_source: Input.source parser
a8bcb5a446c8 more abstract type Input.source;
wenzelm
parents: 59029
diff changeset
   103
  val document_source: Input.source parser
69891
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69876
diff changeset
   104
  val document_marker: Input.source parser
63137
9553f11d67c4 simplified syntax: Parse.term corresponds to Args.term etc.;
wenzelm
parents: 63120
diff changeset
   105
  val const: string parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
   106
  val term: string parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
   107
  val prop: string parser
40793
d21aedaa91e7 added Parse.literal_fact with proper inner_syntax markup (source position);
wenzelm
parents: 40296
diff changeset
   108
  val literal_fact: string parser
29310
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
   109
  val propp: (string * string list) parser
1a633304fa5e added type 'a parser, simplified signature;
wenzelm
parents: 28965
diff changeset
   110
  val termp: (string * string list) parser
59924
801b979ec0c2 more general notion of command span: command keyword not necessarily at start;
wenzelm
parents: 59918
diff changeset
   111
  val private: Position.T parser
59990
a81dc82ecba3 clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents: 59939
diff changeset
   112
  val qualified: Position.T parser
62969
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 62965
diff changeset
   113
  val target: (string * Position.T) parser
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 62965
diff changeset
   114
  val opt_target: (string * Position.T) option parser
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   115
  val args: Token.T list parser
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   116
  val args1: (string -> bool) -> Token.T list parser
58028
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   117
  val attribs: Token.src list parser
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   118
  val opt_attribs: Token.src list parser
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   119
  val thm_sel: Facts.interval list parser
62969
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 62965
diff changeset
   120
  val thm: (Facts.ref * Token.src list) parser
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 62965
diff changeset
   121
  val thms1: (Facts.ref * Token.src list) list parser
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   122
  val options: ((string * Position.T) * (string * Position.T)) list parser
74562
8403bd51f8b1 clarified modules;
wenzelm
parents: 74373
diff changeset
   123
  val embedded_ml: ML_Lex.token Antiquote.antiquote list parser
74564
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   124
  val read_antiq: Keyword.keywords -> 'a parser -> Symbol_Pos.T list * Position.T -> 'a
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   125
  val read_embedded: Proof.context -> Keyword.keywords -> 'a parser -> Input.source -> 'a
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   126
end;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   127
36949
080e85d46108 renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
wenzelm
parents: 35838
diff changeset
   128
structure Parse: PARSE =
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   129
struct
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   130
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   131
(** error handling **)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   132
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   133
(* group atomic parsers (no cuts!) *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   134
44357
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 43947
diff changeset
   135
fun group s scan = scan || Scan.fail_with
48911
5debc3e4fa81 tuned messages: end-of-input rarely means physical end-of-file from the past;
wenzelm
parents: 48881
diff changeset
   136
  (fn [] => (fn () => s () ^ " expected,\nbut end-of-input was found")
42519
wenzelm
parents: 42326
diff changeset
   137
    | tok :: _ =>
43947
9b00f09f7721 defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
wenzelm
parents: 43775
diff changeset
   138
        (fn () =>
9b00f09f7721 defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
wenzelm
parents: 43775
diff changeset
   139
          (case Token.text_of tok of
9b00f09f7721 defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
wenzelm
parents: 43775
diff changeset
   140
            (txt, "") =>
55708
f4b114070675 tuned signature;
wenzelm
parents: 55111
diff changeset
   141
              s () ^ " expected,\nbut " ^ txt ^ Position.here (Token.pos_of tok) ^
f4b114070675 tuned signature;
wenzelm
parents: 55111
diff changeset
   142
              " was found"
43947
9b00f09f7721 defer evaluation of Scan.message, for improved performance in the frequent situation where failure is handled later (e.g. via ||);
wenzelm
parents: 43775
diff changeset
   143
          | (txt1, txt2) =>
55708
f4b114070675 tuned signature;
wenzelm
parents: 55111
diff changeset
   144
              s () ^ " expected,\nbut " ^ txt1 ^ Position.here (Token.pos_of tok) ^
f4b114070675 tuned signature;
wenzelm
parents: 55111
diff changeset
   145
              " was found:\n" ^ txt2)));
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   146
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   147
5877
ee214dec5657 removed args, args1, thm_xname;
wenzelm
parents: 5826
diff changeset
   148
(* cut *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   149
78819
b8775a63cb35 proper cut for Parse.enum1' and its derivatives (see also 769abc29bb8e);
wenzelm
parents: 78818
diff changeset
   150
val err_prefix = "Outer syntax error";
b8775a63cb35 proper cut for Parse.enum1' and its derivatives (see also 769abc29bb8e);
wenzelm
parents: 78818
diff changeset
   151
b8775a63cb35 proper cut for Parse.enum1' and its derivatives (see also 769abc29bb8e);
wenzelm
parents: 78818
diff changeset
   152
fun !!! scan = Scan.!!! err_prefix Token.input_position scan;
b8775a63cb35 proper cut for Parse.enum1' and its derivatives (see also 769abc29bb8e);
wenzelm
parents: 78818
diff changeset
   153
fun !!!! scan = Scan.!!! err_prefix Token.context_input_position scan;
8581
5c7ed2af8bfb !!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents: 8350
diff changeset
   154
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   155
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   156
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   157
(** basic parsers **)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   158
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   159
(* tokens *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   160
27815
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   161
fun RESET_VALUE atom = (*required for all primitive parsers*)
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   162
  Scan.ahead (Scan.one (K true)) -- atom >> (fn (arg, x) => (Token.assign NONE arg; x));
27815
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   163
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   164
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   165
val not_eof = RESET_VALUE (Scan.one Token.not_eof);
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   166
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   167
fun token atom = Scan.ahead not_eof --| atom;
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   168
59029
c907cbe36713 more careful ML source positions, for improved PIDE markup;
wenzelm
parents: 58908
diff changeset
   169
fun range scan = (Scan.ahead not_eof >> (Token.range_of o single)) -- scan >> Library.swap;
55708
f4b114070675 tuned signature;
wenzelm
parents: 55111
diff changeset
   170
fun position scan = (Scan.ahead not_eof >> Token.pos_of) -- scan >> Library.swap;
59809
87641097d0f3 tuned signature;
wenzelm
parents: 59784
diff changeset
   171
fun input atom = Scan.ahead atom |-- not_eof >> Token.input_of;
55111
5792f5106c40 tuned signature;
wenzelm
parents: 55033
diff changeset
   172
fun inner_syntax atom = Scan.ahead atom |-- not_eof >> Token.inner_syntax_of;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   173
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   174
fun kind k =
44357
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 43947
diff changeset
   175
  group (fn () => Token.str_of_kind k)
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 43947
diff changeset
   176
    (RESET_VALUE (Scan.one (Token.is_kind k) >> Token.content_of));
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   177
67136
1368cfa92b7a tuned signature;
wenzelm
parents: 63806
diff changeset
   178
val command = kind Token.Command;
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   179
val keyword = kind Token.Keyword;
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   180
val short_ident = kind Token.Ident;
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   181
val long_ident = kind Token.Long_Ident;
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   182
val sym_ident = kind Token.Sym_Ident;
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   183
val term_var = kind Token.Var;
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   184
val type_ident = kind Token.Type_Ident;
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   185
val type_var = kind Token.Type_Var;
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   186
val number = kind Token.Nat;
40290
47f572aff50a support for floating-point tokens in outer syntax (coinciding with inner syntax version);
wenzelm
parents: 36959
diff changeset
   187
val float_number = kind Token.Float;
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   188
val string = kind Token.String;
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   189
val alt_string = kind Token.Alt_String;
55033
8e8243975860 support for nested text cartouches;
wenzelm
parents: 51988
diff changeset
   190
val cartouche = kind Token.Cartouche;
74373
6e4093927dbb outer syntax: support for control-cartouche tokens;
wenzelm
parents: 73689
diff changeset
   191
val control = token (kind Token.control_kind) >> (the o Token.get_control);
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   192
val eof = kind Token.EOF;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   193
67136
1368cfa92b7a tuned signature;
wenzelm
parents: 63806
diff changeset
   194
fun command_name x =
48927
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48911
diff changeset
   195
  group (fn () => Token.str_of_kind Token.Command ^ " " ^ quote x)
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48911
diff changeset
   196
    (RESET_VALUE (Scan.one (fn tok => Token.is_command tok andalso Token.content_of tok = x)))
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48911
diff changeset
   197
  >> Token.content_of;
ef462b5558eb theory def/ref position reports, which enable hyperlinks etc.;
wenzelm
parents: 48911
diff changeset
   198
56202
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
   199
fun keyword_with pred = RESET_VALUE (Scan.one (Token.keyword_with pred) >> Token.content_of);
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
   200
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
   201
fun keyword_markup markup x =
44357
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 43947
diff changeset
   202
  group (fn () => Token.str_of_kind Token.Keyword ^ " " ^ quote x)
56063
38f13d055107 more explicit markup for Token.Literal;
wenzelm
parents: 55828
diff changeset
   203
    (Scan.ahead not_eof -- keyword_with (fn y => x = y))
56202
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
   204
  >> (fn (tok, x) => (Token.assign (SOME (Token.Literal markup)) tok; x));
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
   205
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
   206
val keyword_improper = keyword_markup (true, Markup.improper);
0a11d17eeeff more markup for improper elements;
wenzelm
parents: 56201
diff changeset
   207
val $$$ = keyword_markup (false, Markup.quasi_keyword);
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   208
16030
bbfb2f1378b3 added reserved;
wenzelm
parents: 15979
diff changeset
   209
fun reserved x =
44357
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 43947
diff changeset
   210
  group (fn () => "reserved identifier " ^ quote x)
36959
f5417836dbea renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
wenzelm
parents: 36955
diff changeset
   211
    (RESET_VALUE (Scan.one (Token.ident_with (fn y => x = y)) >> Token.content_of));
16030
bbfb2f1378b3 added reserved;
wenzelm
parents: 15979
diff changeset
   212
62529
8b7bdfc09f3b clarified treatment of fragments of Isabelle symbols during bootstrap;
wenzelm
parents: 61814
diff changeset
   213
val dots = sym_ident :-- (fn "\<dots>" => Scan.succeed () | _ => Scan.fail) >> #1;
60629
d4e97fcdf83e allow to specify suffix of goal parameters;
wenzelm
parents: 60448
diff changeset
   214
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   215
val minus = sym_ident :-- (fn "-" => Scan.succeed () | _ => Scan.fail) >> #1;
60629
d4e97fcdf83e allow to specify suffix of goal parameters;
wenzelm
parents: 60448
diff changeset
   216
11792
311eee3d63b6 parser for underscore (actually a symbolic identifier!);
wenzelm
parents: 11651
diff changeset
   217
val underscore = sym_ident :-- (fn "_" => Scan.succeed () | _ => Scan.fail) >> #1;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   218
fun maybe scan = underscore >> K NONE || scan >> SOME;
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   219
fun maybe_position scan = position (underscore >> K NONE) || scan >> apfst SOME;
11792
311eee3d63b6 parser for underscore (actually a symbolic identifier!);
wenzelm
parents: 11651
diff changeset
   220
14835
695ee8ad0bb6 Library.read_int; Output.output;
wenzelm
parents: 14646
diff changeset
   221
val nat = number >> (#1 o Library.read_int o Symbol.explode);
27815
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   222
val int = Scan.optional (minus >> K ~1) 1 -- nat >> op *;
63806
c54a53ef1873 clarified modules;
wenzelm
parents: 63672
diff changeset
   223
val real = float_number >> Value.parse_real || int >> Real.fromInt;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   224
14646
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
   225
fun opt_keyword s = Scan.optional ($$$ "(" |-- !!! (($$$ s >> K true) --| $$$ ")")) false;
59917
9830c944670f more uniform "verbose" option to print name space;
wenzelm
parents: 59809
diff changeset
   226
val opt_bang = Scan.optional ($$$ "!" >> K true) false;
14646
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
   227
20983
d4500b9b220e added begin parser;
wenzelm
parents: 20961
diff changeset
   228
val begin = $$$ "begin";
d4500b9b220e added begin parser;
wenzelm
parents: 20961
diff changeset
   229
val opt_begin = Scan.optional (begin >> K true) false;
20961
555d27f2c210 added opt_begin;
wenzelm
parents: 20273
diff changeset
   230
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   231
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   232
(* enumerations *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   233
55764
wenzelm
parents: 55708
diff changeset
   234
fun enum1_positions sep scan =
wenzelm
parents: 55708
diff changeset
   235
  scan -- Scan.repeat (position ($$$ sep) -- !!! scan) >>
wenzelm
parents: 55708
diff changeset
   236
    (fn (x, ys) => (x :: map #2 ys, map (#2 o #1) ys));
wenzelm
parents: 55708
diff changeset
   237
fun enum_positions sep scan =
wenzelm
parents: 55708
diff changeset
   238
  enum1_positions sep scan || Scan.succeed ([], []);
wenzelm
parents: 55708
diff changeset
   239
25999
f8bcd311d501 added ::: / @@@ scanner combinators;
wenzelm
parents: 25795
diff changeset
   240
fun enum1 sep scan = scan ::: Scan.repeat ($$$ sep |-- !!! scan);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   241
fun enum sep scan = enum1 sep scan || Scan.succeed [];
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   242
78819
b8775a63cb35 proper cut for Parse.enum1' and its derivatives (see also 769abc29bb8e);
wenzelm
parents: 78818
diff changeset
   243
fun enum1' sep scan = scan ::: Scan.repeat (Scan.lift ($$$ sep) |-- !!!! scan);
27815
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   244
fun enum' sep scan = enum1' sep scan || Scan.succeed [];
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   245
6013
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
   246
fun and_list1 scan = enum1 "and" scan;
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
   247
fun and_list scan = enum "and" scan;
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
   248
27815
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   249
fun and_list1' scan = enum1' "and" scan;
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   250
fun and_list' scan = enum' "and" scan;
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   251
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   252
fun list1 scan = enum1 "," scan;
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   253
fun list scan = enum "," scan;
2d36632bc5de unified Args.T with OuterLex.token;
wenzelm
parents: 27788
diff changeset
   254
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   255
63120
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
   256
(* names and embedded content *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   257
62969
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 62965
diff changeset
   258
val name =
63120
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
   259
  group (fn () => "name")
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
   260
    (short_ident || long_ident || sym_ident || number || string);
44357
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 43947
diff changeset
   261
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   262
val name_range = input name >> Input.source_content_range;
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   263
val name_position = input name >> Input.source_content;
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   264
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   265
val string_position = input string >> Input.source_content;
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   266
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   267
val binding = name_position >> Binding.make;
44357
5f5649ac8235 tuned Parse.group: delayed failure message;
wenzelm
parents: 43947
diff changeset
   268
63120
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
   269
val embedded =
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
   270
  group (fn () => "embedded content")
63137
9553f11d67c4 simplified syntax: Parse.term corresponds to Args.term etc.;
wenzelm
parents: 63120
diff changeset
   271
    (cartouche || string || short_ident || long_ident || sym_ident ||
9553f11d67c4 simplified syntax: Parse.term corresponds to Args.term etc.;
wenzelm
parents: 63120
diff changeset
   272
      term_var || type_ident || type_var || number);
63120
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
   273
74563
042041c0ebeb clarified modules;
wenzelm
parents: 74562
diff changeset
   274
val embedded_inner_syntax = inner_syntax embedded;
70205
3293471cf176 tuned signature;
wenzelm
parents: 70047
diff changeset
   275
val embedded_input = input embedded;
3293471cf176 tuned signature;
wenzelm
parents: 70047
diff changeset
   276
val embedded_position = embedded_input >> Input.source_content;
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   277
72840
6b96464066a0 tuned signature --- more operations;
wenzelm
parents: 70205
diff changeset
   278
val path_input = group (fn () => "file name/path specification") embedded_input;
6b96464066a0 tuned signature --- more operations;
wenzelm
parents: 70205
diff changeset
   279
val path = path_input >> Input.string_of;
70047
96fe857a7a6f clarified signature: more explicit operations for corresponding Isar commands;
wenzelm
parents: 69891
diff changeset
   280
val path_binding = group (fn () => "path binding (strict file name)") (position embedded);
6553
dc962d157a63 comment, interest;
wenzelm
parents: 6511
diff changeset
   281
76614
ac08b6e3b9e3 clarified signature;
wenzelm
parents: 75986
diff changeset
   282
fun in_path default =
ac08b6e3b9e3 clarified signature;
wenzelm
parents: 75986
diff changeset
   283
  Scan.optional ($$$ "in" |-- !!! path_input) (Input.string default);
ac08b6e3b9e3 clarified signature;
wenzelm
parents: 75986
diff changeset
   284
ac08b6e3b9e3 clarified signature;
wenzelm
parents: 75986
diff changeset
   285
fun in_path_parens default =
ac08b6e3b9e3 clarified signature;
wenzelm
parents: 75986
diff changeset
   286
  Scan.optional ($$$ "(" |-- !!! ($$$ "in" |-- path_input --| $$$ ")")) (Input.string default);
ac08b6e3b9e3 clarified signature;
wenzelm
parents: 75986
diff changeset
   287
75986
27d98da31985 support 'chapter_definition' with description for presentation purposes;
wenzelm
parents: 74887
diff changeset
   288
val chapter_name = group (fn () => "chapter name") name_position;
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   289
val session_name = group (fn () => "session name") name_position;
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   290
val theory_name = group (fn () => "theory name") name_position;
59693
d96cb03caf9e tunes signature -- more uniform ML vs. Scala;
wenzelm
parents: 59081
diff changeset
   291
62969
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 62965
diff changeset
   292
val liberal_name = keyword_with Token.ident_or_symbolic || name;
40800
330eb65c9469 Parse.liberal_name for document antiquotations and attributes;
wenzelm
parents: 40793
diff changeset
   293
18898
e3d2aa8ba0e1 added parname;
wenzelm
parents: 18669
diff changeset
   294
val parname = Scan.optional ($$$ "(" |-- name --| $$$ ")") "";
28965
1de908189869 cleaned up binding module and related code
haftmann
parents: 28941
diff changeset
   295
val parbinding = Scan.optional ($$$ "(" |-- binding --| $$$ ")") Binding.empty;
18898
e3d2aa8ba0e1 added parname;
wenzelm
parents: 18669
diff changeset
   296
6553
dc962d157a63 comment, interest;
wenzelm
parents: 6511
diff changeset
   297
46922
3717f3878714 source positions for locale and class expressions;
wenzelm
parents: 45596
diff changeset
   298
(* type classes *)
3717f3878714 source positions for locale and class expressions;
wenzelm
parents: 45596
diff changeset
   299
63120
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
   300
val class = group (fn () => "type class") (inner_syntax embedded);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   301
63120
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
   302
val sort = group (fn () => "sort") (inner_syntax embedded);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   303
63120
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
   304
val type_const = group (fn () => "type constructor") (inner_syntax embedded);
46922
3717f3878714 source positions for locale and class expressions;
wenzelm
parents: 45596
diff changeset
   305
3717f3878714 source positions for locale and class expressions;
wenzelm
parents: 45596
diff changeset
   306
val arity = type_const -- ($$$ "::" |-- !!!
61466
9a468c3a1fa1 tuned signature;
wenzelm
parents: 60629
diff changeset
   307
  (Scan.optional ($$$ "(" |-- !!! (list1 sort --| $$$ ")")) [] -- sort)) >> Scan.triple2;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   308
46922
3717f3878714 source positions for locale and class expressions;
wenzelm
parents: 45596
diff changeset
   309
val multi_arity = and_list1 type_const -- ($$$ "::" |-- !!!
61466
9a468c3a1fa1 tuned signature;
wenzelm
parents: 60629
diff changeset
   310
  (Scan.optional ($$$ "(" |-- !!! (list1 sort --| $$$ ")")) [] -- sort)) >> Scan.triple2;
25541
68de88c7e877 added parser for multi_arity
haftmann
parents: 24910
diff changeset
   311
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   312
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   313
(* types *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   314
63137
9553f11d67c4 simplified syntax: Parse.term corresponds to Args.term etc.;
wenzelm
parents: 63120
diff changeset
   315
val typ = group (fn () => "type") (inner_syntax embedded);
27753
94b672153b49 sort/typ/term/prop: inner_syntax markup encodes original source position;
wenzelm
parents: 27737
diff changeset
   316
35838
c8bd075c4de8 support type arguments with sort constraints;
wenzelm
parents: 35351
diff changeset
   317
fun type_arguments arg =
c8bd075c4de8 support type arguments with sort constraints;
wenzelm
parents: 35351
diff changeset
   318
  arg >> single ||
c8bd075c4de8 support type arguments with sort constraints;
wenzelm
parents: 35351
diff changeset
   319
  $$$ "(" |-- !!! (list1 arg --| $$$ ")") ||
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   320
  Scan.succeed [];
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   321
35838
c8bd075c4de8 support type arguments with sort constraints;
wenzelm
parents: 35351
diff changeset
   322
val type_args = type_arguments type_ident;
c8bd075c4de8 support type arguments with sort constraints;
wenzelm
parents: 35351
diff changeset
   323
val type_args_constrained = type_arguments (type_ident -- Scan.option ($$$ "::" |-- !!! sort));
c8bd075c4de8 support type arguments with sort constraints;
wenzelm
parents: 35351
diff changeset
   324
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   325
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   326
(* mixfix annotations *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   327
51654
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   328
local
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   329
69580
6f755e3cd95d mixfix annotations may use cartouches;
wenzelm
parents: 69579
diff changeset
   330
val mfix = input (string || cartouche);
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   331
69579
wenzelm
parents: 69349
diff changeset
   332
val mixfix_ =
wenzelm
parents: 69349
diff changeset
   333
  mfix -- !!! (Scan.optional ($$$ "[" |-- !!! (list nat --| $$$ "]")) [] -- Scan.optional nat 1000)
wenzelm
parents: 69349
diff changeset
   334
    >> (fn (sy, (ps, p)) => fn range => Mixfix (sy, ps, p, range));
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   335
69579
wenzelm
parents: 69349
diff changeset
   336
val structure_ = $$$ "structure" >> K Structure;
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   337
69579
wenzelm
parents: 69349
diff changeset
   338
val binder_ =
wenzelm
parents: 69349
diff changeset
   339
  $$$ "binder" |-- !!! (mfix -- ($$$ "[" |-- nat --| $$$ "]" -- nat || nat >> (fn n => (n, n))))
wenzelm
parents: 69349
diff changeset
   340
    >> (fn (sy, (p, q)) => fn range => Binder (sy, p, q, range));
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   341
69579
wenzelm
parents: 69349
diff changeset
   342
val infixl_ = $$$ "infixl" |-- !!! (mfix -- nat >> (fn (sy, p) => fn range => Infixl (sy, p, range)));
wenzelm
parents: 69349
diff changeset
   343
val infixr_ = $$$ "infixr" |-- !!! (mfix -- nat >> (fn (sy, p) => fn range => Infixr (sy, p, range)));
wenzelm
parents: 69349
diff changeset
   344
val infix_ = $$$ "infix" |-- !!! (mfix -- nat >> (fn (sy, p) => fn range => Infix (sy, p, range)));
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   345
69579
wenzelm
parents: 69349
diff changeset
   346
val mixfix_body = mixfix_ || structure_ || binder_ || infixl_ || infixr_ || infix_;
51654
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   347
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   348
fun annotation guard body =
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   349
  Scan.trace ($$$ "(" |-- guard (body --| $$$ ")"))
62760
wenzelm
parents: 62752
diff changeset
   350
    >> (fn (mx, toks) => mx (Token.range_of toks));
62752
d09d71223e7a more position information for type mixfix;
wenzelm
parents: 62529
diff changeset
   351
51654
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   352
fun opt_annotation guard body = Scan.optional (annotation guard body) NoSyn;
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   353
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   354
in
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   355
51654
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   356
val mixfix = annotation !!! mixfix_body;
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   357
val mixfix' = annotation I mixfix_body;
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   358
val opt_mixfix = opt_annotation !!! mixfix_body;
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   359
val opt_mixfix' = opt_annotation I mixfix_body;
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   360
8450b944e58a just one syntax category "mixfix" -- check structure annotation semantically;
wenzelm
parents: 51627
diff changeset
   361
end;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   362
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   363
62856
3f97aa4580c6 tuned -- more explicit sections;
wenzelm
parents: 62760
diff changeset
   364
(* syntax mode *)
3f97aa4580c6 tuned -- more explicit sections;
wenzelm
parents: 62760
diff changeset
   365
3f97aa4580c6 tuned -- more explicit sections;
wenzelm
parents: 62760
diff changeset
   366
val syntax_mode_spec =
3f97aa4580c6 tuned -- more explicit sections;
wenzelm
parents: 62760
diff changeset
   367
  ($$$ "output" >> K ("", false)) || name -- Scan.optional ($$$ "output" >> K false) true;
3f97aa4580c6 tuned -- more explicit sections;
wenzelm
parents: 62760
diff changeset
   368
3f97aa4580c6 tuned -- more explicit sections;
wenzelm
parents: 62760
diff changeset
   369
val syntax_mode =
3f97aa4580c6 tuned -- more explicit sections;
wenzelm
parents: 62760
diff changeset
   370
  Scan.optional ($$$ "(" |-- !!! (syntax_mode_spec --| $$$ ")")) Syntax.mode_default;
3f97aa4580c6 tuned -- more explicit sections;
wenzelm
parents: 62760
diff changeset
   371
3f97aa4580c6 tuned -- more explicit sections;
wenzelm
parents: 62760
diff changeset
   372
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   373
(* fixes *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   374
21400
4788fc8e66ea added where_;
wenzelm
parents: 21371
diff changeset
   375
val where_ = $$$ "where";
4788fc8e66ea added where_;
wenzelm
parents: 21371
diff changeset
   376
61466
9a468c3a1fa1 tuned signature;
wenzelm
parents: 60629
diff changeset
   377
val const_decl = name -- ($$$ "::" |-- !!! typ) -- opt_mixfix >> Scan.triple1;
9a468c3a1fa1 tuned signature;
wenzelm
parents: 60629
diff changeset
   378
val const_binding = binding -- ($$$ "::" |-- !!! typ) -- opt_mixfix >> Scan.triple1;
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   379
61466
9a468c3a1fa1 tuned signature;
wenzelm
parents: 60629
diff changeset
   380
val param_mixfix = binding -- Scan.option ($$$ "::" |-- typ) -- mixfix' >> (single o Scan.triple1);
63230
ae5275fa96dc avoid multiple reports on shared type;
wenzelm
parents: 63139
diff changeset
   381
60448
78f3c67bc35e support for 'consider' command;
wenzelm
parents: 59990
diff changeset
   382
val params =
63230
ae5275fa96dc avoid multiple reports on shared type;
wenzelm
parents: 63139
diff changeset
   383
  (binding -- Scan.repeat binding) -- Scan.option ($$$ "::" |-- !!! (Scan.ahead typ -- embedded))
ae5275fa96dc avoid multiple reports on shared type;
wenzelm
parents: 63139
diff changeset
   384
    >> (fn ((x, ys), T) =>
ae5275fa96dc avoid multiple reports on shared type;
wenzelm
parents: 63139
diff changeset
   385
        (x, Option.map #1 T, NoSyn) :: map (fn y => (y, Option.map #2 T, NoSyn)) ys);
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   386
63285
e9c777bfd78c clarified syntax;
wenzelm
parents: 63230
diff changeset
   387
val vars = and_list1 (param_mixfix || params) >> flat;
e9c777bfd78c clarified syntax;
wenzelm
parents: 63230
diff changeset
   388
e9c777bfd78c clarified syntax;
wenzelm
parents: 63230
diff changeset
   389
val for_fixes = Scan.optional ($$$ "for" |-- !!! vars) [];
19845
b8985bf2ce8b added for_fixes;
wenzelm
parents: 19811
diff changeset
   390
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   391
27877
af9f0adbab1f renamed P.ml_source to P.ML_source;
wenzelm
parents: 27872
diff changeset
   392
(* embedded source text *)
27872
631371a02b8c P.doc_source and P.ml_sorce for proper SymbolPos.text;
wenzelm
parents: 27815
diff changeset
   393
74887
56247fdb8bbb discontinued old-style {* verbatim *} tokens;
wenzelm
parents: 74879
diff changeset
   394
val ML_source = input (group (fn () => "ML source") embedded);
56247fdb8bbb discontinued old-style {* verbatim *} tokens;
wenzelm
parents: 74879
diff changeset
   395
val document_source = input (group (fn () => "document source") embedded);
27872
631371a02b8c P.doc_source and P.ml_sorce for proper SymbolPos.text;
wenzelm
parents: 27815
diff changeset
   396
69891
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69876
diff changeset
   397
val document_marker =
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69876
diff changeset
   398
  group (fn () => "document marker")
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69876
diff changeset
   399
    (RESET_VALUE (Scan.one Token.is_document_marker >> Token.input_of));
def3ec9cdb7e document markers are formal comments, and may thus occur anywhere in the command-span;
wenzelm
parents: 69876
diff changeset
   400
27872
631371a02b8c P.doc_source and P.ml_sorce for proper SymbolPos.text;
wenzelm
parents: 27815
diff changeset
   401
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   402
(* terms *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   403
63120
629a4c5e953e embedded content may be delimited via cartouches;
wenzelm
parents: 62969
diff changeset
   404
val const = group (fn () => "constant") (inner_syntax embedded);
63137
9553f11d67c4 simplified syntax: Parse.term corresponds to Args.term etc.;
wenzelm
parents: 63120
diff changeset
   405
val term = group (fn () => "term") (inner_syntax embedded);
9553f11d67c4 simplified syntax: Parse.term corresponds to Args.term etc.;
wenzelm
parents: 63120
diff changeset
   406
val prop = group (fn () => "proposition") (inner_syntax embedded);
42300
0d1cbc1fe579 notation: proper markup for type constructor / constant;
wenzelm
parents: 42299
diff changeset
   407
56499
7e0178c84994 allow text cartouches in regular outer syntax categories "text" and "altstring";
wenzelm
parents: 56202
diff changeset
   408
val literal_fact = inner_syntax (group (fn () => "literal fact") (alt_string || cartouche));
40793
d21aedaa91e7 added Parse.literal_fact with proper inner_syntax markup (source position);
wenzelm
parents: 40296
diff changeset
   409
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   410
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
   411
(* patterns *)
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   412
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
   413
val is_terms = Scan.repeat1 ($$$ "is" |-- term);
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   414
val is_props = Scan.repeat1 ($$$ "is" |-- prop);
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   415
19585
70a1ce3b23ae removed 'concl is' patterns;
wenzelm
parents: 19482
diff changeset
   416
val propp = prop -- Scan.optional ($$$ "(" |-- !!! (is_props --| $$$ ")")) [];
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
   417
val termp = term -- Scan.optional ($$$ "(" |-- !!! (is_terms --| $$$ ")")) [];
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   418
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   419
59924
801b979ec0c2 more general notion of command span: command keyword not necessarily at start;
wenzelm
parents: 59918
diff changeset
   420
(* target information *)
801b979ec0c2 more general notion of command span: command keyword not necessarily at start;
wenzelm
parents: 59918
diff changeset
   421
801b979ec0c2 more general notion of command span: command keyword not necessarily at start;
wenzelm
parents: 59918
diff changeset
   422
val private = position ($$$ "private") >> #2;
59990
a81dc82ecba3 clarified keyword 'qualified' in accordance to a similar keyword from Haskell (despite unrelated Binding.qualified in Isabelle/ML);
wenzelm
parents: 59939
diff changeset
   423
val qualified = position ($$$ "qualified") >> #2;
19811
46abcbb2da9d added locale_insts;
wenzelm
parents: 19585
diff changeset
   424
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   425
val target = ($$$ "(" -- $$$ "in") |-- !!! (name_position --| $$$ ")");
22119
6f1c82c0243c moved parts to spec_parse.ML;
wenzelm
parents: 21858
diff changeset
   426
val opt_target = Scan.option target;
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   427
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   428
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   429
(* arguments within outer syntax *)
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   430
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   431
local
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   432
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   433
val argument_kinds =
59081
2ceb05ee0331 clarified token kind;
wenzelm
parents: 59064
diff changeset
   434
 [Token.Ident, Token.Long_Ident, Token.Sym_Ident, Token.Var, Token.Type_Ident, Token.Type_Var,
74887
56247fdb8bbb discontinued old-style {* verbatim *} tokens;
wenzelm
parents: 74879
diff changeset
   435
  Token.Nat, Token.Float, Token.String, Token.Alt_String, Token.Cartouche];
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   436
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   437
fun arguments is_symid =
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   438
  let
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   439
    fun argument blk =
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   440
      group (fn () => "argument")
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   441
        (Scan.one (fn tok =>
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   442
          let val kind = Token.kind_of tok in
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   443
            member (op =) argument_kinds kind orelse
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   444
            Token.keyword_with is_symid tok orelse
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   445
            (blk andalso Token.keyword_with (fn s => s = ",") tok)
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   446
          end));
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   447
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   448
    fun args blk x = Scan.optional (args1 blk) [] x
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   449
    and args1 blk x =
61476
1884c40f1539 tuned signature;
wenzelm
parents: 61466
diff changeset
   450
      (Scan.repeats1 (Scan.repeat1 (argument blk) || argsp "(" ")" || argsp "[" "]")) x
56201
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   451
    and argsp l r x = (token ($$$ l) ::: !!! (args true @@@ (token ($$$ r) >> single))) x;
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   452
  in (args, args1) end;
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   453
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   454
in
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   455
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   456
val args = #1 (arguments Token.ident_or_symbolic) false;
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   457
fun args1 is_symid = #2 (arguments is_symid) false;
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   458
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   459
end;
dd2df97b379b tuned signature;
wenzelm
parents: 56063
diff changeset
   460
58028
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   461
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   462
(* attributes *)
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   463
61814
1ca1142e1711 clarified type Token.src: plain token list, with usual implicit value assignment;
wenzelm
parents: 61476
diff changeset
   464
val attrib = token liberal_name ::: !!! args;
58028
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   465
val attribs = $$$ "[" |-- list attrib --| $$$ "]";
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   466
val opt_attribs = Scan.optional attribs [];
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   467
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   468
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   469
(* theorem references *)
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   470
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   471
val thm_sel = $$$ "(" |-- list1
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   472
 (nat --| minus -- nat >> Facts.FromTo ||
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   473
  nat --| minus >> Facts.From ||
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   474
  nat >> Facts.Single) --| $$$ ")";
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   475
62969
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 62965
diff changeset
   476
val thm =
58028
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   477
  $$$ "[" |-- attribs --| $$$ "]" >> pair (Facts.named "") ||
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   478
  (literal_fact >> Facts.Fact ||
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   479
    name_position -- Scan.option thm_sel >> Facts.Named) -- opt_attribs;
58028
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   480
62969
9f394a16c557 eliminated "xname" and variants;
wenzelm
parents: 62965
diff changeset
   481
val thms1 = Scan.repeat1 thm;
58028
e4250d370657 tuned signature -- define some elementary operations earlier;
wenzelm
parents: 58011
diff changeset
   482
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   483
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   484
(* options *)
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   485
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   486
val option_name = group (fn () => "option name") name_position;
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   487
val option_value = group (fn () => "option value") ((token real || token name) >> Token.content_of);
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   488
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   489
val option =
69349
7cef9e386ffe more accurate positions for "name" (quoted string) and "embedded" (cartouche): refer to content without delimiters, which is e.g. relevant for systematic selection/renaming of scope groups;
wenzelm
parents: 67215
diff changeset
   490
  option_name :-- (fn (_, pos) =>
67215
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   491
    Scan.optional ($$$ "=" |-- !!! (position option_value)) ("true", pos));
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   492
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   493
val options = $$$ "[" |-- list1 option --| $$$ "]";
03d0c958d65a PIDE markup for session ROOT files;
wenzelm
parents: 67136
diff changeset
   494
74562
8403bd51f8b1 clarified modules;
wenzelm
parents: 74373
diff changeset
   495
8403bd51f8b1 clarified modules;
wenzelm
parents: 74373
diff changeset
   496
(* embedded ML *)
8403bd51f8b1 clarified modules;
wenzelm
parents: 74373
diff changeset
   497
8403bd51f8b1 clarified modules;
wenzelm
parents: 74373
diff changeset
   498
val embedded_ml =
74879
89c7f74b5ae1 clarified Parse.embedded_ml: follow documentation (8baf2e8b16e2);
wenzelm
parents: 74567
diff changeset
   499
  input underscore >> ML_Lex.read_source ||
74562
8403bd51f8b1 clarified modules;
wenzelm
parents: 74373
diff changeset
   500
  embedded_input >> ML_Lex.read_source ||
8403bd51f8b1 clarified modules;
wenzelm
parents: 74373
diff changeset
   501
  control >> (ML_Lex.read_symbols o Antiquote.control_symbols);
8403bd51f8b1 clarified modules;
wenzelm
parents: 74373
diff changeset
   502
74564
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   503
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   504
(* read embedded source, e.g. for antiquotations *)
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   505
74565
wenzelm
parents: 74564
diff changeset
   506
fun tokenize keywords = Token.tokenize keywords {strict = true} #> filter Token.is_proper;
wenzelm
parents: 74564
diff changeset
   507
74564
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   508
fun read_antiq keywords scan (syms, pos) =
74567
40910c47d7a1 tuned signature;
wenzelm
parents: 74565
diff changeset
   509
  (case Scan.read Token.stopper scan (tokenize (Keyword.no_major_keywords keywords) syms) of
74565
wenzelm
parents: 74564
diff changeset
   510
    SOME res => res
wenzelm
parents: 74564
diff changeset
   511
  | NONE => error ("Malformed antiquotation" ^ Position.here pos));
74564
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   512
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   513
fun read_embedded ctxt keywords parse input =
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   514
  let
74565
wenzelm
parents: 74564
diff changeset
   515
    val toks = tokenize keywords (Input.source_explode input);
74564
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   516
    val _ = Context_Position.reports_text ctxt (maps (Token.reports keywords) toks);
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   517
  in
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   518
    (case Scan.read Token.stopper parse toks of
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   519
      SOME res => res
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   520
    | NONE => error ("Bad input" ^ Position.here (Input.pos_of input)))
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   521
  end;
0a66a61e740c clarified modules;
wenzelm
parents: 74563
diff changeset
   522
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   523
end;