src/Pure/Isar/outer_syntax.ML
changeset 15570 8d8c70b41bab
parent 15531 08c8dad8e399
child 15830 74d8412b1a27
equal deleted inserted replaced
15569:1b3115d1a8df 15570:8d8c70b41bab
   181 (*Note: the syntax for files is statically determined at the very
   181 (*Note: the syntax for files is statically determined at the very
   182   beginning; for interactive processing it may change dynamically.*)
   182   beginning; for interactive processing it may change dynamically.*)
   183 
   183 
   184 fun get_lexicons () = ! global_lexicons;
   184 fun get_lexicons () = ! global_lexicons;
   185 fun get_parsers () = ! global_parsers;
   185 fun get_parsers () = ! global_parsers;
   186 fun get_parser () = apsome (#2 o #1) o curry Symtab.lookup (! global_parsers);
   186 fun get_parser () = Option.map (#2 o #1) o curry Symtab.lookup (! global_parsers);
   187 
   187 
   188 fun is_markup kind name =
   188 fun is_markup kind name =
   189   (case assoc (! global_markups, name) of SOME k => k = kind | NONE => false);
   189   (case assoc (! global_markups, name) of SOME k => k = kind | NONE => false);
   190 fun markup kind = Scan.one (T.is_kind T.Command andf is_markup kind o T.val_of);
   190 fun markup kind = Scan.one (T.is_kind T.Command andf is_markup kind o T.val_of);
   191 
   191 
   199  (if is_none (Symtab.lookup (tab, name)) then ()
   199  (if is_none (Symtab.lookup (tab, name)) then ()
   200   else warning ("Redefined outer syntax command " ^ quote name);
   200   else warning ("Redefined outer syntax command " ^ quote name);
   201   Symtab.update ((name, (((comment, kind), (int_only, parse)), markup)), tab));
   201   Symtab.update ((name, (((comment, kind), (int_only, parse)), markup)), tab));
   202 
   202 
   203 fun add_parsers parsers =
   203 fun add_parsers parsers =
   204   (change_parsers (fn tab => foldl add_parser (tab, parsers));
   204   (change_parsers (fn tab => Library.foldl add_parser (tab, parsers));
   205     change_lexicons (apsnd (fn lex => Scan.extend_lexicon lex
   205     change_lexicons (apsnd (fn lex => Scan.extend_lexicon lex
   206       (map (fn Parser (name, _, _, _) => Symbol.explode name) parsers))));
   206       (map (fn Parser (name, _, _, _) => Symbol.explode name) parsers))));
   207 
   207 
   208 end;
   208 end;
   209 
   209 
   219 
   219 
   220 fun print_outer_syntax () =
   220 fun print_outer_syntax () =
   221   let
   221   let
   222     fun pretty_cmd (name, comment, _, _) =
   222     fun pretty_cmd (name, comment, _, _) =
   223       Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment];
   223       Pretty.block [Pretty.str (name ^ ":"), Pretty.brk 2, Pretty.str comment];
   224     val (int_cmds, cmds) = partition #4 (dest_parsers ());
   224     val (int_cmds, cmds) = List.partition #4 (dest_parsers ());
   225   in
   225   in
   226     [Pretty.strs ("syntax keywords:" :: map quote (dest_keywords ())),
   226     [Pretty.strs ("syntax keywords:" :: map quote (dest_keywords ())),
   227       Pretty.big_list "proper commands:" (map pretty_cmd cmds),
   227       Pretty.big_list "proper commands:" (map pretty_cmd cmds),
   228       Pretty.big_list "improper commands (interactive-only):" (map pretty_cmd int_cmds)]
   228       Pretty.big_list "improper commands (interactive-only):" (map pretty_cmd int_cmds)]
   229     |> Pretty.chunks |> Pretty.writeln
   229     |> Pretty.chunks |> Pretty.writeln
   275 
   275 
   276 fun read toks =
   276 fun read toks =
   277   Source.of_list toks
   277   Source.of_list toks
   278   |> toplevel_source false true true get_parser
   278   |> toplevel_source false true true get_parser
   279   |> Source.exhaust
   279   |> Source.exhaust
   280   |> map (fn tr => (Toplevel.name_of tr, the (Toplevel.source_of tr), tr));
   280   |> map (fn tr => (Toplevel.name_of tr, valOf (Toplevel.source_of tr), tr));
   281 
   281 
   282 
   282 
   283 (** read theory **)
   283 (** read theory **)
   284 
   284 
   285 (* check_text *)
   285 (* check_text *)
   294   let
   294   let
   295     val src = Source.of_string (File.read path);
   295     val src = Source.of_string (File.read path);
   296     val pos = Path.position path;
   296     val pos = Path.position path;
   297     val (name', parents, files) = ThyHeader.scan (src, pos);
   297     val (name', parents, files) = ThyHeader.scan (src, pos);
   298     val ml_path = ThyLoad.ml_path name;
   298     val ml_path = ThyLoad.ml_path name;
   299     val ml_file = if ml andalso is_some (ThyLoad.check_file NONE ml_path) then [ml_path] else [];
   299     val ml_file = if ml andalso isSome (ThyLoad.check_file NONE ml_path) then [ml_path] else [];
   300   in
   300   in
   301     if name <> name' then
   301     if name <> name' then
   302       error ("Filename " ^ quote (Path.pack path) ^
   302       error ("Filename " ^ quote (Path.pack path) ^
   303         " does not agree with theory name " ^ quote name')
   303         " does not agree with theory name " ^ quote name')
   304     else (parents, map (Path.unpack o #1) files @ ml_file)
   304     else (parents, map (Path.unpack o #1) files @ ml_file)