author | wenzelm |
Tue, 14 Aug 2012 20:50:50 +0200 | |
changeset 48807 | fde8c3d84ff5 |
parent 48795 | bece259ee055 |
child 48860 | 56ec76f769c0 |
permissions | -rw-r--r-- |
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 |
|
48807 | 10 |
import java.util.Calendar |
11 |
||
12 |
||
48365
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 |
{ |
48421 | 15 |
type Spec = (String, Option[String]) |
16 |
||
17 |
val empty: Options = new Options() |
|
18 |
||
19 |
||
20 |
/* representation */ |
|
21 |
||
22 |
sealed abstract class Type |
|
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
23 |
{ |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
24 |
def print: String = toString.toLowerCase |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
25 |
} |
48421 | 26 |
private case object Bool extends Type |
27 |
private case object Int extends Type |
|
28 |
private case object Real extends Type |
|
29 |
private case object String extends Type |
|
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
30 |
|
48370 | 31 |
case class Opt(typ: Type, value: String, description: String) |
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
32 |
|
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 |
/* parsing */ |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
35 |
|
48795
bece259ee055
clarified format of etc/options: only declarations, not re-definitions;
wenzelm
parents:
48718
diff
changeset
|
36 |
private val OPTION = "option" |
48807 | 37 |
private val OPTIONS = Path.explode("etc/options") |
38 |
private val PREFS = Path.explode("$ISABELLE_HOME_USER/etc/preferences") |
|
39 |
private val PREFS_BACKUP = Path.explode("$ISABELLE_HOME_USER/etc/preferences~") |
|
48713
de26cf3191a3
more token markers, based on actual outer syntax;
wenzelm
parents:
48693
diff
changeset
|
40 |
|
48807 | 41 |
lazy val options_syntax = Outer_Syntax.init() + ":" + "=" + "--" + (OPTION, Keyword.THY_DECL) |
42 |
lazy val prefs_syntax = Outer_Syntax.init() + "=" |
|
48713
de26cf3191a3
more token markers, based on actual outer syntax;
wenzelm
parents:
48693
diff
changeset
|
43 |
|
48807 | 44 |
object Parser extends Parse.Parser |
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
45 |
{ |
48807 | 46 |
val option_name = atom("option name", _.is_xname) |
47 |
val option_type = atom("option type", _.is_ident) |
|
48 |
val option_value = |
|
49 |
opt(token("-", tok => tok.is_sym_ident && tok.content == "-")) ~ atom("nat", _.is_nat) ^^ |
|
50 |
{ case s ~ n => if (s.isDefined) "-" + n else n } | |
|
51 |
atom("option value", tok => tok.is_name || tok.is_float) |
|
52 |
||
53 |
val option_entry: Parser[Options => Options] = |
|
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
54 |
{ |
48795
bece259ee055
clarified format of etc/options: only declarations, not re-definitions;
wenzelm
parents:
48718
diff
changeset
|
55 |
command(OPTION) ~! (option_name ~ keyword(":") ~ option_type ~ |
48580 | 56 |
keyword("=") ~ option_value ~ (keyword("--") ~! text ^^ { case _ ~ x => x } | success(""))) ^^ |
48795
bece259ee055
clarified format of etc/options: only declarations, not re-definitions;
wenzelm
parents:
48718
diff
changeset
|
57 |
{ case _ ~ (a ~ _ ~ b ~ _ ~ c ~ d) => (options: Options) => options.declare(a, b, c, d) } |
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
58 |
} |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
59 |
|
48807 | 60 |
val prefs_entry: Parser[Options => Options] = |
61 |
{ |
|
62 |
option_name ~ (keyword("=") ~! option_value) ^^ |
|
63 |
{ case a ~ (_ ~ b) => (options: Options) => options + (a, b) } |
|
64 |
} |
|
65 |
||
66 |
def parse_file(syntax: Outer_Syntax, parser: Parser[Options => Options], |
|
67 |
options: Options, file: Path): Options = |
|
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
68 |
{ |
48807 | 69 |
val toks = syntax.scan(File.read(file)) |
70 |
val ops = |
|
71 |
parse_all(rep(parser), Token.reader(toks, file.implode)) match { |
|
72 |
case Success(result, _) => result |
|
73 |
case bad => error(bad.toString) |
|
74 |
} |
|
75 |
try { (options /: ops) { case (opts, op) => op(opts) } } |
|
76 |
catch { case ERROR(msg) => error(msg + Position.str_of(file.position)) } |
|
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
77 |
} |
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 |
|
48807 | 80 |
def init_defaults(): Options = |
48365
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 |
var options = empty |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
83 |
for { |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
84 |
dir <- Isabelle_System.components() |
48548 | 85 |
file = dir + OPTIONS if file.is_file |
48807 | 86 |
} { options = Parser.parse_file(options_syntax, Parser.option_entry, options, file) } |
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
87 |
options |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
88 |
} |
48457 | 89 |
|
48807 | 90 |
def init(): Options = init_defaults().load_prefs() |
91 |
||
48457 | 92 |
|
93 |
/* encode */ |
|
94 |
||
95 |
val encode: XML.Encode.T[Options] = (options => options.encode) |
|
48693
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
96 |
|
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
97 |
|
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
98 |
/* command line entry point */ |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
99 |
|
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
100 |
def main(args: Array[String]) |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
101 |
{ |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
102 |
Command_Line.tool { |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
103 |
args.toList match { |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
104 |
case export_file :: more_options => |
48807 | 105 |
val options = (Options.init() /: more_options)(_ + _) |
48693
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
106 |
|
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
107 |
if (export_file == "") java.lang.System.out.println(options.print) |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
108 |
else File.write(Path.explode(export_file), YXML.string_of_body(options.encode)) |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
109 |
|
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
110 |
0 |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
111 |
case _ => error("Bad arguments:\n" + cat_lines(args)) |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
112 |
} |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
113 |
} |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
114 |
} |
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
115 |
} |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
116 |
|
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
117 |
|
48807 | 118 |
final class Options private(protected val options: Map[String, Options.Opt] = Map.empty) |
48365
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 |
override def toString: String = options.iterator.mkString("Options (", ",", ")") |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
121 |
|
48693
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
122 |
def print: String = |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
123 |
cat_lines(options.toList.sortBy(_._1).map({ case (name, opt) => |
48795
bece259ee055
clarified format of etc/options: only declarations, not re-definitions;
wenzelm
parents:
48718
diff
changeset
|
124 |
"option " + name + " : " + opt.typ.print + " = " + |
48693
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
125 |
(if (opt.typ == Options.String) quote(opt.value) else opt.value) + |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
126 |
"\n -- " + quote(opt.description) })) |
ceeea46bdeba
"isabelle options" prints Isabelle system options;
wenzelm
parents:
48605
diff
changeset
|
127 |
|
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
128 |
|
48370 | 129 |
/* check */ |
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
130 |
|
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
131 |
private def check_name(name: String): Options.Opt = |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
132 |
options.get(name) match { |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
133 |
case Some(opt) => opt |
48368 | 134 |
case None => error("Unknown option " + quote(name)) |
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
135 |
} |
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 |
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
|
138 |
{ |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
139 |
val opt = check_name(name) |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
140 |
if (opt.typ == typ) opt |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
141 |
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
|
142 |
} |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
143 |
|
48370 | 144 |
|
145 |
/* basic operations */ |
|
146 |
||
147 |
private def put[A](name: String, typ: Options.Type, value: String): Options = |
|
148 |
{ |
|
149 |
val opt = check_type(name, typ) |
|
150 |
new Options(options + (name -> opt.copy(value = value))) |
|
151 |
} |
|
152 |
||
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
153 |
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
|
154 |
{ |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
155 |
val opt = check_type(name, typ) |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
156 |
parse(opt.value) match { |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
157 |
case Some(x) => x |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
158 |
case None => |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
159 |
error("Malformed value for option " + quote(name) + |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
160 |
" : " + typ.print + " =\n" + quote(opt.value)) |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
161 |
} |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
162 |
} |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
163 |
|
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
164 |
|
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
165 |
/* internal lookup and update */ |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
166 |
|
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
167 |
val bool = new Object |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
168 |
{ |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
169 |
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
|
170 |
def update(name: String, x: Boolean): Options = |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
171 |
put(name, Options.Bool, Properties.Value.Boolean(x)) |
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 |
|
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
174 |
val int = new Object |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
175 |
{ |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
176 |
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
|
177 |
def update(name: String, x: Int): Options = |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
178 |
put(name, Options.Int, Properties.Value.Int(x)) |
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 |
|
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
181 |
val real = new Object |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
182 |
{ |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
183 |
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
|
184 |
def update(name: String, x: Double): Options = |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
185 |
put(name, Options.Real, Properties.Value.Double(x)) |
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 |
|
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
188 |
val string = new Object |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
189 |
{ |
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
190 |
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
|
191 |
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
|
192 |
} |
48370 | 193 |
|
194 |
||
48807 | 195 |
/* external updates */ |
48370 | 196 |
|
197 |
private def check_value(name: String): Options = |
|
198 |
{ |
|
199 |
val opt = check_name(name) |
|
200 |
opt.typ match { |
|
201 |
case Options.Bool => bool(name); this |
|
202 |
case Options.Int => int(name); this |
|
203 |
case Options.Real => real(name); this |
|
204 |
case Options.String => string(name); this |
|
205 |
} |
|
206 |
} |
|
207 |
||
208 |
def declare(name: String, typ_name: String, value: String, description: String = ""): Options = |
|
209 |
{ |
|
210 |
options.get(name) match { |
|
211 |
case Some(_) => error("Duplicate declaration of option " + quote(name)) |
|
212 |
case None => |
|
213 |
val typ = |
|
214 |
typ_name match { |
|
215 |
case "bool" => Options.Bool |
|
216 |
case "int" => Options.Int |
|
217 |
case "real" => Options.Real |
|
218 |
case "string" => Options.String |
|
48456
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
219 |
case _ => error("Unknown type for option " + quote(name) + " : " + quote(typ_name)) |
48370 | 220 |
} |
48807 | 221 |
val opt = Options.Opt(typ, value, description) |
222 |
(new Options(options + (name -> opt))).check_value(name) |
|
48370 | 223 |
} |
224 |
} |
|
225 |
||
48807 | 226 |
def + (name: String, value: String): Options = |
48370 | 227 |
{ |
228 |
val opt = check_name(name) |
|
229 |
(new Options(options + (name -> opt.copy(value = value)))).check_value(name) |
|
230 |
} |
|
231 |
||
48807 | 232 |
def + (name: String, opt_value: Option[String]): Options = |
48370 | 233 |
{ |
234 |
val opt = check_name(name) |
|
235 |
opt_value match { |
|
48807 | 236 |
case Some(value) => this + (name, value) |
237 |
case None if opt.typ == Options.Bool => this + (name, "true") |
|
48370 | 238 |
case None => error("Missing value for option " + quote(name) + " : " + opt.typ.print) |
239 |
} |
|
240 |
} |
|
241 |
||
48807 | 242 |
def + (str: String): Options = |
48370 | 243 |
{ |
244 |
str.indexOf('=') match { |
|
48807 | 245 |
case -1 => this + (str, None) |
246 |
case i => this + (str.substring(0, i), str.substring(i + 1)) |
|
48370 | 247 |
} |
248 |
} |
|
48456
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
249 |
|
48807 | 250 |
def ++ (specs: List[Options.Spec]): Options = |
251 |
(this /: specs)({ case (x, (y, z)) => x + (y, z) }) |
|
252 |
||
48456
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
253 |
|
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
254 |
/* encode */ |
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
255 |
|
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
256 |
def encode: XML.Body = |
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
257 |
{ |
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
258 |
import XML.Encode.{string => str, _} |
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
259 |
list(triple(str, str, str))( |
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
260 |
options.toList.map({ case (name, opt) => (name, opt.typ.print, opt.value) })) |
d8ff14f44a40
added ML version of stand-alone options, with XML.encode/decode operations (unidirectional from Scala to ML);
wenzelm
parents:
48421
diff
changeset
|
261 |
} |
48807 | 262 |
|
263 |
||
264 |
/* user preferences */ |
|
265 |
||
266 |
def load_prefs(): Options = |
|
267 |
if (Options.PREFS.is_file) |
|
268 |
Options.Parser.parse_file( |
|
269 |
Options.prefs_syntax, Options.Parser.prefs_entry, this, Options.PREFS) |
|
270 |
else this |
|
271 |
||
272 |
def save_prefs() |
|
273 |
{ |
|
274 |
val current_defaults = Options.init_defaults() |
|
275 |
val changed = |
|
276 |
(for { |
|
277 |
(name, opt1) <- current_defaults.options.iterator |
|
278 |
opt2 <- options.get(name) |
|
279 |
if (opt1.value != opt2.value) |
|
280 |
} yield (name, opt2.value)).toList |
|
281 |
val prefs = |
|
282 |
changed.sortBy(_._1) |
|
283 |
.map({ case (x, y) => x + " = " + Outer_Syntax.quote_string(y) + "\n" }).mkString |
|
284 |
||
285 |
Options.PREFS.file renameTo Options.PREFS_BACKUP.file |
|
286 |
File.write(Options.PREFS, |
|
287 |
"(* generated by Isabelle " + Calendar.getInstance.getTime + " *)\n\n" + prefs) |
|
288 |
} |
|
48365
d88aefda01c4
basic support for stand-alone options with external string representation;
wenzelm
parents:
diff
changeset
|
289 |
} |