doc-src/more_antiquote.ML
author haftmann
Wed, 01 Oct 2008 08:42:42 +0200
changeset 28440 0b9ddfa6458e
child 28461 640b7f8f9cad
permissions -rw-r--r--
added more_antiquote.ML
     1 (*  Title:      Doc/more_antiquote.ML
     2     ID:         $Id$
     3     Author:     Florian Haftmann, TU Muenchen
     4 
     5 More antiquotations.
     6 *)
     7 
     8 signature MORE_ANTIQUOTE =
     9 sig
    10   val verbatim_lines: string list -> string
    11 end;
    12 
    13 structure More_Antiquote : MORE_ANTIQUOTE =
    14 struct
    15 
    16 structure O = ThyOutput;
    17 
    18 (* printing verbatim lines *)
    19 
    20 val verbatim_line = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
    21 val verbatim_lines = rev
    22   #> dropwhile (fn s => s = "")
    23   #> rev
    24   #> map verbatim_line #> space_implode "\\newline%\n"
    25   #> prefix "\\isaverbatim%\n\\noindent%\n"
    26 
    27 
    28 (* class antiquotation *)
    29 
    30 local
    31 
    32 fun pr_class ctxt = enclose "\\isa{" "}" o Sign.extern_class (ProofContext.theory_of ctxt)
    33   o Sign.read_class (ProofContext.theory_of ctxt);
    34 
    35 in
    36 
    37 val _ = O.add_commands
    38   [("class", ThyOutput.args (Scan.lift Args.name) (K pr_class))]
    39 
    40 end;
    41 
    42 
    43 (* code antiquotation *)
    44 
    45 local
    46 
    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; 
    58 
    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)
    63     |> split_lines
    64     |> verbatim_lines;
    65 
    66 in
    67 
    68 val _ = O.add_commands
    69   [("code_stmts", O.args
    70       (parse_const_terms -- Scan.repeat parse_names -- Scan.lift (Args.parens Args.name))
    71         code_stmts)]
    72 
    73 end
    74 
    75 end;