src/Doc/antiquote_setup.ML
changeset 53044 be27b6be8027
parent 52408 fa2dc6c6c94f
child 53045 4c297ee47c28
     1.1 --- a/src/Doc/antiquote_setup.ML	Fri Aug 16 21:33:36 2013 +0200
     1.2 +++ b/src/Doc/antiquote_setup.ML	Fri Aug 16 22:39:31 2013 +0200
     1.3 @@ -146,13 +146,20 @@
     1.4  
     1.5  fun no_check _ _ = true;
     1.6  
     1.7 -fun thy_check intern defined ctxt =
     1.8 -  let val thy = Proof_Context.theory_of ctxt
     1.9 -  in defined thy o intern thy end;
    1.10 +fun thy_check check ctxt = can (check (Proof_Context.theory_of ctxt));
    1.11  
    1.12 -fun check_tool name =
    1.13 -  let val tool_dirs = map Path.explode ["~~/lib/Tools", "~~/src/Tools/jEdit/lib/Tools"]
    1.14 -  in exists (fn dir => File.exists (Path.append dir (Path.basic name))) tool_dirs end;
    1.15 +fun check_tool (name, pos) =
    1.16 +  let
    1.17 +    (* FIXME ISABELLE_TOOLS !? *)
    1.18 +    val dirs = map Path.explode ["~~/lib/Tools", "~~/src/Tools/jEdit/lib/Tools"];
    1.19 +    fun tool dir =
    1.20 +      let val path = Path.append dir (Path.basic name)
    1.21 +      in if File.exists path then SOME path else NONE end;
    1.22 +  in
    1.23 +    (case get_first tool dirs of
    1.24 +      NONE => false
    1.25 +    | SOME path => (Position.report pos (Markup.path (Path.implode path)); true))
    1.26 +  end;
    1.27  
    1.28  val arg = enclose "{" "}" o clean_string;
    1.29  
    1.30 @@ -160,8 +167,8 @@
    1.31    Thy_Output.antiquotation
    1.32      (Binding.name (translate (fn " " => "_" | c => c) kind ^
    1.33        (case index of NONE => "" | SOME true => "_def" | SOME false => "_ref")))
    1.34 -    (Scan.lift (Scan.optional (Args.parens Args.name) "" -- Args.name))
    1.35 -    (fn {context = ctxt, ...} => fn (logic, name) =>
    1.36 +    (Scan.lift (Scan.optional (Args.parens Args.name) "" -- Parse.position Args.name))
    1.37 +    (fn {context = ctxt, ...} => fn (logic, (name, pos)) =>
    1.38        let
    1.39          val hyper_name =
    1.40            "{" ^ Long_Name.append kind (Long_Name.append logic (clean_name name)) ^ "}";
    1.41 @@ -174,7 +181,7 @@
    1.42            | SOME is_def =>
    1.43                "\\index" ^ (if is_def then "def" else "ref") ^ arg logic ^ arg kind ^ arg name);
    1.44        in
    1.45 -        if check ctxt name then
    1.46 +        if check ctxt (name, pos) then
    1.47            idx ^
    1.48            (Output.output name
    1.49              |> (if markup = "" then I else enclose ("\\" ^ markup ^ "{") "}")
    1.50 @@ -182,7 +189,7 @@
    1.51              |> (if Config.get ctxt Thy_Output.display
    1.52                  then enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
    1.53                  else hyper o enclose "\\mbox{\\isa{" "}}"))
    1.54 -        else error ("Bad " ^ kind ^ " " ^ quote name)
    1.55 +        else error ("Bad " ^ kind ^ " " ^ quote name ^ Position.here pos)
    1.56        end);
    1.57  
    1.58  fun entity_antiqs check markup kind =
    1.59 @@ -194,25 +201,22 @@
    1.60  
    1.61  val entity_setup =
    1.62    entity_antiqs no_check "" "syntax" #>
    1.63 -  entity_antiqs (K (is_some o Keyword.command_keyword)) "isacommand" "command" #>
    1.64 -  entity_antiqs (K Keyword.is_keyword) "isakeyword" "keyword" #>
    1.65 -  entity_antiqs (K Keyword.is_keyword) "isakeyword" "element" #>
    1.66 -  entity_antiqs (thy_check Method.intern Method.defined) "" "method" #>
    1.67 -  entity_antiqs (thy_check Attrib.intern Attrib.defined) "" "attribute" #>
    1.68 +  entity_antiqs (K (is_some o Keyword.command_keyword o #1)) "isacommand" "command" #>
    1.69 +  entity_antiqs (K (Keyword.is_keyword o #1)) "isakeyword" "keyword" #>
    1.70 +  entity_antiqs (K (Keyword.is_keyword o #1)) "isakeyword" "element" #>
    1.71 +  entity_antiqs (thy_check Method.check) "" "method" #>
    1.72 +  entity_antiqs (thy_check Attrib.check) "" "attribute" #>
    1.73    entity_antiqs no_check "" "fact" #>
    1.74    entity_antiqs no_check "" "variable" #>
    1.75    entity_antiqs no_check "" "case" #>
    1.76 -  entity_antiqs (thy_check Thy_Output.intern_command Thy_Output.defined_command)
    1.77 -    "" "antiquotation" #>
    1.78 -  entity_antiqs (thy_check Thy_Output.intern_option Thy_Output.defined_option)
    1.79 -    "" "antiquotation option" #>
    1.80 +  entity_antiqs (thy_check Thy_Output.check_command) "" "antiquotation" #>
    1.81 +  entity_antiqs (thy_check Thy_Output.check_option) "" "antiquotation option" #>
    1.82    entity_antiqs no_check "isatt" "setting" #>
    1.83    entity_antiqs no_check "isatt" "system option" #>
    1.84    entity_antiqs no_check "" "inference" #>
    1.85    entity_antiqs no_check "isatt" "executable" #>
    1.86    entity_antiqs (K check_tool) "isatool" "tool" #>
    1.87 -  entity_antiqs (thy_check ML_Context.intern_antiq ML_Context.defined_antiq)
    1.88 -    "" Markup.ML_antiquotationN;
    1.89 +  entity_antiqs (thy_check ML_Context.check_antiq) "" Markup.ML_antiquotationN;
    1.90  
    1.91  end;
    1.92