CookBook/chunks.ML
author Christian Urban <urbanc@in.tum.de>
Sun, 08 Feb 2009 08:45:25 +0000
changeset 104 5dcad9348e4d
parent 96 018bfa718982
child 117 796c6ea633b3
permissions -rw-r--r--
polished
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
90
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
     1
24
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
     2
structure Chunks =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
     3
struct
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
     4
90
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
     5
(* rebuilding the output_list function from ThyOutput in order to *)
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
     6
(* enable the option [gray] *)
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
     7
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
     8
val gray = ref false;
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
     9
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    10
fun boolean "" = true
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    11
  | boolean "true" = true
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    12
  | boolean "false" = false
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    13
  | boolean s = error ("Bad boolean value: " ^ quote s);
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    14
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    15
fun output_list pretty src ctxt xs =
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    16
  map (pretty ctxt) xs        (*always pretty in order to exhibit errors!*)
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    17
  |> (if ! ThyOutput.source then K [ThyOutput.pretty_text (ThyOutput.str_of_source src)] else I)
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    18
  |> (if ! ThyOutput.quotes then map Pretty.quote else I)
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    19
  |> (if ! ThyOutput.display then
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    20
    map (Output.output o Pretty.string_of o Pretty.indent (! ThyOutput.indent))
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    21
    #> space_implode "\\isasep\\isanewline%\n"
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    22
    #> (if ! gray then (enclose "\\begin{graybox}%\n" "%\n\\end{graybox}") else I) 
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    23
    #> enclose "\\begin{isabelle}%\n" "%\n\\end{isabelle}"
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    24
 else
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    25
    map (Output.output o (if ! ThyOutput.break then Pretty.string_of else Pretty.str_of))
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    26
    #> space_implode "\\isasep\\isanewline%\n"
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    27
    #> enclose "\\isa{" "}");
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    28
96
018bfa718982 (re)defined the document antiquotation @subgoal in order to be closer to what is actually printed
Christian Urban <urbanc@in.tum.de>
parents: 90
diff changeset
    29
fun output pretty src ctxt = output_list pretty src ctxt o single
018bfa718982 (re)defined the document antiquotation @subgoal in order to be closer to what is actually printed
Christian Urban <urbanc@in.tum.de>
parents: 90
diff changeset
    30
90
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    31
val _ = ThyOutput.add_options
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    32
 [("gray", Library.setmp gray o boolean)]
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
    33
96
018bfa718982 (re)defined the document antiquotation @subgoal in order to be closer to what is actually printed
Christian Urban <urbanc@in.tum.de>
parents: 90
diff changeset
    34
018bfa718982 (re)defined the document antiquotation @subgoal in order to be closer to what is actually printed
Christian Urban <urbanc@in.tum.de>
parents: 90
diff changeset
    35
018bfa718982 (re)defined the document antiquotation @subgoal in order to be closer to what is actually printed
Christian Urban <urbanc@in.tum.de>
parents: 90
diff changeset
    36
24
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    37
(** theory data **)
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    38
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    39
structure ChunkData = TheoryDataFun
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    40
(
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    41
  type T = (ML_Lex.token list * stamp) NameSpace.table
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    42
  val empty = NameSpace.empty_table;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    43
  val copy = I;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    44
  val extend = I;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    45
  fun merge _ tables : T = NameSpace.merge_tables (eq_snd (op =)) tables handle Symtab.DUP dup =>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    46
    error ("Attempt to merge different versions of ML chunk " ^ quote dup);
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    47
);
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    48
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    49
fun declare_chunk name thy =
55
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 24
diff changeset
    50
  (Sign.full_bname thy name,
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 24
diff changeset
    51
   ChunkData.map (snd o NameSpace.bind (Sign.naming_of thy)
0b55402ae95e Adapted to changes in binding module.
berghofe
parents: 24
diff changeset
    52
     (Binding.name name, ([], stamp ()))) thy
24
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    53
   handle Symtab.DUP _ => error ("Duplicate definition of ML chunk " ^ quote name));
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    54
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    55
fun augment_chunk tok name =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    56
  ChunkData.map (apsnd (Symtab.map_entry name (apfst (cons tok))));
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    57
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    58
fun the_chunk thy name =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    59
  let val (space, tab) = ChunkData.get thy
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    60
  in case Symtab.lookup tab (NameSpace.intern space name) of
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    61
      NONE => error ("Unknown ML chunk " ^ quote name)
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    62
    | SOME (toks, _) => rev toks
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    63
  end;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    64
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    65
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    66
(** parsers **)
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    67
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    68
val not_eof = ML_Lex.stopper |> Scan.is_stopper #> not;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    69
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    70
val scan_space = Scan.many Symbol.is_blank;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    71
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    72
fun scan_cmt scan =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    73
  Scan.one (ML_Lex.kind_of #> equal ML_Lex.Comment) >>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    74
  (ML_Lex.content_of #> Symbol.explode #> Scan.finite Symbol.stopper scan #> fst);
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    75
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    76
val scan_chunks = Scan.depend (fn (open_chunks, thy) =>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    77
  scan_cmt ((Scan.this_string "(*" -- scan_space -- Scan.this_string "@chunk" --
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    78
    scan_space) |-- Symbol.scan_id --|
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    79
    (scan_space -- Scan.this_string "*)") >> (fn name =>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    80
      let val (name', thy') = declare_chunk name thy
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    81
      in ((name' :: open_chunks, thy'), "") end))
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    82
  ||
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    83
  scan_cmt (Scan.this_string "(*" -- scan_space -- Scan.this_string "@end" --
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    84
    scan_space -- Scan.this_string "*)" >> (fn _ =>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    85
      (case open_chunks of
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    86
         [] => error "end without matching chunk encountered"
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    87
       | _ :: open_chunks' => ((open_chunks', thy), ""))))
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    88
  ||
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    89
  Scan.one not_eof >> (fn tok =>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    90
    ((open_chunks, fold (augment_chunk tok) open_chunks thy), ML_Lex.content_of tok)));
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    91
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    92
fun chunks_of s thy =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    93
  let val toks = Source.exhaust (ML_Lex.source (Source.of_string s))
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    94
  in case Scan.finite' ML_Lex.stopper (Scan.repeat (Scan.error scan_chunks))
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    95
        (([], thy), toks) of
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    96
      (toks', (([], thy'), _)) => (implode toks', thy')
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    97
    | (_, ((open_chunks, _), _)) =>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    98
        error ("Open chunks at end of text: " ^ commas_quote open_chunks)
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
    99
  end;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   100
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   101
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   102
(** use command **)
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   103
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   104
fun load_ml dir raw_path thy =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   105
  (case ThyLoad.check_ml dir raw_path of
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   106
    NONE => error ("Could not find ML file " ^ quote (Path.implode raw_path))
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   107
  | SOME (path, _) =>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   108
      let val (s, thy') = chunks_of (File.read path) thy
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   109
      in
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   110
        Context.theory_map (ThyInfo.exec_file false raw_path) thy'
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   111
      end);
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   112
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   113
fun use_chunks path thy =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   114
  load_ml (ThyInfo.master_directory (Context.theory_name thy)) path thy;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   115
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   116
val _ =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   117
  OuterSyntax.command "use_chunks" "eval ML text from file"
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   118
    (OuterKeyword.tag_ml OuterKeyword.thy_decl)
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   119
    (OuterParse.path >> (Toplevel.theory o use_chunks));
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   120
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   121
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   122
(** antiquotation **)
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   123
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   124
val str_of_source = space_implode " " o map OuterLex.unparse o #2 o #1 o Args.dest_src;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   125
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   126
val verbatim = space_implode "\\verb,|," o map (enclose "\\verb|" "|") o space_explode "|";
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   127
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   128
val transform_cmts =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   129
  Scan.finite ML_Lex.stopper (Scan.repeat
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   130
    (   scan_cmt
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   131
          (Scan.this_string "(*{" |--
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   132
           Scan.repeat (Scan.unless (Scan.this_string "}*)")
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   133
             (Scan.one (not o Symbol.is_eof))) --|
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   134
           Scan.this_string "}*)" >>
57
065f472c09ab Repaired output of marginal comments in ML antiquotation.
berghofe
parents: 55
diff changeset
   135
           (Symbol.encode_raw o enclose "\\hfill\\textrm{\\textit{" "}}" o implode))
24
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   136
     || Scan.one not_eof >> ML_Lex.content_of)) #>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   137
  fst;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   138
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   139
fun output_chunk src ctxt name =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   140
  let
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   141
    val toks = the_chunk (ProofContext.theory_of ctxt) name;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   142
    val (spc, toks') = (case toks of
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   143
        [] => ("", [])
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   144
      | [tok] => ("", [tok])
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   145
      | tok :: toks' =>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   146
          let
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   147
            val (toks'', tok') = split_last toks'
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   148
            val toks''' =
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   149
              if ML_Lex.kind_of tok' = ML_Lex.Space then toks''
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   150
              else toks'
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   151
          in
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   152
            if ML_Lex.kind_of tok = ML_Lex.Space then
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   153
              (tok |> ML_Lex.content_of |> Symbol.explode |>
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   154
               take_suffix (equal " ") |> snd |> implode,
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   155
               toks''')
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   156
            else ("", tok :: toks''')
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   157
          end)
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   158
    val txt = spc ^ implode (transform_cmts toks')
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   159
  in
57
065f472c09ab Repaired output of marginal comments in ML antiquotation.
berghofe
parents: 55
diff changeset
   160
    txt |> split_lines |>
90
b071a0b88298 made chunks aware of the gray-option
Christian Urban <urbanc@in.tum.de>
parents: 57
diff changeset
   161
    output_list (fn _ => fn s => Pretty.str s) src ctxt
24
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   162
  end;
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   163
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   164
val _ = ThyOutput.add_commands
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   165
  [("ML_chunk", ThyOutput.args (Scan.lift Args.name) output_chunk)];
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   166
9d5d2f9d7c09 Antiquotation for referring to chunks of ML code.
berghofe
parents:
diff changeset
   167
end;