src/Pure/Isar/outer_keyword.ML
changeset 27433 b82c12e57e79
parent 27357 5b3a087ff292
child 27440 a1eda23752bd
equal deleted inserted replaced
27432:c5ec309c6de8 27433:b82c12e57e79
    45   val command_keyword: string -> T option
    45   val command_keyword: string -> T option
    46   val command_tags: string -> string list
    46   val command_tags: string -> string list
    47   val report: unit -> unit
    47   val report: unit -> unit
    48   val keyword: string -> unit
    48   val keyword: string -> unit
    49   val command: string -> T -> unit
    49   val command: string -> T -> unit
       
    50   datatype category = Theory | Proof | Other
       
    51   val category_of: string -> category
    50 end;
    52 end;
    51 
    53 
    52 structure OuterKeyword: OUTER_KEYWORD =
    54 structure OuterKeyword: OUTER_KEYWORD =
    53 struct
    55 struct
    54 
    56 
    86 val prf_script = kind "proof-script";
    88 val prf_script = kind "proof-script";
    87 
    89 
    88 val kinds = [control, diag, thy_begin, thy_switch, thy_end, thy_heading, thy_decl, thy_script,
    90 val kinds = [control, diag, thy_begin, thy_switch, thy_end, thy_heading, thy_decl, thy_script,
    89   thy_goal, qed, qed_block, qed_global, prf_heading, prf_goal, prf_block, prf_open, prf_close,
    91   thy_goal, qed, qed_block, qed_global, prf_heading, prf_goal, prf_block, prf_open, prf_close,
    90   prf_chain, prf_decl, prf_asm, prf_asm_goal, prf_script] |> map kind_of;
    92   prf_chain, prf_decl, prf_asm, prf_asm_goal, prf_script] |> map kind_of;
       
    93 
       
    94 val thy_kinds =
       
    95   [thy_begin, thy_switch, thy_end, thy_heading, thy_decl, thy_script, thy_goal] |> map kind_of;
       
    96 
       
    97 val prf_kinds =
       
    98   [qed, qed_block, qed_global, prf_heading, prf_goal, prf_block, prf_open, prf_close,
       
    99     prf_chain, prf_decl, prf_asm, prf_asm_goal, prf_script] |> map kind_of;
    91 
   100 
    92 
   101 
    93 (* tags *)
   102 (* tags *)
    94 
   103 
    95 fun update_tags t ts = t :: remove (op = : string * string -> bool) t ts;
   104 fun update_tags t ts = t :: remove (op = : string * string -> bool) t ts;
   162 fun command name kind =
   171 fun command name kind =
   163  (change_lexicons (apsnd (Scan.extend_lexicon [Symbol.explode name]));
   172  (change_lexicons (apsnd (Scan.extend_lexicon [Symbol.explode name]));
   164   change_commands (Symtab.update (name, kind));
   173   change_commands (Symtab.update (name, kind));
   165   Pretty.writeln (report_command (name, kind)));
   174   Pretty.writeln (report_command (name, kind)));
   166 
   175 
       
   176 
       
   177 (* overall category *)
       
   178 
       
   179 datatype category = Theory | Proof | Other;
       
   180 
       
   181 fun category_of name =
       
   182   (case command_keyword name of
       
   183     SOME kind =>
       
   184       let val k = kind_of kind in
       
   185         if member (op =) thy_kinds k then Theory
       
   186         else if member (op =) prf_kinds k then Proof
       
   187         else Other
       
   188       end
       
   189   | NONE => error ("Unknown command " ^ quote name));
       
   190 
   167 end;
   191 end;