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