src/Pure/System/options.ML
author wenzelm
Wed, 25 Mar 2015 14:39:40 +0100
changeset 59812 675d0c692c41
parent 56467 8d7d6f17c6a7
child 62712 22a17cec2efe
permissions -rw-r--r--
semantic completion for @{system_option};
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/System/options.ML
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
     3
51945
5b1ac9843f02 tuned comments;
wenzelm
parents: 51943
diff changeset
     4
System options with external string representation.
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
     5
*)
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
     6
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
     7
signature OPTIONS =
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
     8
sig
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
     9
  val boolT: string
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    10
  val intT: string
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    11
  val realT: string
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    12
  val stringT: string
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    13
  val unknownT: string
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    14
  type T
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    15
  val empty: T
59812
675d0c692c41 semantic completion for @{system_option};
wenzelm
parents: 56467
diff changeset
    16
  val names: T -> string list
56467
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    17
  val markup: T -> string * Position.T -> Markup.T
51942
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
    18
  val typ: T -> string -> string
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    19
  val bool: T -> string -> bool
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    20
  val int: T -> string -> int
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    21
  val real: T -> string -> real
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    22
  val string: T -> string -> string
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    23
  val put_bool: string -> bool -> T -> T
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    24
  val put_int: string -> int -> T -> T
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    25
  val put_real: string -> real -> T -> T
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    26
  val put_string: string -> string -> T -> T
56465
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
    27
  val declare: {pos: Position.T, name: string, typ: string, value: string} -> T -> T
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    28
  val update: string -> string -> T -> T
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    29
  val decode: XML.body -> T
48698
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
    30
  val default: unit -> T
56467
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    31
  val default_markup: string * Position.T -> Markup.T
51946
449fbf64f4a5 tuned signature;
wenzelm
parents: 51945
diff changeset
    32
  val default_typ: string -> string
51942
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
    33
  val default_bool: string -> bool
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
    34
  val default_int: string -> int
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
    35
  val default_real: string -> real
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
    36
  val default_string: string -> string
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    37
  val default_put_bool: string -> bool -> unit
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    38
  val default_put_int: string -> int -> unit
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    39
  val default_put_real: string -> real -> unit
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    40
  val default_put_string: string -> string -> unit
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    41
  val get_default: string -> string
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    42
  val put_default: string -> string -> unit
48698
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
    43
  val set_default: T -> unit
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
    44
  val reset_default: unit -> unit
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
    45
  val load_default: unit -> unit
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    46
end;
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    47
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    48
structure Options: OPTIONS =
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    49
struct
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    50
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    51
(* representation *)
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    52
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    53
val boolT = "bool";
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    54
val intT = "int";
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    55
val realT = "real";
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    56
val stringT = "string";
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    57
val unknownT = "unknown";
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    58
56465
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
    59
datatype T = Options of {pos: Position.T, typ: string, value: string} Symtab.table;
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    60
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    61
val empty = Options Symtab.empty;
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    62
59812
675d0c692c41 semantic completion for @{system_option};
wenzelm
parents: 56467
diff changeset
    63
fun names (Options tab) = sort_strings (Symtab.keys tab);
675d0c692c41 semantic completion for @{system_option};
wenzelm
parents: 56467
diff changeset
    64
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
    65
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    66
(* check *)
51942
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
    67
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    68
fun check_name (Options tab) name =
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    69
  let val opt = Symtab.lookup tab name in
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    70
    if is_some opt andalso #typ (the opt) <> unknownT then the opt
51978
237ee582d663 tuned messages;
wenzelm
parents: 51951
diff changeset
    71
    else error ("Unknown system option " ^ quote name)
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    72
  end;
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    73
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    74
fun check_type options name typ =
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    75
  let val opt = check_name options name in
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    76
    if #typ opt = typ then opt
