src/Pure/Isar/outer_parse.ML
author wenzelm
Sat, 21 Jan 2006 23:02:14 +0100
changeset 18728 6790126ab5f6
parent 18669 cd6d6baf0411
child 18898 e3d2aa8ba0e1
permissions -rw-r--r--
simplified type attribute;
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
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    17
  val not_eof: token list -> token * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    18
  val position: (token list -> 'a * 'b) -> token list -> ('a * Position.T) * 'b
7026
69724548fad1 separate command tokens;
wenzelm
parents: 6983
diff changeset
    19
  val command: token list -> string * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    20
  val keyword: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    21
  val short_ident: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    22
  val long_ident: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    23
  val sym_ident: token list -> string * token list
15963
5b70f789e079 export parser for "-"
kleing
parents: 15714
diff changeset
    24
  val minus: token list -> string * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    25
  val term_var: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    26
  val type_ident: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    27
  val type_var: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    28
  val number: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    29
  val string: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    30
  val verbatim: token list -> string * token list
6860
8dc6a1e6fa13 added sync;
wenzelm
parents: 6726
diff changeset
    31
  val sync: token list -> string * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    32
  val eof: token list -> string * token list
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    33
  val $$$ : string -> token list -> string * token list
16030
bbfb2f1378b3 added reserved;
wenzelm
parents: 15979
diff changeset
    34
  val reserved : string -> token list -> string * token list
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    35
  val semicolon: token list -> string * token list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    36
  val underscore: token list -> string * token list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    37
  val maybe: (token list -> 'a * token list) -> token list -> 'a option * token list
17070
3b29a01417f8 added tags parser;
wenzelm
parents: 16736
diff changeset
    38
  val tag_name: token list -> string * token list
3b29a01417f8 added tags parser;
wenzelm
parents: 16736
diff changeset
    39
  val tags: token list -> string list * token list
7930
220892918bd1 added opt_unit (from isar_syn.ML);
wenzelm
parents: 7477
diff changeset
    40
  val opt_unit: token list -> unit * token list
14646
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
    41
  val opt_keyword: string -> token list -> bool * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    42
  val nat: token list -> int * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    43
  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
    44
  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
    45
  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
    46
  val list1: (token list -> 'a * token list) -> token list -> 'a list * token list
6013
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
    47
  val and_list: (token list -> 'a * token list) -> token list -> 'a list * token list
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
    48
  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
    49
  val name: token list -> bstring * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    50
  val xname: token list -> xstring * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    51
  val text: token list -> string * token list
14949
5f5605361aad added path;
wenzelm
parents: 14835
diff changeset
    52
  val path: token list -> Path.T * token list
8897
fb1436ca3b2e adapted to inner syntax of sorts;
wenzelm
parents: 8807
diff changeset
    53
  val sort: token list -> string * token list
fb1436ca3b2e adapted to inner syntax of sorts;
wenzelm
parents: 8807
diff changeset
    54
  val arity: token list -> (string list * string) * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    55
  val type_args: token list -> string list * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    56
  val typ: token list -> string * token list
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
    57
  val mixfix: token list -> mixfix * token list
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
    58
  val opt_infix: token list -> mixfix * token list
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
    59
  val opt_mixfix: token list -> mixfix * token list
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
    60
  val opt_infix': token list -> mixfix * token list
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
    61
  val opt_mixfix': token list -> mixfix * token list
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
    62
  val const: token list -> (string * string * mixfix) * token list
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
    63
  val fixes: token list -> (string * string option * mixfix) list * token list
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
    64
  val simple_fixes: token list -> (string * string option) list * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    65
  val term: token list -> string * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    66
  val prop: token list -> string * token list
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
    67
  val propp: token list -> (string * (string list * string list)) * token list
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
    68
  val termp: token list -> (string * string list) * token list
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
    69
  val arguments: token list -> Args.T list * token list
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    70
  val attribs: token list -> Attrib.src list * token list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    71
  val opt_attribs: token list -> Attrib.src list * token list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    72
  val thm_name: string -> token list -> (bstring * Attrib.src list) * token list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    73
  val opt_thm_name: string -> token list -> (bstring * Attrib.src list) * token list
18618
387d170e4aa9 added param, spec, named_spec;
wenzelm
parents: 18136
diff changeset
    74
  val spec: token list -> ((bstring * Attrib.src list) * string list) * token list
387d170e4aa9 added param, spec, named_spec;
wenzelm
parents: 18136
diff changeset
    75
  val named_spec: token list -> ((bstring * Attrib.src list) * string list) * token list
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    76
  val spec_name: token list -> ((bstring * string) * Attrib.src list) * token list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    77
  val spec_opt_name: token list -> ((bstring * string) * Attrib.src list) * token list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    78
  val xthm: token list -> (thmref * Attrib.src list) * token list
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
    79
  val xthms1: token list -> (thmref * Attrib.src list) list * token list
17358
5746c9bd4356 added name_facts;
wenzelm
parents: 17165
diff changeset
    80
  val name_facts: token list ->
5746c9bd4356 added name_facts;
wenzelm
parents: 17165
diff changeset
    81
    ((bstring * Attrib.src list) * (thmref * Attrib.src list) list) list * token list
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
    82
  val locale_mixfix: token list -> mixfix * token list
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
    83
  val locale_fixes: token list -> (string * string option * mixfix) list * token list
16736
1e792b32abef Preparations for interpretation of locales in locales.
ballarin
parents: 16498
diff changeset
    84
  val locale_target: token list -> xstring * token list
1e792b32abef Preparations for interpretation of locales in locales.
ballarin
parents: 16498
diff changeset
    85
  val opt_locale_target: token list -> xstring option * token list
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
    86
  val locale_expr: token list -> Locale.expr * token list
12942
48fbe245879e export locale_target, locale_keyword;
wenzelm
parents: 12876
diff changeset
    87
  val locale_keyword: token list -> string * token list
18136
51385f358b53 P.context_element, P.locale_element;
wenzelm
parents: 18037
diff changeset
    88
  val locale_element: token list -> Element.context Locale.element * token list
51385f358b53 P.context_element, P.locale_element;
wenzelm
parents: 18037
diff changeset
    89
  val context_element: token list -> Element.context * token list
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    90
  val method: token list -> Method.text * token list
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    91
end;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    92
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    93
structure OuterParse: OUTER_PARSE =
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    94
struct
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    95
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
    96
structure T = OuterLex;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
    97
type token = T.token;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    98
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
    99
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   100
(** error handling **)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   101
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   102
(* group atomic parsers (no cuts!) *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   103
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   104
fun fail_with s = Scan.fail_with
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   105
  (fn [] => s ^ " expected (past end-of-file!)"
9155
adfa40218e06 OuterLex.name_of: include val;
wenzelm
parents: 9131
diff changeset
   106
    | (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
   107
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   108
fun group s scan = scan || fail_with s;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   109
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   110
5877
ee214dec5657 removed args, args1, thm_xname;
wenzelm
parents: 5826
diff changeset
   111
(* cut *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   112
8581
5c7ed2af8bfb !!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents: 8350
diff changeset
   113
fun cut kind scan =
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   114
  let
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   115
    fun get_pos [] = " (past end-of-file!)"
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   116
      | get_pos (tok :: _) = T.pos_of tok;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   117
15531
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   118
    fun err (toks, NONE) = kind ^ get_pos toks
08c8dad8e399 Deleted Library.option type.
skalberg
parents: 15456
diff changeset
   119
      | err (toks, SOME msg) = kind ^ get_pos toks ^ ": " ^ msg;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   120
  in Scan.!! err scan end;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   121
8586
e451c4865548 made SML/NJ happy;
wenzelm
parents: 8581
diff changeset
   122
fun !!! scan = cut "Outer syntax error" scan;
e451c4865548 made SML/NJ happy;
wenzelm
parents: 8581
diff changeset
   123
fun !!!! scan = cut "Corrupted outer syntax in presentation" scan;
8581
5c7ed2af8bfb !!!! = cut "Corrupted outer syntax in presentation";
wenzelm
parents: 8350
diff changeset
   124
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   125
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   126
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   127
(** basic parsers **)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   128
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   129
(* utils *)
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
fun triple1 ((x, y), z) = (x, y, z);
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   132
fun triple2 (x, (y, z)) = (x, y, z);
6430
69400c97d3bf triple_swap;
wenzelm
parents: 6398
diff changeset
   133
fun triple_swap ((x, y), z) = ((x, z), y);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   134
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   135
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   136
(* tokens *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   137
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   138
val not_eof = Scan.one T.not_eof;
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   139
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   140
fun position scan = (Scan.ahead not_eof >> T.position_of) -- scan >> Library.swap;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   141
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   142
fun kind k =
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   143
  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
   144
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   145
val command = kind T.Command;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   146
val keyword = kind T.Keyword;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   147
val short_ident = kind T.Ident;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   148
val long_ident = kind T.LongIdent;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   149
val sym_ident = kind T.SymIdent;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   150
val term_var = kind T.Var;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   151
val type_ident = kind T.TypeIdent;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   152
val type_var = kind T.TypeVar;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   153
val number = kind T.Nat;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   154
val string = kind T.String;
17165
9b498019723f added alt_string;
wenzelm
parents: 17070
diff changeset
   155
val alt_string = kind T.AltString;
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   156
val verbatim = kind T.Verbatim;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   157
val sync = kind T.Sync;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   158
val eof = kind T.EOF;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   159
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   160
fun $$$ x =
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   161
  group (T.str_of_kind T.Keyword ^ " " ^ quote x)
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   162
    (Scan.one (T.keyword_with (equal x)) >> T.val_of);
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   163
16030
bbfb2f1378b3 added reserved;
wenzelm
parents: 15979
diff changeset
   164
fun reserved x =
bbfb2f1378b3 added reserved;
wenzelm
parents: 15979
diff changeset
   165
  group ("Reserved identifier " ^ quote x)
bbfb2f1378b3 added reserved;
wenzelm
parents: 15979
diff changeset
   166
    (Scan.one (T.ident_with (equal x)) >> T.val_of);
bbfb2f1378b3 added reserved;
wenzelm
parents: 15979
diff changeset
   167
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   168
val semicolon = $$$ ";";
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   169
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   170
val minus = sym_ident :-- (fn "-" => Scan.succeed () | _ => Scan.fail) >> #1;
11792
311eee3d63b6 parser for underscore (actually a symbolic identifier!);
wenzelm
parents: 11651
diff changeset
   171
val underscore = sym_ident :-- (fn "_" => Scan.succeed () | _ => Scan.fail) >> #1;
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   172
fun maybe scan = underscore >> K NONE || scan >> SOME;
11792
311eee3d63b6 parser for underscore (actually a symbolic identifier!);
wenzelm
parents: 11651
diff changeset
   173
14835
695ee8ad0bb6 Library.read_int; Output.output;
wenzelm
parents: 14646
diff changeset
   174
val nat = number >> (#1 o Library.read_int o Symbol.explode);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   175
17070
3b29a01417f8 added tags parser;
wenzelm
parents: 16736
diff changeset
   176
val tag_name = group "tag name" (short_ident || string);
3b29a01417f8 added tags parser;
wenzelm
parents: 16736
diff changeset
   177
val tags = Scan.repeat ($$$ "%" |-- !!! tag_name);
3b29a01417f8 added tags parser;
wenzelm
parents: 16736
diff changeset
   178
7930
220892918bd1 added opt_unit (from isar_syn.ML);
wenzelm
parents: 7477
diff changeset
   179
val opt_unit = Scan.optional ($$$ "(" -- $$$ ")" >> (K ())) ();
14646
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
   180
fun opt_keyword s = Scan.optional ($$$ "(" |-- !!! (($$$ s >> K true) --| $$$ ")")) false;
f5f2340398f9 added opt_keyword, mixfix';
wenzelm
parents: 14605
diff changeset
   181
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   182
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   183
(* enumerations *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   184
6003
b382568901f6 enum: !!! after seperator;
wenzelm
parents: 5960
diff changeset
   185
fun enum1 sep scan = scan -- Scan.repeat ($$$ sep |-- !!! scan) >> op ::;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   186
fun enum sep scan = enum1 sep scan || Scan.succeed [];
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   187
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   188
fun list1 scan = enum1 "," scan;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   189
fun list scan = enum "," scan;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   190
6013
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
   191
fun and_list1 scan = enum1 "and" scan;
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
   192
fun and_list scan = enum "and" scan;
6da9ae6d40f5 and_list;
wenzelm
parents: 6003
diff changeset
   193
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   194
5960
2bebd0d0a961 comment parser;
wenzelm
parents: 5940
diff changeset
   195
(* names and text *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   196
8146
3243f2261d4b 'name' etc. include 'number';
wenzelm
parents: 8077
diff changeset
   197
val name = group "name declaration" (short_ident || sym_ident || string || number);
3243f2261d4b 'name' etc. include 'number';
wenzelm
parents: 8077
diff changeset
   198
val xname = group "name reference" (short_ident || long_ident || sym_ident || string || number);
3243f2261d4b 'name' etc. include 'number';
wenzelm
parents: 8077
diff changeset
   199
val text = group "text" (short_ident || long_ident || sym_ident || string || number || verbatim);
14949
5f5605361aad added path;
wenzelm
parents: 14835
diff changeset
   200
val path = group "file name/path specification" name >> Path.unpack;
6553
dc962d157a63 comment, interest;
wenzelm
parents: 6511
diff changeset
   201
dc962d157a63 comment, interest;
wenzelm
parents: 6511
diff changeset
   202
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   203
(* sorts and arities *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   204
8897
fb1436ca3b2e adapted to inner syntax of sorts;
wenzelm
parents: 8807
diff changeset
   205
val sort = group "sort" xname;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   206
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   207
fun gen_arity cod =
7352
d98001b492b3 fixed arity;
wenzelm
parents: 7171
diff changeset
   208
  Scan.optional ($$$ "(" |-- !!! (list1 sort --| $$$ ")")) [] -- cod;
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   209
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   210
val arity = gen_arity sort;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   211
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   212
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   213
(* types *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   214
8146
3243f2261d4b 'name' etc. include 'number';
wenzelm
parents: 8077
diff changeset
   215
val typ = group "type"
3243f2261d4b 'name' etc. include 'number';
wenzelm
parents: 8077
diff changeset
   216
  (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
   217
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   218
val type_args =
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   219
  type_ident >> single ||
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   220
  $$$ "(" |-- !!! (list1 type_ident --| $$$ ")") ||
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   221
  Scan.succeed [];
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   222
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   223
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   224
(* mixfix annotations *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   225
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   226
val mfix = string --
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   227
  !!! (Scan.optional ($$$ "[" |-- !!! (list nat --| $$$ "]")) [] --
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   228
    Scan.optional nat Syntax.max_pri) >> (Mixfix o triple2);
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   229
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   230
val infx = $$$ "infix" |-- !!! (nat >> Infix || string -- nat >> InfixName);
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   231
val infxl = $$$ "infixl" |-- !!! (nat >> Infixl || string -- nat >> InfixlName);
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   232
val infxr = $$$ "infixr" |-- !!! (nat >> Infixr || string -- nat >> InfixrName);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   233
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   234
val binder = $$$ "binder" |--
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   235
  !!! (string -- ($$$ "[" |-- nat --| $$$ "]" -- nat || nat >> (fn n => (n, n))))
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   236
  >> (Binder o triple2);
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   237
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   238
fun annotation guard fix = $$$ "(" |-- guard (fix --| $$$ ")");
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   239
fun opt_annotation guard fix = Scan.optional (annotation guard fix) NoSyn;
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   240
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   241
val mixfix = annotation !!! (mfix || binder || infxl || infxr || infx);
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   242
val opt_infix = opt_annotation !!! (infxl || infxr || infx);
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   243
val opt_mixfix = opt_annotation !!! (mfix || binder || infxl || infxr || infx);
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   244
val opt_infix' = opt_annotation I (infxl || infxr || infx);
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   245
val opt_mixfix' = opt_annotation I (mfix || binder || infxl || infxr || infx);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   246
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   247
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   248
(* fixes *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   249
18618
387d170e4aa9 added param, spec, named_spec;
wenzelm
parents: 18136
diff changeset
   250
val const = name -- ($$$ "::" |-- !!! typ) -- opt_mixfix >> triple1;
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   251
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   252
val params = Scan.repeat1 name -- Scan.option ($$$ "::" |-- !!! typ)
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   253
  >> (fn (xs, T) => map (rpair T) xs);
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   254
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   255
val simple_fixes = and_list1 params >> List.concat;
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   256
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   257
val fixes =
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   258
  and_list1 (name -- Scan.option ($$$ "::" |-- typ) -- mixfix >> (single o triple1) ||
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   259
    params >> map Syntax.no_syn) >> List.concat;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   260
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   261
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   262
(* terms *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   263
7477
c7caea1ce78c removed text vars;
wenzelm
parents: 7418
diff changeset
   264
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
   265
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   266
val term = group "term" trm;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   267
val prop = group "proposition" trm;
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   268
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   269
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
   270
(* patterns *)
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   271
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
   272
val is_terms = Scan.repeat1 ($$$ "is" |-- term);
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   273
val is_props = Scan.repeat1 ($$$ "is" |-- prop);
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   274
val concl_props = $$$ "concl" |-- !!! is_props;
7418
87c12d352bab any_props: improved error;
wenzelm
parents: 7352
diff changeset
   275
val any_props = concl_props >> pair [] || is_props -- Scan.optional concl_props [];
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   276
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   277
val propp = prop -- Scan.optional ($$$ "(" |-- !!! (any_props --| $$$ ")")) ([], []);
12047
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   278
val propp' = prop -- Scan.optional ($$$ "(" |-- !!! (is_props --| $$$ ")")) [];
6949
a0b34115077f added termp;
wenzelm
parents: 6935
diff changeset
   279
val termp = term -- Scan.optional ($$$ "(" |-- !!! (is_terms --| $$$ ")")) [];
6935
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   280
a3f3f4128cab propp: 'concl' patterns;
wenzelm
parents: 6860
diff changeset
   281
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   282
(* arguments *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   283
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   284
fun keyword_symid is_symid = Scan.one (T.keyword_with is_symid) >> T.val_of;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   285
val keyword_sid = keyword_symid T.is_sid;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   286
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   287
fun atom_arg is_symid blk =
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   288
  group "argument"
7477
c7caea1ce78c removed text vars;
wenzelm
parents: 7418
diff changeset
   289
    (position (short_ident || long_ident || sym_ident || term_var ||
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   290
        type_ident || type_var || number) >> Args.mk_ident ||
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   291
      position (keyword_symid is_symid) >> Args.mk_keyword ||
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   292
      position (string || verbatim) >> Args.mk_string ||
18037
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17756
diff changeset
   293
      position alt_string >> Args.mk_alt_string ||
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   294
      position (if blk then $$$ "," else Scan.fail) >> Args.mk_keyword);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   295
5877
ee214dec5657 removed args, args1, thm_xname;
wenzelm
parents: 5826
diff changeset
   296
fun paren_args l r scan = position ($$$ l) -- !!! (scan true -- position ($$$ r))
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   297
  >> (fn (x, (ys, z)) => Args.mk_keyword x :: ys @ [Args.mk_keyword z]);
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   298
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   299
fun args is_symid blk x = Scan.optional (args1 is_symid blk) [] x
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   300
and args1 is_symid blk x =
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   301
  ((Scan.repeat1
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   302
    (Scan.repeat1 (atom_arg is_symid blk) ||
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   303
      paren_args "(" ")" (args is_symid) ||
15570
8d8c70b41bab Move towards standard functions.
skalberg
parents: 15531
diff changeset
   304
      paren_args "[" "]" (args is_symid))) >> List.concat) x;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   305
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   306
val arguments = args T.is_sid false;
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   307
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   308
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   309
(* theorem specifications *)
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   310
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   311
val attrib = position ((keyword_sid || xname) -- !!! arguments) >> Args.src;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   312
val attribs = $$$ "[" |-- !!! (list attrib --| $$$ "]");
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   313
val opt_attribs = Scan.optional attribs [];
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   314
6398
e6f0c192ef88 fixed thm_name again;
wenzelm
parents: 6372
diff changeset
   315
fun thm_name s = name -- opt_attribs --| $$$ s;
6511
11b07125422e opt_thm_name: name optional;
wenzelm
parents: 6430
diff changeset
   316
fun opt_thm_name s =
17756
d4a35f82fbb4 minor tweaks for Poplog/ML;
wenzelm
parents: 17358
diff changeset
   317
  Scan.optional ((name -- opt_attribs || (attribs >> pair "")) --| $$$ s) ("", []);
5917
dcb669fda86b generalized (opt_)thm_name;
wenzelm
parents: 5877
diff changeset
   318
18618
387d170e4aa9 added param, spec, named_spec;
wenzelm
parents: 18136
diff changeset
   319
val spec = opt_thm_name ":" -- Scan.repeat1 prop;
387d170e4aa9 added param, spec, named_spec;
wenzelm
parents: 18136
diff changeset
   320
val named_spec = thm_name ":" -- Scan.repeat1 prop;
387d170e4aa9 added param, spec, named_spec;
wenzelm
parents: 18136
diff changeset
   321
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   322
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
   323
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
   324
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15206
diff changeset
   325
val thm_sel = $$$ "(" |-- list1
15703
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   326
 (nat --| minus -- nat >> PureThy.FromTo ||
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   327
  nat --| minus >> PureThy.From ||
727ef1b8b3ee *** empty log message ***
wenzelm
parents: 15570
diff changeset
   328
  nat >> PureThy.Single) --| $$$ ")";
15456
956d6acacf89 Specific theorems in a named list of theorems can now be referred to
berghofe
parents: 15206
diff changeset
   329
18037
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17756
diff changeset
   330
val xthm = (alt_string >> Fact || xname -- thm_sel >> NameSelection || xname >> Name)
1095d2213b9d syntax for literal facts;
wenzelm
parents: 17756
diff changeset
   331
  -- opt_attribs;
6372
44b104595441 added simple_arity, spec_name, spec_opt_name;
wenzelm
parents: 6355
diff changeset
   332
val xthms1 = Scan.repeat1 xthm;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   333
17358
5746c9bd4356 added name_facts;
wenzelm
parents: 17165
diff changeset
   334
val name_facts = and_list1 (opt_thm_name "=" -- xthms1);
5746c9bd4356 added name_facts;
wenzelm
parents: 17165
diff changeset
   335
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   336
18136
51385f358b53 P.context_element, P.locale_element;
wenzelm
parents: 18037
diff changeset
   337
(* locale and context elements *)
12047
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   338
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   339
val locale_mixfix = $$$ "(" -- $$$ "structure" -- !!! ($$$ ")") >> K Structure || mixfix;
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   340
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   341
val locale_fixes =
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   342
  and_list1 (name -- Scan.option ($$$ "::" |-- typ) -- locale_mixfix >> (single o triple1) ||
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   343
    params >> map Syntax.no_syn) >> List.concat;
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   344
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   345
local
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   346
16169
b59202511b8a Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
   347
val loc_keyword = $$$ "fixes" || $$$ "constrains" || $$$ "assumes" ||
b59202511b8a Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
   348
   $$$ "defines" || $$$ "notes" || $$$ "includes";
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   349
15127
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   350
val loc_element =
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   351
  $$$ "fixes" |-- !!! locale_fixes >> Element.Fixes ||
16169
b59202511b8a Locales: new element constrains, parameter renaming with syntax,
ballarin
parents: 16102
diff changeset
   352
  $$$ "constrains" |-- !!! (and_list1 (name -- ($$$ "::" |-- typ)))
18136
51385f358b53 P.context_element, P.locale_element;
wenzelm
parents: 18037
diff changeset
   353
    >> Element.Constrains ||
15127
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   354
  $$$ "assumes" |-- !!! (and_list1 (opt_thm_name ":" -- Scan.repeat1 propp))
18136
51385f358b53 P.context_element, P.locale_element;
wenzelm
parents: 18037
diff changeset
   355
    >> Element.Assumes ||
15127
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   356
  $$$ "defines" |-- !!! (and_list1 (opt_thm_name ":" -- propp'))
18136
51385f358b53 P.context_element, P.locale_element;
wenzelm
parents: 18037
diff changeset
   357
    >> Element.Defines ||
15127
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   358
  $$$ "notes" |-- !!! (and_list1 (opt_thm_name "=" -- xthms1))
18136
51385f358b53 P.context_element, P.locale_element;
wenzelm
parents: 18037
diff changeset
   359
    >> Element.Notes;
15127
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   360
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   361
fun plus1 scan =
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   362
  scan -- Scan.repeat ($$$ "+" |-- Scan.unless loc_keyword (!!! scan)) >> op ::;
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   363
18669
cd6d6baf0411 uniform handling of fixes;
wenzelm
parents: 18618
diff changeset
   364
val rename = name -- Scan.option mixfix;
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 16030
diff changeset
   365
12268
28e60c998eee added uname;
wenzelm
parents: 12263
diff changeset
   366
fun expr2 x = (xname >> Locale.Locale || $$$ "(" |-- !!! (expr0 --| $$$ ")")) x
16102
c5f6726d9bb1 Locale expressions: rename with optional mixfix syntax.
ballarin
parents: 16030
diff changeset
   367
and expr1 x = (expr2 -- Scan.repeat1 (maybe rename) >> Locale.Rename || expr2) x
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   368
and expr0 x = (plus1 expr1 >> (fn [e] => e | es => Locale.Merge es)) x;
12268
28e60c998eee added uname;
wenzelm
parents: 12263
diff changeset
   369
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   370
in
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   371
16736
1e792b32abef Preparations for interpretation of locales in locales.
ballarin
parents: 16498
diff changeset
   372
val locale_target = ($$$ "(" -- $$$ "in") |-- !!! (xname --| $$$ ")");
1e792b32abef Preparations for interpretation of locales in locales.
ballarin
parents: 16498
diff changeset
   373
val opt_locale_target = Scan.option locale_target;
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   374
val locale_expr = expr0;
12942
48fbe245879e export locale_target, locale_keyword;
wenzelm
parents: 12876
diff changeset
   375
val locale_keyword = loc_keyword;
12047
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   376
18136
51385f358b53 P.context_element, P.locale_element;
wenzelm
parents: 18037
diff changeset
   377
val locale_element = group "locale element"
51385f358b53 P.context_element, P.locale_element;
wenzelm
parents: 18037
diff changeset
   378
  (loc_element >> Locale.Elem || $$$ "includes" |-- !!! locale_expr >> Locale.Expr);
15127
2550a5578d39 Disallowed "includes" in locale declarations.
ballarin
parents: 14981
diff changeset
   379
18136
51385f358b53 P.context_element, P.locale_element;
wenzelm
parents: 18037
diff changeset
   380
val context_element = group "context element" loc_element;
12272
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   381
9bc50336dab6 improved locale expression syntax;
wenzelm
parents: 12268
diff changeset
   382
end;
12047
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   383
e151e66da2d6 added locale_element;
wenzelm
parents: 11792
diff changeset
   384
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   385
(* proof methods *)
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   386
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   387
fun is_symid_meth s =
9131
cd17637c917f added semicolon;
wenzelm
parents: 9037
diff changeset
   388
  s <> "|" andalso s <> "?" andalso s <> "+" andalso T.is_sid s;
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   389
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   390
fun meth4 x =
5877
ee214dec5657 removed args, args1, thm_xname;
wenzelm
parents: 5826
diff changeset
   391
 (position (xname >> rpair []) >> (Method.Source o Args.src) ||
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   392
  $$$ "(" |-- !!! (meth0 --| $$$ ")")) x
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   393
and meth3 x =
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   394
 (meth4 --| $$$ "?" >> Method.Try ||
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   395
  meth4 --| $$$ "+" >> Method.Repeat1 ||
5940
33bdc03bba7e fixed method syntax;
wenzelm
parents: 5917
diff changeset
   396
  meth4) x
33bdc03bba7e fixed method syntax;
wenzelm
parents: 5917
diff changeset
   397
and meth2 x =
6983
7f28cd9cfe72 term/prop: include number;
wenzelm
parents: 6949
diff changeset
   398
 (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
   399
  meth3) x
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   400
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
   401
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
   402
6558
120ff48e8618 method = meth3 (again);
wenzelm
parents: 6553
diff changeset
   403
val method = meth3;
5826
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   404
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   405
977f789566b7 Generic parsers for Isabelle/Isar outer syntax.
wenzelm
parents:
diff changeset
   406
end;