src/Doc/antiquote_setup.ML
changeset 61620 01db1bed4487
parent 61618 27af754f50ca
child 61621 70b8085f51b4
equal deleted inserted replaced
61619:f22054b192b0 61620:01db1bed4487
   143 
   143 
   144 (* Isabelle/Isar entities (with index) *)
   144 (* Isabelle/Isar entities (with index) *)
   145 
   145 
   146 local
   146 local
   147 
   147 
   148 fun no_check _ _ = true;
   148 fun no_check (_: Proof.context) (name, _: Position.T) = name;
   149 
   149 
   150 fun is_keyword ctxt (name, _) =
   150 fun check_keyword ctxt (name, pos) =
   151   Keyword.is_keyword (Thy_Header.get_keywords' ctxt) name;
   151   if Keyword.is_keyword (Thy_Header.get_keywords' ctxt) name then name
   152 
   152   else error ("Bad outer syntax keyword " ^ quote name ^ Position.here pos);
   153 fun check_command ctxt (name, pos) = (Outer_Syntax.check_command ctxt (name, pos); true);
       
   154 
   153 
   155 fun check_system_option ctxt (name, pos) =
   154 fun check_system_option ctxt (name, pos) =
   156   (Context_Position.report ctxt pos (Options.default_markup (name, pos)); true)
   155   (Context_Position.report ctxt pos (Options.default_markup (name, pos)); true)
   157     handle ERROR _ => false;
   156     handle ERROR _ => false;
   158 
   157 
   164   in
   163   in
   165     (case get_first tool (Path.split (getenv "ISABELLE_TOOLS")) of
   164     (case get_first tool (Path.split (getenv "ISABELLE_TOOLS")) of
   166       NONE => false
   165       NONE => false
   167     | SOME path => (Context_Position.report ctxt pos (Markup.path (Path.implode path)); true))
   166     | SOME path => (Context_Position.report ctxt pos (Markup.path (Path.implode path)); true))
   168   end;
   167   end;
       
   168 
       
   169 fun check_action _ = can JEdit.check_action;
   169 
   170 
   170 val arg = enclose "{" "}" o clean_string;
   171 val arg = enclose "{" "}" o clean_string;
   171 
   172 
   172 fun entity check markup binding index =
   173 fun entity check markup binding index =
   173   Thy_Output.antiquotation
   174   Thy_Output.antiquotation
   185         val idx =
   186         val idx =
   186           (case index of
   187           (case index of
   187             NONE => ""
   188             NONE => ""
   188           | SOME is_def =>
   189           | SOME is_def =>
   189               "\\index" ^ (if is_def then "def" else "ref") ^ arg logic ^ arg kind ^ arg name);
   190               "\\index" ^ (if is_def then "def" else "ref") ^ arg logic ^ arg kind ^ arg name);
       
   191         val _ = check ctxt (name, pos);
   190       in
   192       in
   191         if check ctxt (name, pos) then
   193         idx ^
   192           idx ^
   194         (Output.output name
   193           (Output.output name
   195           |> (if markup = "" then I else enclose ("\\" ^ markup ^ "{") "}")
   194             |> (if markup = "" then I else enclose ("\\" ^ markup ^ "{") "}")
   196           |> hyper o enclose "\\mbox{\\isa{" "}}")
   195             |> hyper o enclose "\\mbox{\\isa{" "}}")
       
   196         else error ("Bad " ^ kind ^ " " ^ quote name ^ Position.here pos)
       
   197       end);
   197       end);
   198 
   198 
   199 fun entity_antiqs check markup kind =
   199 fun entity_antiqs check markup kind =
   200   entity check markup kind NONE #>
   200   entity check markup kind NONE #>
   201   entity check markup kind (SOME true) #>
   201   entity check markup kind (SOME true) #>
   204 in
   204 in
   205 
   205 
   206 val _ =
   206 val _ =
   207   Theory.setup
   207   Theory.setup
   208    (entity_antiqs no_check "" @{binding syntax} #>
   208    (entity_antiqs no_check "" @{binding syntax} #>
   209     entity_antiqs check_command "isacommand" @{binding command} #>
   209     entity_antiqs Outer_Syntax.check_command "isacommand" @{binding command} #>
   210     entity_antiqs is_keyword "isakeyword" @{binding keyword} #>
   210     entity_antiqs check_keyword "isakeyword" @{binding keyword} #>
   211     entity_antiqs is_keyword "isakeyword" @{binding element} #>
   211     entity_antiqs check_keyword "isakeyword" @{binding element} #>
   212     entity_antiqs (can o Method.check_name) "" @{binding method} #>
   212     entity_antiqs Method.check_name "" @{binding method} #>
   213     entity_antiqs (can o Attrib.check_name) "" @{binding attribute} #>
   213     entity_antiqs Attrib.check_name "" @{binding attribute} #>
   214     entity_antiqs no_check "" @{binding fact} #>
   214     entity_antiqs no_check "" @{binding fact} #>
   215     entity_antiqs no_check "" @{binding variable} #>
   215     entity_antiqs no_check "" @{binding variable} #>
   216     entity_antiqs no_check "" @{binding case} #>
   216     entity_antiqs no_check "" @{binding case} #>
   217     entity_antiqs (can o Thy_Output.check_command) "" @{binding antiquotation} #>
   217     entity_antiqs Thy_Output.check_command "" @{binding antiquotation} #>
   218     entity_antiqs (can o Thy_Output.check_option) "" @{binding antiquotation_option} #>
   218     entity_antiqs Thy_Output.check_option "" @{binding antiquotation_option} #>
   219     entity_antiqs no_check "isasystem" @{binding setting} #>
   219     entity_antiqs no_check "isasystem" @{binding setting} #>
   220     entity_antiqs check_system_option "isasystem" @{binding system_option} #>
   220     entity_antiqs check_system_option "isasystem" @{binding system_option} #>
   221     entity_antiqs no_check "" @{binding inference} #>
   221     entity_antiqs no_check "" @{binding inference} #>
   222     entity_antiqs no_check "isasystem" @{binding executable} #>
   222     entity_antiqs no_check "isasystem" @{binding executable} #>
   223     entity_antiqs check_tool "isatool" @{binding tool} #>
   223     entity_antiqs check_tool "isatool" @{binding tool} #>
   224     entity_antiqs (can o ML_Context.check_antiquotation) "" @{binding ML_antiquotation} #>
   224     entity_antiqs ML_Context.check_antiquotation "" @{binding ML_antiquotation} #>
   225     entity_antiqs (K (JEdit.is_action o #1)) "isasystem" @{binding action});
   225     entity_antiqs check_action "isasystem" @{binding action});
   226 
   226 
   227 end;
   227 end;
   228 
   228 
   229 end;
   229 end;