author | noschinl |
Mon, 13 Apr 2015 20:11:12 +0200 | |
changeset 60054 | ef4878146485 |
parent 57909 | 0fb331032f02 |
child 62433 | 2436a02f28c4 |
permissions | -rw-r--r-- |
43780 | 1 |
/* Title: Pure/General/properties.scala |
45673
cd41e3903fbf
separate compilation of PIDE vs. Pure sources, which enables independent Scala library;
wenzelm
parents:
45667
diff
changeset
|
2 |
Module: PIDE |
43780 | 3 |
Author: Makarius |
4 |
||
5 |
Property lists. |
|
6 |
*/ |
|
7 |
||
8 |
package isabelle |
|
9 |
||
10 |
||
11 |
object Properties |
|
12 |
{ |
|
13 |
/* plain values */ |
|
14 |
||
15 |
object Value |
|
16 |
{ |
|
48344 | 17 |
object Boolean |
18 |
{ |
|
19 |
def apply(x: scala.Boolean): java.lang.String = x.toString |
|
20 |
def unapply(s: java.lang.String): Option[scala.Boolean] = |
|
21 |
s match { |
|
22 |
case "true" => Some(true) |
|
23 |
case "false" => Some(false) |
|
24 |
case _ => None |
|
25 |
} |
|
26 |
} |
|
27 |
||
43780 | 28 |
object Int |
29 |
{ |
|
57909
0fb331032f02
more compact representation of special string values;
wenzelm
parents:
50946
diff
changeset
|
30 |
def apply(x: scala.Int): java.lang.String = Library.signed_string_of_int(x) |
43780 | 31 |
def unapply(s: java.lang.String): Option[scala.Int] = |
32 |
try { Some(Integer.parseInt(s)) } |
|
33 |
catch { case _: NumberFormatException => None } |
|
34 |
} |
|
35 |
||
36 |
object Long |
|
37 |
{ |
|
57909
0fb331032f02
more compact representation of special string values;
wenzelm
parents:
50946
diff
changeset
|
38 |
def apply(x: scala.Long): java.lang.String = Library.signed_string_of_long(x) |
43780 | 39 |
def unapply(s: java.lang.String): Option[scala.Long] = |
40 |
try { Some(java.lang.Long.parseLong(s)) } |
|
41 |
catch { case _: NumberFormatException => None } |
|
42 |
} |
|
43 |
||
44 |
object Double |
|
45 |
{ |
|
46 |
def apply(x: scala.Double): java.lang.String = x.toString |
|
47 |
def unapply(s: java.lang.String): Option[scala.Double] = |
|
48 |
try { Some(java.lang.Double.parseDouble(s)) } |
|
49 |
catch { case _: NumberFormatException => None } |
|
50 |
} |
|
51 |
} |
|
52 |
||
53 |
||
54 |
/* named entries */ |
|
55 |
||
56 |
type Entry = (java.lang.String, java.lang.String) |
|
57 |
type T = List[Entry] |
|
58 |
||
59 |
class String(val name: java.lang.String) |
|
60 |
{ |
|
61 |
def apply(value: java.lang.String): T = List((name, value)) |
|
62 |
def unapply(props: T): Option[java.lang.String] = |
|
63 |
props.find(_._1 == name).map(_._2) |
|
64 |
} |
|
65 |
||
48344 | 66 |
class Boolean(val name: java.lang.String) |
67 |
{ |
|
68 |
def apply(value: scala.Boolean): T = List((name, Value.Boolean(value))) |
|
69 |
def unapply(props: T): Option[scala.Boolean] = |
|
70 |
props.find(_._1 == name) match { |
|
71 |
case None => None |
|
72 |
case Some((_, value)) => Value.Boolean.unapply(value) |
|
73 |
} |
|
74 |
} |
|
75 |
||
48015 | 76 |
class Int(val name: java.lang.String) |
43780 | 77 |
{ |
78 |
def apply(value: scala.Int): T = List((name, Value.Int(value))) |
|
79 |
def unapply(props: T): Option[scala.Int] = |
|
80 |
props.find(_._1 == name) match { |
|
81 |
case None => None |
|
82 |
case Some((_, value)) => Value.Int.unapply(value) |
|
83 |
} |
|
84 |
} |
|
85 |
||
48015 | 86 |
class Long(val name: java.lang.String) |
43780 | 87 |
{ |
88 |
def apply(value: scala.Long): T = List((name, Value.Long(value))) |
|
89 |
def unapply(props: T): Option[scala.Long] = |
|
90 |
props.find(_._1 == name) match { |
|
91 |
case None => None |
|
92 |
case Some((_, value)) => Value.Long.unapply(value) |
|
93 |
} |
|
94 |
} |
|
95 |
||
48015 | 96 |
class Double(val name: java.lang.String) |
43780 | 97 |
{ |
98 |
def apply(value: scala.Double): T = List((name, Value.Double(value))) |
|
99 |
def unapply(props: T): Option[scala.Double] = |
|
100 |
props.find(_._1 == name) match { |
|
101 |
case None => None |
|
102 |
case Some((_, value)) => Value.Double.unapply(value) |
|
103 |
} |
|
104 |
} |
|
105 |
} |
|
106 |