51978
237ee582d663 tuned messages;
wenzelm
parents: 51951
diff changeset
    77
    else error ("Ill-typed system option " ^ quote name ^ " : " ^ #typ opt ^ " vs. " ^ typ)
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    78
  end;
51942
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
    79
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
    80
56467
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    81
(* markup *)
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    82
56467
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    83
fun markup options (name, pos) =
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    84
  let
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    85
    val opt =
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    86
      check_name options name
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    87
        handle ERROR msg => error (msg ^ Position.here pos);
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    88
    val props = Position.def_properties_of (#pos opt);
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    89
  in Markup.properties props (Markup.entity Markup.system_optionN name) end;
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    90
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    91
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    92
(* typ *)
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
    93
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    94
fun typ options name = #typ (check_name options name);
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    95
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    96
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    97
(* basic operations *)
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    98
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
    99
fun put T print name x (options as Options tab) =
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   100
  let val opt = check_type options name T
56465
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   101
  in Options (Symtab.update (name, {pos = #pos opt, typ = #typ opt, value = print x}) tab) end;
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   102
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   103
fun get T parse options name =
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   104
  let val opt = check_type options name T in
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   105
    (case parse (#value opt) of
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   106
      SOME x => x
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   107
    | NONE =>
51978
237ee582d663 tuned messages;
wenzelm
parents: 51951
diff changeset
   108
        error ("Malformed value for system option " ^ quote name ^
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   109
          " : " ^ T ^ " =\n" ^ quote (#value opt)))
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   110
  end;
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   111
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   112
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   113
(* internal lookup and update *)
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   114
51951
fab4ab92e812 more standard Isabelle/ML operations -- avoid inaccurate Bool.fromString;
wenzelm
parents: 51946
diff changeset
   115
val bool = get boolT (try Markup.parse_bool);
fab4ab92e812 more standard Isabelle/ML operations -- avoid inaccurate Bool.fromString;
wenzelm
parents: 51946
diff changeset
   116
val int = get intT (try Markup.parse_int);
51988
a9725750c53a more uniform Markup.parse_real;
wenzelm
parents: 51978
diff changeset
   117
val real = get realT (try Markup.parse_real);
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   118
val string = get stringT SOME;
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   119
51951
fab4ab92e812 more standard Isabelle/ML operations -- avoid inaccurate Bool.fromString;
wenzelm
parents: 51946
diff changeset
   120
val put_bool = put boolT Markup.print_bool;
fab4ab92e812 more standard Isabelle/ML operations -- avoid inaccurate Bool.fromString;
wenzelm
parents: 51946
diff changeset
   121
val put_int = put intT Markup.print_int;
51990
cc66addbba6d more uniform Markup.print_real;
wenzelm
parents: 51988
diff changeset
   122
val put_real = put realT Markup.print_real;
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   123
val put_string = put stringT I;
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   124
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   125
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   126
(* external updates *)
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   127
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   128
fun check_value options name =
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   129
  let val opt = check_name options name in
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   130
    if #typ opt = boolT then ignore (bool options name)
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   131
    else if #typ opt = intT then ignore (int options name)
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   132
    else if #typ opt = realT then ignore (real options name)
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   133
    else if #typ opt = stringT then ignore (string options name)
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   134
    else ()
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   135
  end;
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   136
56465
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   137
fun declare {pos, name, typ, value} (Options tab) =
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   138
  let
56465
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   139
    val options' =
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   140
      (case Symtab.lookup tab name of
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   141
        SOME other =>
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   142
          error ("Duplicate declaration of system option " ^ quote name ^ Position.here pos ^
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   143
            Position.here (#pos other))
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   144
      | NONE => Options (Symtab.update (name, {pos = pos, typ = typ, value = value}) tab));
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   145
    val _ =
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   146
      typ = boolT orelse typ = intT orelse typ = realT orelse typ = stringT orelse
56465
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   147
        error ("Unknown type for system option " ^ quote name ^ " : " ^ quote typ ^
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   148
          Position.here pos);
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   149
    val _ = check_value options' name;
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   150
  in options' end;
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   151
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   152
fun update name value (options as Options tab) =
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   153
  let
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   154
    val opt = check_name options name;
56465
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   155
    val options' =
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   156
      Options (Symtab.update (name, {pos = #pos opt, typ = #typ opt, value = value}) tab);
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   157
    val _ = check_value options' name;
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   158
  in options' end;
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   159
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   160
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   161
(* decode *)
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   162
56465
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   163
fun decode_opt body =
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   164
  let open XML.Decode
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   165
  in list (pair properties (pair string (pair string string))) end body
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   166
  |> map (fn (props, (name, (typ, value))) =>
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   167
      {pos = Position.of_properties props, name = name, typ = typ, value = value});
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   168
6ad693903e22 more positions and markup;
wenzelm
parents: 51990
diff changeset
   169
fun decode body = fold declare (decode_opt body) empty;
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   170
48698
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   171
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   172
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   173
(** global default **)
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   174
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   175
val global_default = Synchronized.var "Options.default" (NONE: T option);
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   176
51978
237ee582d663 tuned messages;
wenzelm
parents: 51951
diff changeset
   177
fun err_no_default () = error "Missing default for system options within Isabelle process";
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   178
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   179
fun change_default f x y =
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   180
  Synchronized.change global_default
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   181
    (fn SOME options => SOME (f x y options)
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   182
      | NONE => err_no_default ());
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   183
48698
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   184
fun default () =
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   185
  (case Synchronized.value global_default of
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   186
    SOME options => options
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   187
  | NONE => err_no_default ());
48698
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   188
56467
8d7d6f17c6a7 more uniform ML/document antiquotations;
wenzelm
parents: 56465
diff changeset
   189
fun default_markup arg = markup (default ()) arg;
51946
449fbf64f4a5 tuned signature;
wenzelm
parents: 51945
diff changeset
   190
fun default_typ name = typ (default ()) name;
51942
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
   191
fun default_bool name = bool (default ()) name;
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
   192
fun default_int name = int (default ()) name;
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
   193
fun default_real name = real (default ()) name;
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
   194
fun default_string name = string (default ()) name;
527e39becafc more systematic access to options default;
wenzelm
parents: 48698
diff changeset
   195
51943
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   196
val default_put_bool = change_default put_bool;
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   197
val default_put_int = change_default put_int;
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   198
val default_put_real = change_default put_real;
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   199
val default_put_string = change_default put_string;
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   200
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   201
fun get_default name =
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   202
  let val options = default () in get (typ options name) SOME options name end;
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   203
val put_default = change_default update;
3278729bfa38 more operations in accordance to Scala version;
wenzelm
parents: 51942
diff changeset
   204
48698
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   205
fun set_default options = Synchronized.change global_default (K (SOME options));
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   206
fun reset_default () = Synchronized.change global_default (K NONE);
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   207
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   208
fun load_default () =
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   209
  (case getenv "ISABELLE_PROCESS_OPTIONS" of
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   210
    "" => ()
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   211
  | name =>
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   212
      let val path = Path.explode name in
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   213
        (case try File.read path of
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   214
          SOME s => (set_default (decode (YXML.parse_body s)); ignore (try File.rm path))
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   215
        | NONE => ())
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   216
      end);
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   217
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   218
val _ = load_default ();
2585042b1a30 pass Isabelle/Scala system options into ML process of Isar tty or build jobs;
wenzelm
parents: 48456
diff changeset
   219
48456
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   220
end;
d8ff14f44a40 added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
diff changeset
   221