src/Pure/Isar/token.ML
changeset 59913 a7f6359665c6
parent 59908 fdf6957f8635
child 59924 801b979ec0c2
equal deleted inserted replaced
59912:c7ba9b133bd4 59913:a7f6359665c6
    30     Files of file Exn.result list
    30     Files of file Exn.result list
    31   val name0: string -> value
    31   val name0: string -> value
    32   val pos_of: T -> Position.T
    32   val pos_of: T -> Position.T
    33   val range_of: T list -> Position.range
    33   val range_of: T list -> Position.range
    34   val src: xstring * Position.T -> T list -> src
    34   val src: xstring * Position.T -> T list -> src
       
    35   val src_checked: string * Position.T -> T list -> string * Markup.T -> src
    35   val name_of_src: src -> string * Position.T
    36   val name_of_src: src -> string * Position.T
    36   val args_of_src: src -> T list
    37   val args_of_src: src -> T list
    37   val range_of_src: src -> Position.T
    38   val range_of_src: src -> Position.T
    38   val check_src: Proof.context -> 'a Name_Space.table -> src -> src * 'a
    39   val check_src: Proof.context -> 'a Name_Space.table -> src -> src * 'a
    39   val eof: T
    40   val eof: T
   159 
   160 
   160 and src =
   161 and src =
   161   Src of
   162   Src of
   162    {name: string * Position.T,
   163    {name: string * Position.T,
   163     args: T list,
   164     args: T list,
   164     checked_markup: (string * Markup.T) option}
   165     checked: (string * Markup.T) option}
   165 
   166 
   166 and slot =
   167 and slot =
   167   Slot |
   168   Slot |
   168   Value of value option |
   169   Value of value option |
   169   Assignable of value option Unsynchronized.ref
   170   Assignable of value option Unsynchronized.ref
   193   | range_of [] = Position.no_range;
   194   | range_of [] = Position.no_range;
   194 
   195 
   195 
   196 
   196 (* src *)
   197 (* src *)
   197 
   198 
   198 fun src name args = Src {name = name, args = args, checked_markup = NONE};
   199 fun src name args = Src {name = name, args = args, checked = NONE};
   199 
   200 fun src_checked name args checked = Src {name = name, args = args, checked = SOME checked};
   200 fun map_args f (Src {name, args, checked_markup}) =
   201 
   201   Src {name = name, args = map f args, checked_markup = checked_markup};
   202 fun map_args f (Src {name, args, checked}) =
       
   203   Src {name = name, args = map f args, checked = checked};
   202 
   204 
   203 fun name_of_src (Src {name, ...}) = name;
   205 fun name_of_src (Src {name, ...}) = name;
   204 fun args_of_src (Src {args, ...}) = args;
   206 fun args_of_src (Src {args, ...}) = args;
   205 
   207 
   206 fun range_of_src (Src {name = (_, pos), args, ...}) =
   208 fun range_of_src (Src {name = (_, pos), args, ...}) =
   207   if null args then pos
   209   if null args then pos
   208   else Position.set_range (pos, #2 (range_of args));
   210   else Position.set_range (pos, #2 (range_of args));
   209 
   211 
   210 fun check_src _ table (src as Src {name = (name, _), checked_markup = SOME _, ...}) =
   212 fun check_src _ table (src as Src {name = (name, _), checked = SOME _, ...}) =
   211       (src, Name_Space.get table name)
   213       (src, Name_Space.get table name)
   212   | check_src ctxt table (Src {name = (xname, pos), args, checked_markup = NONE}) =
   214   | check_src ctxt table (Src {name = (xname, pos), args, checked = NONE}) =
   213       let
   215       let
   214         val (name, x) = Name_Space.check (Context.Proof ctxt) table (xname, pos);
   216         val (name, x) = Name_Space.check (Context.Proof ctxt) table (xname, pos);
   215         val space = Name_Space.space_of_table table;
   217         val space = Name_Space.space_of_table table;
   216         val kind = Name_Space.kind_of space;
   218         val kind = Name_Space.kind_of space;
   217         val markup = Name_Space.markup space name;
   219         val markup = Name_Space.markup space name;
   218       in (Src {name = (name, pos), args = args, checked_markup = SOME (kind, markup)}, x) end;
   220       in (src_checked (name, pos) args (kind, markup), x) end;
   219 
   221 
   220 
   222 
   221 (* stopper *)
   223 (* stopper *)
   222 
   224 
   223 fun mk_eof pos = Token (("", (pos, Position.none)), (EOF, ""), Slot);
   225 fun mk_eof pos = Token (("", (pos, Position.none)), (EOF, ""), Slot);
   476       Pretty.enclose "(" ")" (Pretty.breaks (map (Pretty.backquote o Display.pretty_thm ctxt) ths))
   478       Pretty.enclose "(" ")" (Pretty.breaks (map (Pretty.backquote o Display.pretty_thm ctxt) ths))
   477   | _ => Pretty.marks_str (markups Keyword.empty_keywords tok, unparse tok));
   479   | _ => Pretty.marks_str (markups Keyword.empty_keywords tok, unparse tok));
   478 
   480 
   479 fun pretty_src ctxt src =
   481 fun pretty_src ctxt src =
   480   let
   482   let
   481     val Src {name = (name, _), args, checked_markup} = src;
   483     val Src {name = (name, _), args, checked} = src;
   482     val prt_name =
   484     val prt_name =
   483       (case checked_markup of
   485       (case checked of
   484         NONE => Pretty.str name
   486         NONE => Pretty.str name
   485       | SOME (_, markup) => Pretty.mark_str (markup, name));
   487       | SOME (_, markup) => Pretty.mark_str (markup, name));
   486     val prt_arg = pretty_value ctxt;
   488     val prt_arg = pretty_value ctxt;
   487   in Pretty.block (Pretty.breaks (prt_name :: map prt_arg args)) end;
   489   in Pretty.block (Pretty.breaks (prt_name :: map prt_arg args)) end;
   488 
   490 
   661   in (case res of [x] => x | _ => err "") end;
   663   in (case res of [x] => x | _ => err "") end;
   662 
   664 
   663 
   665 
   664 (* wrapped syntax *)
   666 (* wrapped syntax *)
   665 
   667 
   666 fun syntax_generic scan (Src {name = (name, pos), args = args0, checked_markup}) context =
   668 fun syntax_generic scan (Src {name = (name, pos), args = args0, checked}) context =
   667   let
   669   let
   668     val args1 = map init_assignable args0;
   670     val args1 = map init_assignable args0;
   669     fun reported_text () =
   671     fun reported_text () =
   670       if Context_Position.is_visible_generic context then
   672       if Context_Position.is_visible_generic context then
   671         ((pos, Markup.operator) :: maps (reports_of_value o closure) args1)
   673         ((pos, Markup.operator) :: maps (reports_of_value o closure) args1)
   677         let val _ = Output.report (reported_text ())
   679         let val _ = Output.report (reported_text ())
   678         in (x, context') end
   680         in (x, context') end
   679     | (_, (_, args2)) =>
   681     | (_, (_, args2)) =>
   680         let
   682         let
   681           val print_name =
   683           val print_name =
   682             (case checked_markup of
   684             (case checked of
   683               NONE => quote name
   685               NONE => quote name
   684             | SOME (kind, markup) => plain_words kind ^ " " ^ quote (Markup.markup markup name));
   686             | SOME (kind, markup) => plain_words kind ^ " " ^ quote (Markup.markup markup name));
   685           val print_args =
   687           val print_args =
   686             if null args2 then "" else ":\n  " ^ space_implode " " (map print args2);
   688             if null args2 then "" else ":\n  " ^ space_implode " " (map print args2);
   687         in
   689         in
   694 
   696 
   695 end;
   697 end;
   696 
   698 
   697 type 'a parser = 'a Token.parser;
   699 type 'a parser = 'a Token.parser;
   698 type 'a context_parser = 'a Token.context_parser;
   700 type 'a context_parser = 'a Token.context_parser;
   699