| author | blanchet | 
| Tue, 26 Oct 2010 16:59:19 +0200 | |
| changeset 40201 | 0dcd03b05da4 | 
| parent 36959 | f5417836dbea | 
| child 40290 | 47f572aff50a | 
| permissions | -rw-r--r-- | 
| 36949 
080e85d46108
renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
 wenzelm parents: 
35838diff
changeset | 1 | (* Title: Pure/Isar/parse.ML | 
| 5826 | 2 | Author: Markus Wenzel, TU Muenchen | 
| 3 | ||
| 4 | Generic parsers for Isabelle/Isar outer syntax. | |
| 5 | *) | |
| 6 | ||
| 36949 
080e85d46108
renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
 wenzelm parents: 
35838diff
changeset | 7 | signature PARSE = | 
| 5826 | 8 | sig | 
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 9 | type 'a parser = Token.T list -> 'a * Token.T list | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 10 | type 'a context_parser = Context.generic * Token.T list -> 'a * (Context.generic * Token.T list) | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 11 | val group: string -> (Token.T list -> 'a) -> Token.T list -> 'a | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 12 | val !!! : (Token.T list -> 'a) -> Token.T list -> 'a | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 13 | val !!!! : (Token.T list -> 'a) -> Token.T list -> 'a | 
| 12047 | 14 |   val triple1: ('a * 'b) * 'c -> 'a * 'b * 'c
 | 
| 15 |   val triple2: 'a * ('b * 'c) -> 'a * 'b * 'c
 | |
| 16 |   val triple_swap: ('a * 'b) * 'c -> ('a * 'c) * 'b
 | |
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 17 | val not_eof: Token.T parser | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 18 |   val position: (Token.T list -> 'a * 'b) -> Token.T list -> ('a * Position.T) * 'b
 | 
| 29310 | 19 | val command: string parser | 
| 20 | val keyword: string parser | |
| 21 | val short_ident: string parser | |
| 22 | val long_ident: string parser | |
| 23 | val sym_ident: string parser | |
| 24 | val minus: string parser | |
| 25 | val term_var: string parser | |
| 26 | val type_ident: string parser | |
| 27 | val type_var: string parser | |
| 28 | val number: string parser | |
| 29 | val string: string parser | |
| 30 | val alt_string: string parser | |
| 31 | val verbatim: string parser | |
| 32 | val sync: string parser | |
| 33 | val eof: string parser | |
| 34 | val keyword_with: (string -> bool) -> string parser | |
| 35 | val keyword_ident_or_symbolic: string parser | |
| 36 | val $$$ : string -> string parser | |
| 37 | val reserved: string -> string parser | |
| 38 | val semicolon: string parser | |
| 39 | val underscore: string parser | |
| 40 | val maybe: 'a parser -> 'a option parser | |
| 41 | val tag_name: string parser | |
| 42 | val tags: string list parser | |
| 43 | val opt_unit: unit parser | |
| 44 | val opt_keyword: string -> bool parser | |
| 45 | val begin: string parser | |
| 46 | val opt_begin: bool parser | |
| 47 | val nat: int parser | |
| 48 | val int: int parser | |
| 49 | val enum: string -> 'a parser -> 'a list parser | |
| 50 | val enum1: string -> 'a parser -> 'a list parser | |
| 51 | val and_list: 'a parser -> 'a list parser | |
| 52 | val and_list1: 'a parser -> 'a list parser | |
| 30511 | 53 | val enum': string -> 'a context_parser -> 'a list context_parser | 
| 54 | val enum1': string -> 'a context_parser -> 'a list context_parser | |
| 55 | val and_list': 'a context_parser -> 'a list context_parser | |
| 56 | val and_list1': 'a context_parser -> 'a list context_parser | |
| 29310 | 57 | val list: 'a parser -> 'a list parser | 
| 58 | val list1: 'a parser -> 'a list parser | |
| 59 | val name: bstring parser | |
| 29581 | 60 | val binding: binding parser | 
| 29310 | 61 | val xname: xstring parser | 
| 62 | val text: string parser | |
| 63 | val path: Path.T parser | |
| 64 | val parname: string parser | |
| 29581 | 65 | val parbinding: binding parser | 
| 29310 | 66 | val sort: string parser | 
| 67 | val arity: (string * string list * string) parser | |
| 68 | val multi_arity: (string list * string list * string) parser | |
| 69 | val type_args: string list parser | |
| 35838 | 70 | val type_args_constrained: (string * string option) list parser | 
| 29310 | 71 | val typ_group: string parser | 
| 72 | val typ: string parser | |
| 73 | val mixfix: mixfix parser | |
| 74 | val mixfix': mixfix parser | |
| 75 | val opt_mixfix: mixfix parser | |
| 76 | val opt_mixfix': mixfix parser | |
| 77 | val where_: string parser | |
| 78 | val const: (string * string * mixfix) parser | |
| 30339 | 79 | val const_binding: (binding * string * mixfix) parser | 
| 29581 | 80 | val params: (binding * string option) list parser | 
| 81 | val simple_fixes: (binding * string option) list parser | |
| 82 | val fixes: (binding * string option * mixfix) list parser | |
| 83 | val for_fixes: (binding * string option * mixfix) list parser | |
| 84 | val for_simple_fixes: (binding * string option) list parser | |
| 30573 | 85 | val ML_source: (Symbol_Pos.text * Position.T) parser | 
| 86 | val doc_source: (Symbol_Pos.text * Position.T) parser | |
| 29310 | 87 | val term_group: string parser | 
| 88 | val prop_group: string parser | |
| 89 | val term: string parser | |
| 90 | val prop: string parser | |
| 91 | val propp: (string * string list) parser | |
| 92 | val termp: (string * string list) parser | |
| 93 | val target: xstring parser | |
| 94 | val opt_target: xstring option parser | |
| 5826 | 95 | end; | 
| 96 | ||
| 36949 
080e85d46108
renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
 wenzelm parents: 
35838diff
changeset | 97 | structure Parse: PARSE = | 
| 5826 | 98 | struct | 
| 99 | ||
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 100 | type 'a parser = Token.T list -> 'a * Token.T list; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 101 | type 'a context_parser = Context.generic * Token.T list -> 'a * (Context.generic * Token.T list); | 
| 29310 | 102 | |
| 5826 | 103 | |
| 104 | (** error handling **) | |
| 105 | ||
| 106 | (* group atomic parsers (no cuts!) *) | |
| 107 | ||
| 108 | fun fail_with s = Scan.fail_with | |
| 109 | (fn [] => s ^ " expected (past end-of-file!)" | |
| 23789 
1993b865c5ac
replaced OuterLex.name_of by more sophisticated OuterLex.text_of;
 wenzelm parents: 
22331diff
changeset | 110 | | (tok :: _) => | 
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 111 | (case Token.text_of tok of | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 112 | (txt, "") => | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 113 | s ^ " expected,\nbut " ^ txt ^ Token.pos_of tok ^ " was found" | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 114 | | (txt1, txt2) => | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 115 | s ^ " expected,\nbut " ^ txt1 ^ Token.pos_of tok ^ " was found:\n" ^ txt2)); | 
| 5826 | 116 | |
| 117 | fun group s scan = scan || fail_with s; | |
| 118 | ||
| 119 | ||
| 5877 | 120 | (* cut *) | 
| 5826 | 121 | |
| 8581 
5c7ed2af8bfb
!!!! = cut "Corrupted outer syntax in presentation";
 wenzelm parents: 
8350diff
changeset | 122 | fun cut kind scan = | 
| 5826 | 123 | let | 
| 124 | fun get_pos [] = " (past end-of-file!)" | |
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 125 | | get_pos (tok :: _) = Token.pos_of tok; | 
| 5826 | 126 | |
| 15531 | 127 | fun err (toks, NONE) = kind ^ get_pos toks | 
| 25625 | 128 | | err (toks, SOME msg) = | 
| 129 | if String.isPrefix kind msg then msg | |
| 130 | else kind ^ get_pos toks ^ ": " ^ msg; | |
| 5826 | 131 | in Scan.!! err scan end; | 
| 132 | ||
| 8586 | 133 | fun !!! scan = cut "Outer syntax error" scan; | 
| 134 | fun !!!! scan = cut "Corrupted outer syntax in presentation" scan; | |
| 8581 
5c7ed2af8bfb
!!!! = cut "Corrupted outer syntax in presentation";
 wenzelm parents: 
8350diff
changeset | 135 | |
| 5826 | 136 | |
| 137 | ||
| 138 | (** basic parsers **) | |
| 139 | ||
| 140 | (* utils *) | |
| 141 | ||
| 142 | fun triple1 ((x, y), z) = (x, y, z); | |
| 143 | fun triple2 (x, (y, z)) = (x, y, z); | |
| 6430 | 144 | fun triple_swap ((x, y), z) = ((x, z), y); | 
| 5826 | 145 | |
| 146 | ||
| 147 | (* tokens *) | |
| 148 | ||
| 27815 | 149 | fun RESET_VALUE atom = (*required for all primitive parsers*) | 
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 150 | Scan.ahead (Scan.one (K true)) -- atom >> (fn (arg, x) => (Token.assign NONE arg; x)); | 
| 27815 | 151 | |
| 152 | ||
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 153 | val not_eof = RESET_VALUE (Scan.one Token.not_eof); | 
| 15703 | 154 | |
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 155 | fun position scan = (Scan.ahead not_eof >> Token.position_of) -- scan >> Library.swap; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 156 | fun source_position atom = Scan.ahead atom |-- not_eof >> Token.source_position_of; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 157 | fun inner_syntax atom = Scan.ahead atom |-- not_eof >> Token.source_of; | 
| 5826 | 158 | |
| 159 | fun kind k = | |
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 160 | group (Token.str_of_kind k) (RESET_VALUE (Scan.one (Token.is_kind k) >> Token.content_of)); | 
| 5826 | 161 | |
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 162 | val command = kind Token.Command; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 163 | val keyword = kind Token.Keyword; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 164 | val short_ident = kind Token.Ident; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 165 | val long_ident = kind Token.LongIdent; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 166 | val sym_ident = kind Token.SymIdent; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 167 | val term_var = kind Token.Var; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 168 | val type_ident = kind Token.TypeIdent; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 169 | val type_var = kind Token.TypeVar; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 170 | val number = kind Token.Nat; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 171 | val string = kind Token.String; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 172 | val alt_string = kind Token.AltString; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 173 | val verbatim = kind Token.Verbatim; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 174 | val sync = kind Token.Sync; | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 175 | val eof = kind Token.EOF; | 
| 5826 | 176 | |
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 177 | fun keyword_with pred = RESET_VALUE (Scan.one (Token.keyword_with pred) >> Token.content_of); | 
| 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 178 | val keyword_ident_or_symbolic = keyword_with Token.ident_or_symbolic; | 
| 27815 | 179 | |
| 5826 | 180 | fun $$$ x = | 
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 181 | group (Token.str_of_kind Token.Keyword ^ " " ^ quote x) (keyword_with (fn y => x = y)); | 
| 9131 | 182 | |
| 16030 | 183 | fun reserved x = | 
| 27753 
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
 wenzelm parents: 
27737diff
changeset | 184 |   group ("reserved identifier " ^ quote x)
 | 
| 36959 
f5417836dbea
renamed structure OuterLex to Token and type token to Token.T, keeping legacy aliases for some time;
 wenzelm parents: 
36955diff
changeset | 185 | (RESET_VALUE (Scan.one (Token.ident_with (fn y => x = y)) >> Token.content_of)); | 
| 16030 | 186 | |
| 9131 | 187 | val semicolon = $$$ ";"; | 
| 5826 | 188 | |
| 15703 | 189 | val minus = sym_ident :-- (fn "-" => Scan.succeed () | _ => Scan.fail) >> #1; | 
| 11792 
311eee3d63b6
parser for underscore (actually a symbolic identifier!);
 wenzelm parents: 
11651diff
changeset | 190 | val underscore = sym_ident :-- (fn "_" => Scan.succeed () | _ => Scan.fail) >> #1; | 
| 15703 | 191 | fun maybe scan = underscore >> K NONE || scan >> SOME; | 
| 11792 
311eee3d63b6
parser for underscore (actually a symbolic identifier!);
 wenzelm parents: 
11651diff
changeset | 192 | |
| 14835 | 193 | val nat = number >> (#1 o Library.read_int o Symbol.explode); | 
| 27815 | 194 | val int = Scan.optional (minus >> K ~1) 1 -- nat >> op *; | 
| 5826 | 195 | |
| 17070 | 196 | val tag_name = group "tag name" (short_ident || string); | 
| 197 | val tags = Scan.repeat ($$$ "%" |-- !!! tag_name); | |
| 198 | ||
| 7930 | 199 | val opt_unit = Scan.optional ($$$ "(" -- $$$ ")" >> (K ())) ();
 | 
| 14646 | 200 | fun opt_keyword s = Scan.optional ($$$ "(" |-- !!! (($$$ s >> K true) --| $$$ ")")) false;
 | 
| 201 | ||
| 20983 | 202 | val begin = $$$ "begin"; | 
| 203 | val opt_begin = Scan.optional (begin >> K true) false; | |
| 20961 | 204 | |
| 5826 | 205 | |
| 206 | (* enumerations *) | |
| 207 | ||
| 25999 | 208 | fun enum1 sep scan = scan ::: Scan.repeat ($$$ sep |-- !!! scan); | 
| 5826 | 209 | fun enum sep scan = enum1 sep scan || Scan.succeed []; | 
| 210 | ||
| 27815 | 211 | fun enum1' sep scan = scan ::: Scan.repeat (Scan.lift ($$$ sep) |-- scan); | 
| 212 | fun enum' sep scan = enum1' sep scan || Scan.succeed []; | |
| 5826 | 213 | |
| 6013 | 214 | fun and_list1 scan = enum1 "and" scan; | 
| 215 | fun and_list scan = enum "and" scan; | |
| 216 | ||
| 27815 | 217 | fun and_list1' scan = enum1' "and" scan; | 
| 218 | fun and_list' scan = enum' "and" scan; | |
| 219 | ||
| 220 | fun list1 scan = enum1 "," scan; | |
| 221 | fun list scan = enum "," scan; | |
| 222 | ||
| 5826 | 223 | |
| 5960 | 224 | (* names and text *) | 
| 5826 | 225 | |
| 8146 | 226 | val name = group "name declaration" (short_ident || sym_ident || string || number); | 
| 30223 
24d975352879
renamed Binding.name_pos to Binding.make, renamed Binding.base_name to Binding.name_of, renamed Binding.map_base to Binding.map_name, added mandatory flag to Binding.qualify;
 wenzelm parents: 
29581diff
changeset | 227 | val binding = position name >> Binding.make; | 
| 8146 | 228 | val xname = group "name reference" (short_ident || long_ident || sym_ident || string || number); | 
| 229 | val text = group "text" (short_ident || long_ident || sym_ident || string || number || verbatim); | |
| 21858 
05f57309170c
avoid conflict with Alice keywords: renamed pack -> implode, unpack -> explode, any -> many, avoided assert;
 wenzelm parents: 
21609diff
changeset | 230 | val path = group "file name/path specification" name >> Path.explode; | 
| 6553 | 231 | |
| 18898 | 232 | val parname = Scan.optional ($$$ "(" |-- name --| $$$ ")") "";
 | 
| 28965 | 233 | val parbinding = Scan.optional ($$$ "(" |-- binding --| $$$ ")") Binding.empty;
 | 
| 18898 | 234 | |
| 6553 | 235 | |
| 6372 | 236 | (* sorts and arities *) | 
| 5826 | 237 | |
| 27753 
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
 wenzelm parents: 
27737diff
changeset | 238 | val sort = group "sort" (inner_syntax xname); | 
| 5826 | 239 | |
| 22331 | 240 | val arity = xname -- ($$$ "::" |-- !!! | 
| 241 |   (Scan.optional ($$$ "(" |-- !!! (list1 sort --| $$$ ")")) [] -- sort)) >> triple2;
 | |
| 5826 | 242 | |
| 25541 | 243 | val multi_arity = and_list1 xname -- ($$$ "::" |-- !!! | 
| 244 |   (Scan.optional ($$$ "(" |-- !!! (list1 sort --| $$$ ")")) [] -- sort)) >> triple2;
 | |
| 245 | ||
| 5826 | 246 | |
| 247 | (* types *) | |
| 248 | ||
| 27753 
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
 wenzelm parents: 
27737diff
changeset | 249 | val typ_group = group "type" | 
| 8146 | 250 | (short_ident || long_ident || sym_ident || type_ident || type_var || string || number); | 
| 5826 | 251 | |
| 27753 
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
 wenzelm parents: 
27737diff
changeset | 252 | val typ = inner_syntax typ_group; | 
| 
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
 wenzelm parents: 
27737diff
changeset | 253 | |
| 35838 | 254 | fun type_arguments arg = | 
| 255 | arg >> single || | |
| 256 |   $$$ "(" |-- !!! (list1 arg --| $$$ ")") ||
 | |
| 5826 | 257 | Scan.succeed []; | 
| 258 | ||
| 35838 | 259 | val type_args = type_arguments type_ident; | 
| 260 | val type_args_constrained = type_arguments (type_ident -- Scan.option ($$$ "::" |-- !!! sort)); | |
| 261 | ||
| 5826 | 262 | |
| 263 | (* mixfix annotations *) | |
| 264 | ||
| 18669 | 265 | val mfix = string -- | 
| 266 | !!! (Scan.optional ($$$ "[" |-- !!! (list nat --| $$$ "]")) [] -- | |
| 267 | Scan.optional nat Syntax.max_pri) >> (Mixfix o triple2); | |
| 268 | ||
| 35130 | 269 | val infx = $$$ "infix" |-- !!! (string -- nat >> Infix); | 
| 270 | val infxl = $$$ "infixl" |-- !!! (string -- nat >> Infixl); | |
| 271 | val infxr = $$$ "infixr" |-- !!! (string -- nat >> Infixr); | |
| 5826 | 272 | |
| 18669 | 273 | val binder = $$$ "binder" |-- | 
| 274 | !!! (string -- ($$$ "[" |-- nat --| $$$ "]" -- nat || nat >> (fn n => (n, n)))) | |
| 275 | >> (Binder o triple2); | |
| 276 | ||
| 277 | fun annotation guard fix = $$$ "(" |-- guard (fix --| $$$ ")");
 | |
| 278 | fun opt_annotation guard fix = Scan.optional (annotation guard fix) NoSyn; | |
| 279 | ||
| 280 | val mixfix = annotation !!! (mfix || binder || infxl || infxr || infx); | |
| 21609 | 281 | val mixfix' = annotation I (mfix || binder || infxl || infxr || infx); | 
| 18669 | 282 | val opt_mixfix = opt_annotation !!! (mfix || binder || infxl || infxr || infx); | 
| 283 | val opt_mixfix' = opt_annotation I (mfix || binder || infxl || infxr || infx); | |
| 5826 | 284 | |
| 285 | ||
| 18669 | 286 | (* fixes *) | 
| 5826 | 287 | |
| 21400 | 288 | val where_ = $$$ "where"; | 
| 289 | ||
| 18618 | 290 | val const = name -- ($$$ "::" |-- !!! typ) -- opt_mixfix >> triple1; | 
| 30339 | 291 | val const_binding = binding -- ($$$ "::" |-- !!! typ) -- opt_mixfix >> triple1; | 
| 18669 | 292 | |
| 28081 
d664b2c1dfe6
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
28017diff
changeset | 293 | val params = Scan.repeat1 binding -- Scan.option ($$$ "::" |-- !!! typ) | 
| 18669 | 294 | >> (fn (xs, T) => map (rpair T) xs); | 
| 295 | ||
| 19482 
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
 wenzelm parents: 
19284diff
changeset | 296 | val simple_fixes = and_list1 params >> flat; | 
| 18669 | 297 | |
| 298 | val fixes = | |
| 28081 
d664b2c1dfe6
explicit type Name.binding for higher-specification elements;
 wenzelm parents: 
28017diff
changeset | 299 | and_list1 (binding -- Scan.option ($$$ "::" |-- typ) -- mixfix >> (single o triple1) || | 
| 19482 
9f11af8f7ef9
tuned basic list operators (flat, maps, map_filter);
 wenzelm parents: 
19284diff
changeset | 300 | params >> map Syntax.no_syn) >> flat; | 
| 5826 | 301 | |
| 19845 | 302 | val for_fixes = Scan.optional ($$$ "for" |-- !!! fixes) []; | 
| 21371 | 303 | val for_simple_fixes = Scan.optional ($$$ "for" |-- !!! simple_fixes) []; | 
| 19845 | 304 | |
| 5826 | 305 | |
| 27877 | 306 | (* embedded source text *) | 
| 27872 
631371a02b8c
P.doc_source and P.ml_sorce for proper SymbolPos.text;
 wenzelm parents: 
27815diff
changeset | 307 | |
| 27877 | 308 | val ML_source = source_position (group "ML source" text); | 
| 27872 
631371a02b8c
P.doc_source and P.ml_sorce for proper SymbolPos.text;
 wenzelm parents: 
27815diff
changeset | 309 | val doc_source = source_position (group "document source" text); | 
| 
631371a02b8c
P.doc_source and P.ml_sorce for proper SymbolPos.text;
 wenzelm parents: 
27815diff
changeset | 310 | |
| 
631371a02b8c
P.doc_source and P.ml_sorce for proper SymbolPos.text;
 wenzelm parents: 
27815diff
changeset | 311 | |
| 5826 | 312 | (* terms *) | 
| 313 | ||
| 7477 | 314 | val trm = short_ident || long_ident || sym_ident || term_var || number || string; | 
| 5826 | 315 | |
| 27753 
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
 wenzelm parents: 
27737diff
changeset | 316 | val term_group = group "term" trm; | 
| 
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
 wenzelm parents: 
27737diff
changeset | 317 | val prop_group = group "proposition" trm; | 
| 
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
 wenzelm parents: 
27737diff
changeset | 318 | |
| 
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
 wenzelm parents: 
27737diff
changeset | 319 | val term = inner_syntax term_group; | 
| 
94b672153b49
sort/typ/term/prop: inner_syntax markup encodes original source position;
 wenzelm parents: 
27737diff
changeset | 320 | val prop = inner_syntax prop_group; | 
| 5826 | 321 | |
| 322 | ||
| 6949 | 323 | (* patterns *) | 
| 6935 | 324 | |
| 6949 | 325 | val is_terms = Scan.repeat1 ($$$ "is" |-- term); | 
| 6935 | 326 | val is_props = Scan.repeat1 ($$$ "is" |-- prop); | 
| 327 | ||
| 19585 | 328 | val propp = prop -- Scan.optional ($$$ "(" |-- !!! (is_props --| $$$ ")")) [];
 | 
| 6949 | 329 | val termp = term -- Scan.optional ($$$ "(" |-- !!! (is_terms --| $$$ ")")) [];
 | 
| 6935 | 330 | |
| 331 | ||
| 22119 | 332 | (* targets *) | 
| 19811 | 333 | |
| 22119 | 334 | val target = ($$$ "(" -- $$$ "in") |-- !!! (xname --| $$$ ")");
 | 
| 335 | val opt_target = Scan.option target; | |
| 12272 | 336 | |
| 337 | end; | |
| 30511 | 338 | |
| 36949 
080e85d46108
renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
 wenzelm parents: 
35838diff
changeset | 339 | type 'a parser = 'a Parse.parser; | 
| 
080e85d46108
renamed structure OuterKeyword to Keyword and OuterParse to Parse, keeping the old names as legacy aliases for some time;
 wenzelm parents: 
35838diff
changeset | 340 | type 'a context_parser = 'a Parse.context_parser; | 
| 30511 | 341 |