src/Pure/System/options.scala
author wenzelm
Fri, 20 Jul 2012 17:43:55 +0200
changeset 48369 10b534e64209
parent 48368 dc538eef2cf2
child 48370 d0fa3efec93b
permissions -rw-r--r--
tuned signature;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
48365
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
     1
/*  Title:      Pure/System/options.scala
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
     3
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
     4
Stand-alone options with external string representation.
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
     5
*/
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
     6
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
     7
package isabelle
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
     8
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
     9
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    10
import java.io.File
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    11
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    12
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    13
object Options
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    14
{
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    15
  abstract class Type
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    16
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    17
    def print: String = toString.toLowerCase
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    18
    def init: String
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    19
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    20
  case object Bool extends Type { def init = "false" }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    21
  case object Int extends Type { def init = "0" }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    22
  case object Real extends Type { def init = "0.0" }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    23
  case object String extends Type { def init = "" }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    24
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    25
  case class Opt(typ: Type, description: String, value: String)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    26
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    27
  val empty: Options = new Options()
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    28
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    29
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    30
  /* parsing */
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    31
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    32
  private object Parser extends Parse.Parser
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    33
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    34
    val DECLARE = "declare"
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    35
    val DEFINE = "define"
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    36
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    37
    val syntax = Outer_Syntax.empty + ":" + "=" + DECLARE + DEFINE
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    38
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    39
    val entry: Parser[Options => Options] =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    40
    {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    41
      val option_name = atom("option name", _.is_xname)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    42
      val option_type = atom("option type", _.is_ident)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    43
      val option_value = atom("option value", tok => tok.is_name || tok.is_float)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    44
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    45
      keyword(DECLARE) ~! (option_name ~ keyword(":") ~ option_type ~ opt(text)) ^^
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    46
        { case _ ~ (x ~ _ ~ y ~ z) => (options: Options) =>
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    47
            options.declare(x, y, z.getOrElse("")) } |
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    48
      keyword(DEFINE) ~! (option_name ~ keyword("=") ~ option_value) ^^
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    49
        { case _ ~ (x ~ _ ~ y) => (options: Options) =>
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    50
            options.define(x, y) }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    51
    }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    52
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    53
    def parse_entries(file: File): List[Options => Options] =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    54
    {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    55
      val toks = syntax.scan(Standard_System.read_file(file))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    56
      parse_all(rep(entry), Token.reader(toks, file.toString)) match {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    57
        case Success(result, _) => result
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    58
        case bad => error(bad.toString)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    59
      }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    60
    }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    61
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    62
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    63
  val OPTIONS = Path.explode("etc/options")
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    64
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    65
  def init(): Options =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    66
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    67
    var options = empty
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    68
    for {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    69
      dir <- Isabelle_System.components()
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    70
      file = Isabelle_System.platform_file(dir + OPTIONS)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    71
      if file.isFile
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    72
      entry <- Parser.parse_entries(file)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    73
    } {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    74
      try { options = entry(options) }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    75
      catch { case ERROR(msg) => error(msg + " (file " + quote(file.toString) + ")") }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    76
    }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    77
    options
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    78
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    79
}
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    80
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    81
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    82
final class Options private(options: Map[String, Options.Opt] = Map.empty)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    83
{
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    84
  override def toString: String = options.iterator.mkString("Options (", ",", ")")
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    85
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    86
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    87
  /* basic operations */
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    88
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    89
  private def check_name(name: String): Options.Opt =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    90
    options.get(name) match {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    91
      case Some(opt) => opt
48368
dc538eef2cf2 define build_options from command line;
wenzelm
parents: 48365
diff changeset
    92
      case None => error("Unknown option " + quote(name))
48365
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    93
    }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    94
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    95
  private def check_type(name: String, typ: Options.Type): Options.Opt =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    96
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    97
    val opt = check_name(name)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    98
    if (opt.typ == typ) opt
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
    99
    else error("Ill-typed option " + quote(name) + " : " + opt.typ.print + " vs. " + typ.print)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   100
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   101
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   102
  private def get[A](name: String, typ: Options.Type, parse: String => Option[A]): A =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   103
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   104
    val opt = check_type(name, typ)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   105
    parse(opt.value) match {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   106
      case Some(x) => x
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   107
      case None =>
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   108
        error("Malformed value for option " + quote(name) +
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   109
          " : " + typ.print + " =\n" + quote(opt.value))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   110
    }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   111
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   112
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   113
  private def put[A](name: String, typ: Options.Type, value: String): Options =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   114
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   115
    val opt = check_type(name, typ)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   116
    new Options(options + (name -> opt.copy(value = value)))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   117
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   118
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   119
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   120
  /* external declare and define */
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   121
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   122
  def declare(name: String, typ_name: String, description: String = ""): Options =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   123
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   124
    options.get(name) match {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   125
      case Some(_) => error("Duplicate declaration of option " + quote(name))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   126
      case None =>
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   127
        val typ =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   128
          typ_name match {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   129
            case "bool" => Options.Bool
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   130
            case "int" => Options.Int
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   131
            case "real" => Options.Real
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   132
            case "string" => Options.String
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   133
            case _ => error("Malformed type for option " + quote(name) + " : " + quote(typ_name))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   134
          }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   135
        new Options(options + (name -> Options.Opt(typ, description, typ.init)))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   136
    }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   137
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   138
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   139
  def define(name: String, value: String): Options =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   140
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   141
    val opt = check_name(name)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   142
    val result = new Options(options + (name -> opt.copy(value = value)))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   143
    opt.typ match {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   144
      case Options.Bool => result.bool(name); ()
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   145
      case Options.Int => result.int(name); ()
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   146
      case Options.Real => result.real(name); ()
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   147
      case Options.String => result.string(name); ()
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   148
    }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   149
    result
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   150
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   151
48369
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   152
  def define(name: String, opt_value: Option[String]): Options =
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   153
  {
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   154
    val opt = check_name(name)
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   155
    opt_value match {
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   156
      case Some(value) => define(name, value)
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   157
      case None if opt.typ == Options.Bool => define(name, "true")
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   158
      case None => error("Missing value for option " + quote(name) + " : " + opt.typ.print)
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   159
    }
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   160
  }
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   161
48368
dc538eef2cf2 define build_options from command line;
wenzelm
parents: 48365
diff changeset
   162
  def define_simple(str: String): Options =
dc538eef2cf2 define build_options from command line;
wenzelm
parents: 48365
diff changeset
   163
  {
dc538eef2cf2 define build_options from command line;
wenzelm
parents: 48365
diff changeset
   164
    str.indexOf('=') match {
48369
10b534e64209 tuned signature;
wenzelm
parents: 48368
diff changeset
   165
      case -1 => define(str, None)
48368
dc538eef2cf2 define build_options from command line;
wenzelm
parents: 48365
diff changeset
   166
      case i => define(str.substring(0, i), str.substring(i + 1))
dc538eef2cf2 define build_options from command line;
wenzelm
parents: 48365
diff changeset
   167
    }
dc538eef2cf2 define build_options from command line;
wenzelm
parents: 48365
diff changeset
   168
  }
dc538eef2cf2 define build_options from command line;
wenzelm
parents: 48365
diff changeset
   169
48365
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   170
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   171
  /* internal lookup and update */
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   172
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   173
  val bool = new Object
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   174
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   175
    def apply(name: String): Boolean = get(name, Options.Bool, Properties.Value.Boolean.unapply)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   176
    def update(name: String, x: Boolean): Options =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   177
      put(name, Options.Bool, Properties.Value.Boolean(x))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   178
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   179
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   180
  val int = new Object
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   181
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   182
    def apply(name: String): Int = get(name, Options.Int, Properties.Value.Int.unapply)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   183
    def update(name: String, x: Int): Options =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   184
      put(name, Options.Int, Properties.Value.Int(x))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   185
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   186
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   187
  val real = new Object
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   188
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   189
    def apply(name: String): Double = get(name, Options.Real, Properties.Value.Double.unapply)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   190
    def update(name: String, x: Double): Options =
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   191
      put(name, Options.Real, Properties.Value.Double(x))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   192
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   193
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   194
  val string = new Object
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   195
  {
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   196
    def apply(name: String): String = get(name, Options.String, s => Some(s))
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   197
    def update(name: String, x: String): Options = put(name, Options.String, x)
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   198
  }
d88aefda01c4 basic support for stand-alone options with external string representation;
wenzelm
parents:
diff changeset
   199
}