1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/doc-src/more_antiquote.ML Wed Oct 01 08:42:42 2008 +0200
1.3 @@ -0,0 +1,75 @@
1.4 +(* Title: Doc/more_antiquote.ML
1.5 + ID: $Id$
1.6 + Author: Florian Haftmann, TU Muenchen
1.7 +
1.8 +More antiquotations.
1.9 +*)
1.10 +
1.11 +signature MORE_ANTIQUOTE =
1.12 +sig
1.13 + val verbatim_lines: string list -> string
1.14 +end;
1.15 +
1.16 +structure More_Antiquote : MORE_ANTIQUOTE =
1.17 +struct
1.18 +
1.19 +structure O = ThyOutput;
1.20 +
1.21 +(* printing verbatim lines *)
1.22 +
1.23 +val verbatim_line = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
1.24 +val verbatim_lines = rev
1.25 + #> dropwhile (fn s => s = "")
1.26 + #> rev
1.27 + #> map verbatim_line #> space_implode "\\newline%\n"
1.28 + #> prefix "\\isaverbatim%\n\\noindent%\n"
1.29 +
1.30 +
1.31 +(* class antiquotation *)
1.32 +
1.33 +local
1.34 +
1.35 +fun pr_class ctxt = enclose "\\isa{" "}" o Sign.extern_class (ProofContext.theory_of ctxt)
1.36 + o Sign.read_class (ProofContext.theory_of ctxt);
1.37 +
1.38 +in
1.39 +
1.40 +val _ = O.add_commands
1.41 + [("class", ThyOutput.args (Scan.lift Args.name) (K pr_class))]
1.42 +
1.43 +end;
1.44 +
1.45 +
1.46 +(* code antiquotation *)
1.47 +
1.48 +local
1.49 +
1.50 + val parse_const_terms = Scan.repeat1 Args.term
1.51 + >> (fn ts => fn thy => map (Code_Unit.check_const thy) ts);
1.52 + val parse_consts = Scan.lift (Args.parens (Args.$$$ "consts")) |-- parse_const_terms
1.53 + >> (fn mk_cs => fn thy => map (Code_Name.const thy) (mk_cs thy));
1.54 + val parse_types = Scan.lift (Args.parens (Args.$$$ "types") |-- Scan.repeat1 Args.name)
1.55 + >> (fn tycos => fn thy => map (Code_Name.tyco thy o Sign.intern_type thy) tycos);
1.56 + val parse_classes = Scan.lift (Args.parens (Args.$$$ "classes") |-- Scan.repeat1 Args.name)
1.57 + >> (fn classes => fn thy => map (Code_Name.class thy o Sign.intern_class thy) classes);
1.58 + val parse_instances = Scan.lift (Args.parens (Args.$$$ "instances") |-- Scan.repeat1 (Args.name --| Args.$$$ "::" -- Args.name))
1.59 + >> (fn insts => fn thy => map (Code_Name.instance thy o apsnd (Sign.intern_type thy) o apfst (Sign.intern_class thy) o swap) insts);
1.60 + val parse_names = parse_consts || parse_types || parse_classes || parse_instances;
1.61 +
1.62 + fun code_stmts src ctxt ((mk_cs, mk_stmtss), target) =
1.63 + Code_Target.code_of (ProofContext.theory_of ctxt)
1.64 + target "Example" (mk_cs (ProofContext.theory_of ctxt))
1.65 + (maps (fn f => f (ProofContext.theory_of ctxt)) mk_stmtss)
1.66 + |> split_lines
1.67 + |> verbatim_lines;
1.68 +
1.69 +in
1.70 +
1.71 +val _ = O.add_commands
1.72 + [("code_stmts", O.args
1.73 + (parse_const_terms -- Scan.repeat parse_names -- Scan.lift (Args.parens Args.name))
1.74 + code_stmts)]
1.75 +
1.76 +end
1.77 +
1.78 +end;