src/Pure/General/print_mode.ML
author wenzelm
Tue, 29 Dec 2015 14:58:15 +0100
changeset 61957 301833d9013a
parent 39124 9bac2f4cfd6e
child 62542 b27b7c2200b9
permissions -rw-r--r--
former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII"; uniform syntax for Pure.imp; removed obsolete "HTML" syntax;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/General/print_mode.ML
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     3
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
     4
Generic print mode as thread-local value derived from global template;
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
     5
provides implicit configuration for various output mechanisms.
39124
9bac2f4cfd6e tuned comment;
wenzelm
parents: 37146
diff changeset
     6
9bac2f4cfd6e tuned comment;
wenzelm
parents: 37146
diff changeset
     7
The special print mode "input" is never enabled for output.
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     8
*)
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
     9
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    10
signature BASIC_PRINT_MODE =
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    11
sig
32738
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 29606
diff changeset
    12
  val print_mode: string list Unsynchronized.ref  (*global template*)
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 29606
diff changeset
    13
  val print_mode_value: unit -> string list       (*thread-local value*)
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 29606
diff changeset
    14
  val print_mode_active: string -> bool           (*thread-local value*)
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    15
end;
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    16
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    17
signature PRINT_MODE =
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    18
sig
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    19
  include BASIC_PRINT_MODE
25118
158149a6e95b added input/internal, which are never active in print_mode_value;
wenzelm
parents: 24634
diff changeset
    20
  val input: string
61957
301833d9013a former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 39124
diff changeset
    21
  val ASCII: string
25118
158149a6e95b added input/internal, which are never active in print_mode_value;
wenzelm
parents: 24634
diff changeset
    22
  val internal: string
24634
38db11874724 simplified PrintMode interfaces;
wenzelm
parents: 24613
diff changeset
    23
  val setmp: string list -> ('a -> 'b) -> 'a -> 'b
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    24
  val with_modes: string list -> ('a -> 'b) -> 'a -> 'b
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    25
  val closure: ('a -> 'b) -> 'a -> 'b
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    26
end;
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    27
37146
f652333bbf8e renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
wenzelm
parents: 33223
diff changeset
    28
structure Print_Mode: PRINT_MODE =
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    29
struct
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    30
25118
158149a6e95b added input/internal, which are never active in print_mode_value;
wenzelm
parents: 24634
diff changeset
    31
val input = "input";
61957
301833d9013a former "xsymbols" syntax is used by default, and ASCII replacement syntax with print mode "ASCII";
wenzelm
parents: 39124
diff changeset
    32
val ASCII = "ASCII";
25118
158149a6e95b added input/internal, which are never active in print_mode_value;
wenzelm
parents: 24634
diff changeset
    33
val internal = "internal";
24613
bc889c3d55a3 added print_mode_value (CRITICAL);
wenzelm
parents: 24603
diff changeset
    34
32738
15bb09ca0378 explicit indication of Unsynchronized.ref;
wenzelm
parents: 29606
diff changeset
    35
val print_mode = Unsynchronized.ref ([]: string list);
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    36
val tag = Universal.tag () : string list option Universal.tag;
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    37
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    38
fun print_mode_value () =
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    39
  let val modes =
28122
3d099ce624e7 Thread.getLocal/setLocal;
wenzelm
parents: 25798
diff changeset
    40
    (case Thread.getLocal tag of
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    41
      SOME (SOME modes) => modes
33223
d27956b4d3b4 non-critical atomic accesses;
wenzelm
parents: 32738
diff changeset
    42
    | _ => ! print_mode)
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    43
  in subtract (op =) [input, internal] modes end;
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    44
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    45
fun print_mode_active mode = member (op =) (print_mode_value ()) mode;
25118
158149a6e95b added input/internal, which are never active in print_mode_value;
wenzelm
parents: 24634
diff changeset
    46
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    47
fun setmp modes f x =
28122
3d099ce624e7 Thread.getLocal/setLocal;
wenzelm
parents: 25798
diff changeset
    48
  let val orig_modes = (case Thread.getLocal tag of SOME (SOME ms) => SOME ms | _ => NONE)
25798
1e6eafbb466f setmp_thread_data;
wenzelm
parents: 25734
diff changeset
    49
  in setmp_thread_data tag orig_modes (SOME modes) f x end;
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    50
25734
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    51
fun with_modes modes f x = setmp (modes @ print_mode_value ()) f x;
b00b903ae8ae separated into global template vs. thread-local value;
wenzelm
parents: 25118
diff changeset
    52
fun closure f = with_modes [] f;
23934
79393cb9c0a6 added with_modes, with_default;
wenzelm
parents: 23827
diff changeset
    53
23827
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    54
end;
0f0d1cf4992d Generic print mode.
wenzelm
parents:
diff changeset
    55
37146
f652333bbf8e renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
wenzelm
parents: 33223
diff changeset
    56
structure Basic_Print_Mode: BASIC_PRINT_MODE = Print_Mode;
f652333bbf8e renamed structure PrintMode to Print_Mode, keeping the old name as legacy alias for some time;
wenzelm
parents: 33223
diff changeset
    57
open Basic_Print_Mode;