1.1 --- a/doc-src/IsarAdvanced/Codegen/Thy/Setup.thy Wed Oct 01 00:09:51 2008 +0200
1.2 +++ b/doc-src/IsarAdvanced/Codegen/Thy/Setup.thy Wed Oct 01 08:42:42 2008 +0200
1.3 @@ -1,61 +1,10 @@
1.4 theory Setup
1.5 imports Complex_Main
1.6 -uses "../../../antiquote_setup.ML"
1.7 +uses "../../../antiquote_setup.ML" "../../../more_antiquote.ML"
1.8 begin
1.9
1.10 ML {* no_document use_thys ["Efficient_Nat", "Code_Char_chr"] *}
1.11
1.12 ML_val {* Code_Target.code_width := 74 *}
1.13
1.14 -ML {*
1.15 -fun pr_class ctxt = enclose "\\isa{" "}" o Sign.extern_class (ProofContext.theory_of ctxt)
1.16 - o Sign.read_class (ProofContext.theory_of ctxt);
1.17 -*}
1.18 -
1.19 -ML {*
1.20 -val _ = ThyOutput.add_commands
1.21 - [("class", ThyOutput.args (Scan.lift Args.name) (K pr_class))]
1.22 -*}
1.23 -
1.24 -ML {*
1.25 -val verbatim_line = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
1.26 -val verbatim_lines = rev
1.27 - #> dropwhile (fn s => s = "")
1.28 - #> rev
1.29 - #> map verbatim_line #> space_implode "\\newline%\n"
1.30 - #> prefix "\\isaverbatim%\n\\noindent%\n"
1.31 -*}
1.32 -
1.33 -ML {*
1.34 -local
1.35 -
1.36 - val parse_const_terms = Scan.repeat1 Args.term
1.37 - >> (fn ts => fn thy => map (Code_Unit.check_const thy) ts);
1.38 - val parse_consts = Scan.lift (Args.parens (Args.$$$ "consts")) |-- parse_const_terms
1.39 - >> (fn mk_cs => fn thy => map (Code_Name.const thy) (mk_cs thy));
1.40 - val parse_types = Scan.lift (Args.parens (Args.$$$ "types") |-- Scan.repeat1 Args.name)
1.41 - >> (fn tycos => fn thy => map (Code_Name.tyco thy o Sign.intern_type thy) tycos);
1.42 - val parse_classes = Scan.lift (Args.parens (Args.$$$ "classes") |-- Scan.repeat1 Args.name)
1.43 - >> (fn classes => fn thy => map (Code_Name.class thy o Sign.intern_class thy) classes);
1.44 - val parse_instances = Scan.lift (Args.parens (Args.$$$ "instances") |-- Scan.repeat1 (Args.name --| Args.$$$ "::" -- Args.name))
1.45 - >> (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.46 - val parse_names = parse_consts || parse_types || parse_classes || parse_instances;
1.47 -
1.48 - fun code_stmts src ctxt ((mk_cs, mk_stmtss), target) =
1.49 - Code_Target.code_of (ProofContext.theory_of ctxt)
1.50 - target "Example" (mk_cs (ProofContext.theory_of ctxt))
1.51 - (maps (fn f => f (ProofContext.theory_of ctxt)) mk_stmtss)
1.52 - |> split_lines
1.53 - |> verbatim_lines;
1.54 -
1.55 -in
1.56 -
1.57 -val _ = ThyOutput.add_commands
1.58 - [("code_stmts", ThyOutput.args
1.59 - (parse_const_terms -- Scan.repeat parse_names -- Scan.lift (Args.parens Args.name))
1.60 - code_stmts)]
1.61 -
1.62 end
1.63 -*}
1.64 -
1.65 -end
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/doc-src/more_antiquote.ML Wed Oct 01 08:42:42 2008 +0200
2.3 @@ -0,0 +1,75 @@
2.4 +(* Title: Doc/more_antiquote.ML
2.5 + ID: $Id$
2.6 + Author: Florian Haftmann, TU Muenchen
2.7 +
2.8 +More antiquotations.
2.9 +*)
2.10 +
2.11 +signature MORE_ANTIQUOTE =
2.12 +sig
2.13 + val verbatim_lines: string list -> string
2.14 +end;
2.15 +
2.16 +structure More_Antiquote : MORE_ANTIQUOTE =
2.17 +struct
2.18 +
2.19 +structure O = ThyOutput;
2.20 +
2.21 +(* printing verbatim lines *)
2.22 +
2.23 +val verbatim_line = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
2.24 +val verbatim_lines = rev
2.25 + #> dropwhile (fn s => s = "")
2.26 + #> rev
2.27 + #> map verbatim_line #> space_implode "\\newline%\n"
2.28 + #> prefix "\\isaverbatim%\n\\noindent%\n"
2.29 +
2.30 +
2.31 +(* class antiquotation *)
2.32 +
2.33 +local
2.34 +
2.35 +fun pr_class ctxt = enclose "\\isa{" "}" o Sign.extern_class (ProofContext.theory_of ctxt)
2.36 + o Sign.read_class (ProofContext.theory_of ctxt);
2.37 +
2.38 +in
2.39 +
2.40 +val _ = O.add_commands
2.41 + [("class", ThyOutput.args (Scan.lift Args.name) (K pr_class))]
2.42 +
2.43 +end;
2.44 +
2.45 +
2.46 +(* code antiquotation *)
2.47 +
2.48 +local
2.49 +
2.50 + val parse_const_terms = Scan.repeat1 Args.term
2.51 + >> (fn ts => fn thy => map (Code_Unit.check_const thy) ts);
2.52 + val parse_consts = Scan.lift (Args.parens (Args.$$$ "consts")) |-- parse_const_terms
2.53 + >> (fn mk_cs => fn thy => map (Code_Name.const thy) (mk_cs thy));
2.54 + val parse_types = Scan.lift (Args.parens (Args.$$$ "types") |-- Scan.repeat1 Args.name)
2.55 + >> (fn tycos => fn thy => map (Code_Name.tyco thy o Sign.intern_type thy) tycos);
2.56 + val parse_classes = Scan.lift (Args.parens (Args.$$$ "classes") |-- Scan.repeat1 Args.name)
2.57 + >> (fn classes => fn thy => map (Code_Name.class thy o Sign.intern_class thy) classes);
2.58 + val parse_instances = Scan.lift (Args.parens (Args.$$$ "instances") |-- Scan.repeat1 (Args.name --| Args.$$$ "::" -- Args.name))
2.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);
2.60 + val parse_names = parse_consts || parse_types || parse_classes || parse_instances;
2.61 +
2.62 + fun code_stmts src ctxt ((mk_cs, mk_stmtss), target) =
2.63 + Code_Target.code_of (ProofContext.theory_of ctxt)
2.64 + target "Example" (mk_cs (ProofContext.theory_of ctxt))
2.65 + (maps (fn f => f (ProofContext.theory_of ctxt)) mk_stmtss)
2.66 + |> split_lines
2.67 + |> verbatim_lines;
2.68 +
2.69 +in
2.70 +
2.71 +val _ = O.add_commands
2.72 + [("code_stmts", O.args
2.73 + (parse_const_terms -- Scan.repeat parse_names -- Scan.lift (Args.parens Args.name))
2.74 + code_stmts)]
2.75 +
2.76 +end
2.77 +
2.78 +end;