src/Pure/Isar/outer_parse.ML
author ballarin
Mon, 27 Sep 2004 10:27:34 +0200
changeset 15206 09d78ec709c7
parent 15127 2550a5578d39
child 15456 956d6acacf89
permissions -rw-r--r--
Modified locales: improved implementation of "includes".
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/Isar/outer_parse.ML
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     2
    ID:         $Id$
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     3
    Author:     Markus Wenzel, TU Muenchen
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     4
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     5
Generic parsers for Isabelle/Isar outer syntax.
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     6
*)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     7
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     8
signature OUTER_PARSE =
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
     9
sig
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    10
  type token
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    11
  val group: string -> (token list -> 'a) -> token list -> 'a
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    12
  val !!! : (token list -> 'a) -> token list -> 'a
8581
5c7ed2af8bfb !!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents: 8350
diff changeset
    13
  val !!!! : (token list -> 'a) -> token list -> 'a
12047
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
    14
  val triple1: ('a * 'b) * 'c -> 'a * 'b * 'c
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
    15
  val triple2: 'a * ('b * 'c) -> 'a * 'b * 'c
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
    16
  val triple_swap: ('a * 'b) * 'c -> ('a * 'c) * 'b
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    17
  val $$$ : string -> token list -> string * token list
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
    18
  val semicolon: token list -> string * token list
11792
311eee3d63b6 parser for underscore (actually a symbolic identifier!);
wenzelm
parents: 11651
diff changeset
    19
  val underscore: token list -> string * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    20
  val position: (token list -> 'a * 'b) -> token list -> ('a * Position.T) * 'b
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6983
diff changeset
    21
  val command: token list -> string * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    22
  val keyword: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    23
  val short_ident: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    24
  val long_ident: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    25
  val sym_ident: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    26
  val term_var: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    27
  val type_ident: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    28
  val type_var: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    29
  val number: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    30
  val string: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    31
  val verbatim: token list -> string * token list
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6726
diff changeset
    32
  val sync: token list -> string * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    33
  val eof: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    34
  val not_eof: token list -> token * token list
7930
220892918bd1 added opt_unit (from isar_syn.ML);
wenzelm
parents: 7477
diff changeset
    35
  val opt_unit: token list -> unit * token list
14646
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
    36
  val opt_keyword: string -> token list -> bool * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    37
  val nat: token list -> int * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    38
  val enum: string -> (token list -> 'a * token list) -> token list -> 'a list * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    39
  val enum1: string -> (token list -> 'a * token list) -> token list -> 'a list * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    40
  val list: (token list -> 'a * token list) -> token list -> 'a list * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    41
  val list1: (token list -> 'a * token list) -> token list -> 'a list * token list
6013
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
    42
  val and_list: (token list -> 'a * token list) -> token list -> 'a list * token list
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
    43
  val and_list1: (token list -> 'a * token list) -> token list -> 'a list * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    44
  val name: token list -> bstring * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    45
  val xname: token list -> xstring * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    46
  val text: token list -> string * token list
14949
5f5605361aad added path;
wenzelm
parents: 14835
diff changeset
    47
  val path: token list -> Path.T * token list
12268
28e60c998eee added uname;
wenzelm
parents: 12263
diff changeset
    48
  val uname: token list -> string option * token list
8897
fb1436ca3b2e adapted to inner syntax of sorts;
wenzelm
parents: 8807
diff changeset
    49
  val sort: token list -> string * token list
fb1436ca3b2e adapted to inner syntax of sorts;
wenzelm
parents: 8807
diff changeset
    50
  val arity: token list -> (string list * string) * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    51
  val type_args: token list -> string list * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    52
  val typ: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    53
  val opt_infix: token list -> Syntax.mixfix * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    54
  val opt_mixfix: token list -> Syntax.mixfix * token list
9037
91cbae314c84 opt_mixfix', opt_infix';
wenzelm
parents: 8897
diff changeset
    55
  val opt_infix': token list -> Syntax.mixfix * token list
91cbae314c84 opt_mixfix', opt_infix';
wenzelm
parents: 8897
diff changeset
    56
  val opt_mixfix': token list -> Syntax.mixfix * token list
14646
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
    57
  val mixfix': token list -> Syntax.mixfix * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    58
  val const: token list -> (bstring * string * Syntax.mixfix) * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    59
  val term: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    60
  val prop: token list -> string * token list
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
    61
  val propp: token list -> (string * (string list * string list)) * token list
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
    62
  val termp: token list -> (string * string list) * token list
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
    63
  val arguments: token list -> Args.T list * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    64
  val attribs: token list -> Args.src list * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    65
  val opt_attribs: token list -> Args.src list * token list
5917
dcb669fda86b generalized (opt_)thm_name;
wenzelm
parents: 5877
diff changeset
    66
  val thm_name: string -> token list -> (bstring * Args.src list) * token list
dcb669fda86b generalized (opt_)thm_name;
wenzelm
parents: 5877
diff changeset
    67
  val opt_thm_name: string -> token list -> (bstring * Args.src list) * token list
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
    68
  val spec_name: token list -> ((bstring * string) * Args.src list) * token list
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
    69
  val spec_opt_name: token list -> ((bstring * string) * Args.src list) * token list
5917
dcb669fda86b generalized (opt_)thm_name;
wenzelm
parents: 5877
diff changeset
    70
  val xthm: token list -> (xstring * Args.src list) * token list
dcb669fda86b generalized (opt_)thm_name;
wenzelm
parents: 5877
diff changeset
    71
  val xthms1: token list -> (xstring * Args.src list) list * token list
12942
48fbe245879e export locale_target, locale_keyword;
wenzelm
parents: 12876
diff changeset
    72
  val locale_target: token list -> xstring option * token list
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
    73
  val locale_expr: token list -> Locale.expr * token list
12942
48fbe245879e export locale_target, locale_keyword;
wenzelm
parents: 12876
diff changeset
    74
  val locale_keyword: token list -> string * token list
12047
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
    75
  val locale_element: token list -> Args.src Locale.element * token list
15206
09d78ec709c7 Modified locales: improved implementation of "includes".
ballarin
parents: 15127
diff changeset
    76
  val locale_elem_or_expr: token list -> Args.src Locale.element Locale.elem_expr * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    77
  val method: token list -> Method.text * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    78
end;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    79
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    80
structure OuterParse: OUTER_PARSE =
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    81
struct
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    82
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
    83
structure T = OuterLex;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
    84
type token = T.token;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    85
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    86
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    87
(** error handling **)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    88
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    89
(* group atomic parsers (no cuts!) *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    90
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    91
fun fail_with s = Scan.fail_with
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    92
  (fn [] => s ^ " expected (past end-of-file!)"
9155
adfa40218e06 OuterLex.name_of: include val;
wenzelm
parents: 9131
diff changeset
    93
    | (tok :: _) => s ^ " expected,\nbut " ^ T.name_of tok ^ T.pos_of tok ^ " was found");
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    94
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    95
fun group s scan = scan || fail_with s;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    96
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    97
5877
ee214dec5657 removed args, args1, thm_xname;
wenzelm
parents: 5826
diff changeset
    98
(* cut *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    99
8581
5c7ed2af8bfb !!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents: 8350
diff changeset
   100
fun cut kind scan =
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   101
  let
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   102
    fun get_pos [] = " (past end-of-file!)"
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   103
      | get_pos (tok :: _) = T.pos_of tok;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   104
8581
5c7ed2af8bfb !!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents: 8350
diff changeset
   105
    fun err (toks, None) = kind ^ get_pos toks
5c7ed2af8bfb !!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents: 8350
diff changeset
   106
      | err (toks, Some msg) = kind ^ get_pos toks ^ ": " ^ msg;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   107
  in Scan.!! err scan end;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   108
8586
e451c4865548 made SML/NJ happy;
wenzelm
parents: 8581
diff changeset
   109
fun !!! scan = cut "Outer syntax error" scan;
e451c4865548 made SML/NJ happy;
wenzelm
parents: 8581
diff changeset
   110
fun !!!! scan = cut "Corrupted outer syntax in presentation" scan;
8581
5c7ed2af8bfb !!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents: 8350
diff changeset
   111
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   112
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   113
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   114
(** basic parsers **)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   115
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   116
(* utils *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   117
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   118
fun triple1 ((x, y), z) = (x, y, z);
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   119
fun triple2 (x, (y, z)) = (x, y, z);
6430
69400c97d3bf triple_swap;
wenzelm
parents: 6398
diff changeset
   120
fun triple_swap ((x, y), z) = ((x, z), y);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   121
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   122
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   123
(* tokens *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   124
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   125
fun position scan =
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   126
  (Scan.ahead (Scan.one T.not_eof) >> T.position_of) -- scan >> Library.swap;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   127
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   128
fun kind k =
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   129
  group (T.str_of_kind k) (Scan.one (T.is_kind k) >> T.val_of);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   130
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   131
val command = kind T.Command;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   132
val keyword = kind T.Keyword;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   133
val short_ident = kind T.Ident;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   134
val long_ident = kind T.LongIdent;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   135
val sym_ident = kind T.SymIdent;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   136
val term_var = kind T.Var;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   137
val type_ident = kind T.TypeIdent;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   138
val type_var = kind T.TypeVar;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   139
val number = kind T.Nat;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   140
val string = kind T.String;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   141
val verbatim = kind T.Verbatim;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   142
val sync = kind T.Sync;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   143
val eof = kind T.EOF;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   144
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   145
fun $$$ x =
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   146
  group (T.str_of_kind T.Keyword ^ " " ^ quote x)
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   147
    (Scan.one (T.keyword_with (equal x)) >> T.val_of);
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   148
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   149
val semicolon = $$$ ";";
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   150
11792
311eee3d63b6 parser for underscore (actually a symbolic identifier!);
wenzelm
parents: 11651
diff changeset
   151
val underscore = sym_ident :-- (fn "_" => Scan.succeed () | _ => Scan.fail) >> #1;
311eee3d63b6 parser for underscore (actually a symbolic identifier!);
wenzelm
parents: 11651
diff changeset
   152
14835
695ee8ad0bb6 Library.read_int; Output.output;
wenzelm
parents: 14646
diff changeset
   153
val nat = number >> (#1 o Library.read_int o Symbol.explode);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   154
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   155
val not_eof = Scan.one T.not_eof;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   156
7930
220892918bd1 added opt_unit (from isar_syn.ML);
wenzelm
parents: 7477
diff changeset
   157
val opt_unit = Scan.optional ($$$ "(" -- $$$ ")" >> (K ())) ();
220892918bd1 added opt_unit (from isar_syn.ML);
wenzelm
parents: 7477
diff changeset
   158
14646
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
   159
fun opt_keyword s = Scan.optional ($$$ "(" |-- !!! (($$$ s >> K true) --| $$$ ")")) false;
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
   160
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   161
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   162
(* enumerations *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   163
6003
b382568901f6 enum: !!! after seperator;
wenzelm
parents: 5960
diff changeset
   164
fun enum1 sep scan = scan -- Scan.repeat ($$$ sep |-- !!! scan) >> op ::;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   165
fun enum sep scan = enum1 sep scan || Scan.succeed [];
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   166
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   167
fun list1 scan = enum1 "," scan;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   168
fun list scan = enum "," scan;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   169
6013
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
   170
fun and_list1 scan = enum1 "and" scan;
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
   171
fun and_list scan = enum "and" scan;
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
   172
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   173
5960
2bebd0d0a961 comment parser;
wenzelm
parents: 5940
diff changeset
   174
(* names and text *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   175
8146
3243f2261d4b 'name' etc. include 'number';
wenzelm
parents: 8077
diff changeset
   176
val name = group "name declaration" (short_ident || sym_ident || string || number);
3243f2261d4b 'name' etc. include 'number';
wenzelm
parents: 8077
diff changeset
   177
val xname = group "name reference" (short_ident || long_ident || sym_ident || string || number);
3243f2261d4b 'name' etc. include 'number';
wenzelm
parents: 8077
diff changeset
   178
val text = group "text" (short_ident || long_ident || sym_ident || string || number || verbatim);
14949
5f5605361aad added path;
wenzelm
parents: 14835
diff changeset
   179
val path = group "file name/path specification" name >> Path.unpack;
6553
dc962d157a63 comment, interest;
wenzelm
parents: 6511
diff changeset
   180
12268
28e60c998eee added uname;
wenzelm
parents: 12263
diff changeset
   181
val uname = underscore >> K None || name >> Some;
14646
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
   182
6553
dc962d157a63 comment, interest;
wenzelm
parents: 6511
diff changeset
   183
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   184
(* sorts and arities *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   185
8897
fb1436ca3b2e adapted to inner syntax of sorts;
wenzelm
parents: 8807
diff changeset
   186
val sort = group "sort" xname;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   187
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   188
fun gen_arity cod =
7352
d98001b492b3 fixed arity;
wenzelm
parents: 7171
diff changeset
   189
  Scan.optional ($$$ "(" |-- !!! (list1 sort --| $$$ ")")) [] -- cod;
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   190
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   191
val arity = gen_arity sort;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   192
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   193
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   194
(* types *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   195
8146
3243f2261d4b 'name' etc. include 'number';
wenzelm
parents: 8077
diff changeset
   196
val typ = group "type"
3243f2261d4b 'name' etc. include 'number';
wenzelm
parents: 8077
diff changeset
   197
  (short_ident || long_ident || sym_ident || type_ident || type_var || string || number);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   198
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   199
val type_args =
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   200
  type_ident >> single ||
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   201
  $$$ "(" |-- !!! (list1 type_ident --| $$$ ")") ||
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   202
  Scan.succeed [];
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   203
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   204
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   205
(* mixfix annotations *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   206
11651
201b3f76c7b7 support non-oriented infix;
wenzelm
parents: 9155
diff changeset
   207
val infx = $$$ "infix" |-- !!! (nat >> Syntax.Infix || string -- nat >> Syntax.InfixName);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   208
val infxl = $$$ "infixl" |-- !!! (nat >> Syntax.Infixl || string -- nat >> Syntax.InfixlName);
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   209
val infxr = $$$ "infixr" |-- !!! (nat >> Syntax.Infixr || string -- nat >> Syntax.InfixrName);
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   210
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   211
val binder =
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   212
  $$$ "binder" |--
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   213
    !!! (string -- ($$$ "[" |-- nat --| $$$ "]" -- nat || nat >> (fn n => (n, n))))
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   214
  >> (Syntax.Binder o triple2);
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   215
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   216
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   217
val opt_pris = Scan.optional ($$$ "[" |-- !!! (list nat --| $$$ "]")) [];
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   218
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   219
val mixfix =
8648
7461dc59a818 tuned mixfix syntax;
wenzelm
parents: 8586
diff changeset
   220
  (string -- !!! (opt_pris -- Scan.optional nat Syntax.max_pri))
7461dc59a818 tuned mixfix syntax;
wenzelm
parents: 8586
diff changeset
   221
  >> (Syntax.Mixfix o triple2);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   222
14646
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
   223
fun fix_decl guard fix = $$$ "(" |-- guard (fix --| $$$ ")");
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
   224
fun opt_fix guard fix = Scan.optional (fix_decl guard fix) Syntax.NoSyn;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   225
11651
201b3f76c7b7 support non-oriented infix;
wenzelm
parents: 9155
diff changeset
   226
val opt_infix = opt_fix !!! (infxl || infxr || infx);
201b3f76c7b7 support non-oriented infix;
wenzelm
parents: 9155
diff changeset
   227
val opt_mixfix = opt_fix !!! (mixfix || binder || infxl || infxr || infx);
201b3f76c7b7 support non-oriented infix;
wenzelm
parents: 9155
diff changeset
   228
val opt_infix' = opt_fix I (infxl || infxr || infx);
201b3f76c7b7 support non-oriented infix;
wenzelm
parents: 9155
diff changeset
   229
val opt_mixfix' = opt_fix I (mixfix || binder || infxl || infxr || infx);
14646
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
   230
val mixfix' = fix_decl !!! (mixfix || binder || infxl || infxr || infx);
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
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   233
(* consts *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   234
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   235
val const =
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   236
  name -- ($$$ "::" |-- !!! (typ -- opt_mixfix)) >> triple2;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   237
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   238
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   239
(* terms *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   240
7477
c7caea1ce78c removed text vars;
wenzelm
parents: 7418
diff changeset
   241
val trm = short_ident || long_ident || sym_ident || term_var || number || string;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   242
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   243
val term = group "term" trm;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   244
val prop = group "proposition" trm;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   245
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   246
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
   247
(* patterns *)
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   248
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
   249
val is_terms = Scan.repeat1 ($$$ "is" |-- term);
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   250
val is_props = Scan.repeat1 ($$$ "is" |-- prop);
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   251
val concl_props = $$$ "concl" |-- !!! is_props;
7418
87c12d352bab any_props: improved error;
wenzelm
parents: 7352
diff changeset
   252
val any_props = concl_props >> pair [] || is_props -- Scan.optional concl_props [];
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   253
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   254
val propp = prop -- Scan.optional ($$$ "(" |-- !!! (any_props --| $$$ ")")) ([], []);
12047
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   255
val propp' = prop -- Scan.optional ($$$ "(" |-- !!! (is_props --| $$$ ")")) [];
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
   256
val termp = term -- Scan.optional ($$$ "(" |-- !!! (is_terms --| $$$ ")")) [];
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   257
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   258
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   259
(* arguments *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   260
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   261
fun keyword_symid is_symid = Scan.one (T.keyword_with is_symid) >> T.val_of;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   262
val keyword_sid = keyword_symid T.is_sid;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   263
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   264
fun atom_arg is_symid blk =
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   265
  group "argument"
7477
c7caea1ce78c removed text vars;
wenzelm
parents: 7418
diff changeset
   266
    (position (short_ident || long_ident || sym_ident || term_var ||
5877
ee214dec5657 removed args, args1, thm_xname;
wenzelm
parents: 5826
diff changeset
   267
        type_ident || type_var || number) >> Args.ident ||
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   268
      position (keyword_symid is_symid) >> Args.keyword ||
8350
75aaee32893d argument: include verbatim;
wenzelm
parents: 8237
diff changeset
   269
      position (string || verbatim) >> Args.string ||
5877
ee214dec5657 removed args, args1, thm_xname;
wenzelm
parents: 5826
diff changeset
   270
      position (if blk then $$$ "," else Scan.fail) >> Args.keyword);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   271
5877
ee214dec5657 removed args, args1, thm_xname;
wenzelm
parents: 5826
diff changeset
   272
fun paren_args l r scan = position ($$$ l) -- !!! (scan true -- position ($$$ r))
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   273
  >> (fn (x, (ys, z)) => Args.keyword x :: ys @ [Args.keyword z]);
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   274
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   275
fun args is_symid blk x = Scan.optional (args1 is_symid blk) [] x
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   276
and args1 is_symid blk x =
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   277
  ((Scan.repeat1
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   278
    (Scan.repeat1 (atom_arg is_symid blk) ||
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   279
      paren_args "(" ")" (args is_symid) ||
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   280
      paren_args "[" "]" (args is_symid))) >> flat) x;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   281
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   282
val arguments = args T.is_sid false;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   283
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   284
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   285
(* theorem specifications *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   286
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   287
val attrib = position ((keyword_sid || xname) -- !!! arguments) >> Args.src;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   288
val attribs = $$$ "[" |-- !!! (list attrib --| $$$ "]");
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   289
val opt_attribs = Scan.optional attribs [];
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   290
6398
e6f0c192ef88 fixed thm_name again;
wenzelm
parents: 6372
diff changeset
   291
fun thm_name s = name -- opt_attribs --| $$$ s;
6511
11b07125422e opt_thm_name: name optional;
wenzelm
parents: 6430
diff changeset
   292
fun opt_thm_name s =
11b07125422e opt_thm_name: name optional;
wenzelm
parents: 6430
diff changeset
   293
  Scan.optional ((name -- opt_attribs || (attribs >> pair "")) --| $$$ s) ("", []);;
5917
dcb669fda86b generalized (opt_)thm_name;
wenzelm
parents: 5877
diff changeset
   294
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   295
val spec_name = thm_name ":" -- prop >> (fn ((x, y), z) => ((x, z), y));
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   296
val spec_opt_name = opt_thm_name ":" -- prop >> (fn ((x, y), z) => ((x, z), y));
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   297
5917
dcb669fda86b generalized (opt_)thm_name;
wenzelm
parents: 5877
diff changeset
   298
val xthm = xname -- opt_attribs;
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   299
val xthms1 = Scan.repeat1 xthm;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   300
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   301
12047
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   302
(* locale elements *)
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   303
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   304
local
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   305
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   306
val loc_mixfix = $$$ "(" -- $$$ "structure" -- !!! ($$$ ")") >> K None || opt_mixfix >> Some;
12955
f4d60f358cb6 renamed "uses" to "includes";
wenzelm
parents: 12942
diff changeset
   307
val loc_keyword = $$$ "fixes" || $$$ "assumes" || $$$ "defines" || $$$ "notes" || $$$ "includes";
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   308
15127
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   309
val loc_element =
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   310
  $$$ "fixes" |-- !!! (and_list1 (name -- Scan.option ($$$ "::" |-- typ) -- loc_mixfix
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   311
    >> triple1)) >> Locale.Fixes ||
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   312
  $$$ "assumes" |-- !!! (and_list1 (opt_thm_name ":" -- Scan.repeat1 propp))
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   313
    >> Locale.Assumes ||
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   314
  $$$ "defines" |-- !!! (and_list1 (opt_thm_name ":" -- propp'))
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   315
    >> Locale.Defines ||
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   316
  $$$ "notes" |-- !!! (and_list1 (opt_thm_name "=" -- xthms1))
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   317
    >> Locale.Notes;
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   318
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   319
fun plus1 scan =
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   320
  scan -- Scan.repeat ($$$ "+" |-- Scan.unless loc_keyword (!!! scan)) >> op ::;
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   321
12268
28e60c998eee added uname;
wenzelm
parents: 12263
diff changeset
   322
fun expr2 x = (xname >> Locale.Locale || $$$ "(" |-- !!! (expr0 --| $$$ ")")) x
28e60c998eee added uname;
wenzelm
parents: 12263
diff changeset
   323
and expr1 x = (expr2 -- Scan.repeat1 uname >> Locale.Rename || expr2) x
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   324
and expr0 x = (plus1 expr1 >> (fn [e] => e | es => Locale.Merge es)) x;
12268
28e60c998eee added uname;
wenzelm
parents: 12263
diff changeset
   325
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   326
in
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   327
12942
48fbe245879e export locale_target, locale_keyword;
wenzelm
parents: 12876
diff changeset
   328
val locale_target = Scan.option (($$$ "(" -- $$$ "in") |-- !!! (xname --| $$$ ")"));
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   329
val locale_expr = expr0;
12942
48fbe245879e export locale_target, locale_keyword;
wenzelm
parents: 12876
diff changeset
   330
val locale_keyword = loc_keyword;
12047
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   331
15127
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   332
val locale_element = group "locale element" loc_element;
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   333
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   334
val locale_elem_or_expr = group "locale element or includes"
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   335
  (loc_element >> Locale.Elem ||
12955
f4d60f358cb6 renamed "uses" to "includes";
wenzelm
parents: 12942
diff changeset
   336
  $$$ "includes" |-- !!! locale_expr >> Locale.Expr);
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   337
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   338
end;
12047
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   339
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   340
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   341
(* proof methods *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   342
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   343
fun is_symid_meth s =
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   344
  s <> "|" andalso s <> "?" andalso s <> "+" andalso T.is_sid s;
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   345
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   346
fun meth4 x =
5877
ee214dec5657 removed args, args1, thm_xname;
wenzelm
parents: 5826
diff changeset
   347
 (position (xname >> rpair []) >> (Method.Source o Args.src) ||
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   348
  $$$ "(" |-- !!! (meth0 --| $$$ ")")) x
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   349
and meth3 x =
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   350
 (meth4 --| $$$ "?" >> Method.Try ||
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   351
  meth4 --| $$$ "+" >> Method.Repeat1 ||
5940
33bdc03bba7e fixed method syntax;
wenzelm
parents: 5917
diff changeset
   352
  meth4) x
33bdc03bba7e fixed method syntax;
wenzelm
parents: 5917
diff changeset
   353
and meth2 x =
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   354
 (position (xname -- args1 is_symid_meth false) >> (Method.Source o Args.src) ||
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   355
  meth3) x
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   356
and meth1 x = (enum1 "," meth2 >> (fn [m] => m | ms => Method.Then ms)) x
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   357
and meth0 x = (enum1 "|" meth1 >> (fn [m] => m | ms => Method.Orelse ms)) x;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   358
6558
120ff48e8618 method = meth3 (again);
wenzelm
parents: 6553
diff changeset
   359
val method = meth3;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   360
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   361
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   362
end;