src/Pure/System/options.scala
changeset 48795 bece259ee055
parent 48718 73e6c22e2d94
child 48807 fde8c3d84ff5
equal deleted inserted replaced
48794:8d2a026e576b 48795:bece259ee055
    28   case class Opt(typ: Type, value: String, description: String)
    28   case class Opt(typ: Type, value: String, description: String)
    29 
    29 
    30 
    30 
    31   /* parsing */
    31   /* parsing */
    32 
    32 
    33   private val DECLARE = "declare"
    33   private val OPTION = "option"
    34   private val DEFINE = "define"
       
    35 
    34 
    36   lazy val options_syntax =
    35   lazy val options_syntax =
    37     Outer_Syntax.init() + ":" + "=" + "--" +
    36     Outer_Syntax.init() + ":" + "=" + "--" + (OPTION, Keyword.THY_DECL)
    38       (DECLARE, Keyword.THY_DECL) + (DEFINE, Keyword.PRF_DECL)
       
    39 
    37 
    40   private object Parser extends Parse.Parser
    38   private object Parser extends Parse.Parser
    41   {
    39   {
    42     val entry: Parser[Options => Options] =
    40     val entry: Parser[Options => Options] =
    43     {
    41     {
    47       val option_value =
    45       val option_value =
    48         opt(token("-", tok => tok.is_sym_ident && tok.content == "-")) ~ atom("nat", _.is_nat) ^^
    46         opt(token("-", tok => tok.is_sym_ident && tok.content == "-")) ~ atom("nat", _.is_nat) ^^
    49           { case s ~ n => if (s.isDefined) "-" + n else n } |
    47           { case s ~ n => if (s.isDefined) "-" + n else n } |
    50         atom("option value", tok => tok.is_name || tok.is_float)
    48         atom("option value", tok => tok.is_name || tok.is_float)
    51 
    49 
    52       command(DECLARE) ~! (option_name ~ keyword(":") ~ option_type ~
    50       command(OPTION) ~! (option_name ~ keyword(":") ~ option_type ~
    53       keyword("=") ~ option_value ~ (keyword("--") ~! text ^^ { case _ ~ x => x } | success(""))) ^^
    51       keyword("=") ~ option_value ~ (keyword("--") ~! text ^^ { case _ ~ x => x } | success(""))) ^^
    54         { case _ ~ (a ~ _ ~ b ~ _ ~ c ~ d) => (options: Options) => options.declare(a, b, c, d) } |
    52         { case _ ~ (a ~ _ ~ b ~ _ ~ c ~ d) => (options: Options) => options.declare(a, b, c, d) }
    55       command(DEFINE) ~! (option_name ~ keyword("=") ~ option_value) ^^
       
    56         { case _ ~ (a ~ _ ~ b) => (options: Options) => options.define(a, b) }
       
    57     }
    53     }
    58 
    54 
    59     def parse_entries(file: Path): List[Options => Options] =
    55     def parse_entries(file: Path): List[Options => Options] =
    60     {
    56     {
    61       val toks = options_syntax.scan(File.read(file))
    57       val toks = options_syntax.scan(File.read(file))
   112 {
   108 {
   113   override def toString: String = options.iterator.mkString("Options (", ",", ")")
   109   override def toString: String = options.iterator.mkString("Options (", ",", ")")
   114 
   110 
   115   def print: String =
   111   def print: String =
   116     cat_lines(options.toList.sortBy(_._1).map({ case (name, opt) =>
   112     cat_lines(options.toList.sortBy(_._1).map({ case (name, opt) =>
   117       name + " : " + opt.typ.print + " = " +
   113       "option " + name + " : " + opt.typ.print + " = " +
   118         (if (opt.typ == Options.String) quote(opt.value) else opt.value) +
   114         (if (opt.typ == Options.String) quote(opt.value) else opt.value) +
   119       "\n  -- " + quote(opt.description) }))
   115       "\n  -- " + quote(opt.description) }))
   120 
   116 
   121 
   117 
   122   /* check */
   118   /* check */