src/Pure/System/options.scala
changeset 48421 c4d337782de4
parent 48411 5b3440850d36
child 48456 d8ff14f44a40
equal deleted inserted replaced
48420:a8ed41b6280b 48421:c4d337782de4
    10 import java.io.{File => JFile}
    10 import java.io.{File => JFile}
    11 
    11 
    12 
    12 
    13 object Options
    13 object Options
    14 {
    14 {
    15   abstract class Type
    15   type Spec = (String, Option[String])
       
    16 
       
    17   val empty: Options = new Options()
       
    18 
       
    19 
       
    20   /* representation */
       
    21 
       
    22   sealed abstract class Type
    16   {
    23   {
    17     def print: String = toString.toLowerCase
    24     def print: String = toString.toLowerCase
    18   }
    25   }
    19   case object Bool extends Type
    26   private case object Bool extends Type
    20   case object Int extends Type
    27   private case object Int extends Type
    21   case object Real extends Type
    28   private case object Real extends Type
    22   case object String extends Type
    29   private case object String extends Type
    23 
    30 
    24   case class Opt(typ: Type, value: String, description: String)
    31   case class Opt(typ: Type, value: String, description: String)
    25 
       
    26   val empty: Options = new Options()
       
    27 
    32 
    28 
    33 
    29   /* parsing */
    34   /* parsing */
    30 
    35 
    31   private object Parser extends Parse.Parser
    36   private object Parser extends Parse.Parser
    56         case bad => error(bad.toString)
    61         case bad => error(bad.toString)
    57       }
    62       }
    58     }
    63     }
    59   }
    64   }
    60 
    65 
    61   val OPTIONS = Path.explode("etc/options")
    66   private val OPTIONS = Path.explode("etc/options")
    62 
    67 
    63   def init(): Options =
    68   def init(): Options =
    64   {
    69   {
    65     var options = empty
    70     var options = empty
    66     for {
    71     for {
   192       case None if opt.typ == Options.Bool => define(name, "true")
   197       case None if opt.typ == Options.Bool => define(name, "true")
   193       case None => error("Missing value for option " + quote(name) + " : " + opt.typ.print)
   198       case None => error("Missing value for option " + quote(name) + " : " + opt.typ.print)
   194     }
   199     }
   195   }
   200   }
   196 
   201 
       
   202   def ++ (specs: List[Options.Spec]): Options =
       
   203     (this /: specs)({ case (x, (y, z)) => x.define(y, z) })
       
   204 
   197   def define_simple(str: String): Options =
   205   def define_simple(str: String): Options =
   198   {
   206   {
   199     str.indexOf('=') match {
   207     str.indexOf('=') match {
   200       case -1 => define(str, None)
   208       case -1 => define(str, None)
   201       case i => define(str.substring(0, i), str.substring(i + 1))
   209       case i => define(str.substring(0, i), str.substring(i + 1))