doc-src/antiquote_setup.ML
changeset 39869 c269f6bd0a1f
parent 39858 5be7a57c3b4e
child 39873 b70cd46e8e44
equal deleted inserted replaced
39868:732ab20fec3b 39869:c269f6bd0a1f
    54 
    54 
    55 fun ml_structure (txt, _) = "functor XXX() = struct structure XX = " ^ txt ^ " end;";
    55 fun ml_structure (txt, _) = "functor XXX() = struct structure XX = " ^ txt ^ " end;";
    56 
    56 
    57 fun ml_functor (txt, _) = "ML_Env.check_functor " ^ ML_Syntax.print_string txt;
    57 fun ml_functor (txt, _) = "ML_Env.check_functor " ^ ML_Syntax.print_string txt;
    58 
    58 
       
    59 val is_name = ML_Lex.kind_of #> (fn kind => kind = ML_Lex.Ident orelse kind = ML_Lex.LongIdent);
       
    60 
       
    61 fun ml_name txt =
       
    62   (case filter is_name (ML_Lex.tokenize txt) of
       
    63     toks as [_] => ML_Lex.flatten toks
       
    64   | _ => error ("Single ML name expected in input: " ^ quote txt));
       
    65 
    59 fun index_ml name kind ml = Thy_Output.antiquotation name
    66 fun index_ml name kind ml = Thy_Output.antiquotation name
    60   (Scan.lift (Args.name -- Scan.optional (Args.colon |-- Args.name) ""))
    67   (Scan.lift (Args.name -- Scan.optional (Args.colon |-- Args.name) ""))
    61   (fn {context = ctxt, ...} => fn (txt1, txt2) =>
    68   (fn {context = ctxt, ...} => fn (txt1, txt2) =>
    62     let
    69     let
    63       val txt =
    70       val txt =
    68         else txt1 ^ " : " ^ txt2;
    75         else txt1 ^ " : " ^ txt2;
    69       val txt' = if kind = "" then txt else kind ^ " " ^ txt;
    76       val txt' = if kind = "" then txt else kind ^ " " ^ txt;
    70       val _ = ML_Context.eval_text_in (SOME ctxt) false Position.none (ml (txt1, txt2));  (* ML_Lex.read (!?) *)
    77       val _ = ML_Context.eval_text_in (SOME ctxt) false Position.none (ml (txt1, txt2));  (* ML_Lex.read (!?) *)
    71       val kind' = if kind = "" then "ML" else "ML " ^ kind;
    78       val kind' = if kind = "" then "ML" else "ML " ^ kind;
    72     in
    79     in
    73       "\\indexdef{}{" ^ kind' ^ "}{" ^ clean_string txt1 ^ "}" ^
    80       "\\indexdef{}{" ^ kind' ^ "}{" ^ clean_string (ml_name txt1) ^ "}" ^
    74       (txt'
    81       (txt'
    75       |> (if Config.get ctxt Thy_Output.quotes then quote else I)
    82       |> (if Config.get ctxt Thy_Output.quotes then quote else I)
    76       |> (if Config.get ctxt Thy_Output.display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
    83       |> (if Config.get ctxt Thy_Output.display then enclose "\\begin{verbatim}\n" "\n\\end{verbatim}"
    77           else split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n"))
    84           else split_lines #> map verbatim #> space_implode "\\isasep\\isanewline%\n"))
    78     end);
    85     end);