1 (* Title: Doc/more_antiquote.ML
3 Author: Florian Haftmann, TU Muenchen
8 signature MORE_ANTIQUOTE =
10 val verbatim_lines: string list -> string
13 structure More_Antiquote : MORE_ANTIQUOTE =
16 structure O = ThyOutput;
18 (* printing verbatim lines *)
20 val verbatim_line = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
21 val verbatim_lines = rev
22 #> dropwhile (fn s => s = "")
24 #> map verbatim_line #> space_implode "\\newline%\n"
25 #> prefix "\\isaverbatim%\n\\noindent%\n"
28 (* class antiquotation *)
32 fun pr_class ctxt = enclose "\\isa{" "}" o Sign.extern_class (ProofContext.theory_of ctxt)
33 o Sign.read_class (ProofContext.theory_of ctxt);
37 val _ = O.add_commands
38 [("class", ThyOutput.args (Scan.lift Args.name) (K pr_class))]
43 (* code antiquotation *)
47 val parse_const_terms = Scan.repeat1 Args.term
48 >> (fn ts => fn thy => map (Code_Unit.check_const thy) ts);
49 val parse_consts = Scan.lift (Args.parens (Args.$$$ "consts")) |-- parse_const_terms
50 >> (fn mk_cs => fn thy => map (Code_Name.const thy) (mk_cs thy));
51 val parse_types = Scan.lift (Args.parens (Args.$$$ "types") |-- Scan.repeat1 Args.name)
52 >> (fn tycos => fn thy => map (Code_Name.tyco thy o Sign.intern_type thy) tycos);
53 val parse_classes = Scan.lift (Args.parens (Args.$$$ "classes") |-- Scan.repeat1 Args.name)
54 >> (fn classes => fn thy => map (Code_Name.class thy o Sign.intern_class thy) classes);
55 val parse_instances = Scan.lift (Args.parens (Args.$$$ "instances") |-- Scan.repeat1 (Args.name --| Args.$$$ "::" -- Args.name))
56 >> (fn insts => fn thy => map (Code_Name.instance thy o apsnd (Sign.intern_type thy) o apfst (Sign.intern_class thy) o swap) insts);
57 val parse_names = parse_consts || parse_types || parse_classes || parse_instances;
59 fun code_stmts src ctxt ((mk_cs, mk_stmtss), target) =
60 Code_Target.code_of (ProofContext.theory_of ctxt)
61 target "Example" (mk_cs (ProofContext.theory_of ctxt))
62 (maps (fn f => f (ProofContext.theory_of ctxt)) mk_stmtss)
68 val _ = O.add_commands
69 [("code_stmts", O.args
70 (parse_const_terms -- Scan.repeat parse_names -- Scan.lift (Args.parens Args.name))