| author | wenzelm | 
| Sun, 12 Nov 2023 12:54:26 +0100 | |
| changeset 78959 | 78698a97afb3 | 
| parent 78951 | c8c40e11c907 | 
| child 78960 | f4e7dec70fa4 | 
| permissions | -rw-r--r-- | 
| 78939 | 1  | 
/* Title: Pure/System/registry.scala  | 
2  | 
Author: Makarius  | 
|
3  | 
||
4  | 
Hierarchic system configuration in TOML notation.  | 
|
5  | 
*/  | 
|
6  | 
||
7  | 
package isabelle  | 
|
8  | 
||
9  | 
||
10  | 
object Registry {
 | 
|
| 78950 | 11  | 
/* registry files */  | 
12  | 
||
| 78951 | 13  | 
def load(files: Iterable[Path]): Registry = new Registry(TOML.parse_files(files))  | 
14  | 
||
15  | 
def global_files(): List[Path] =  | 
|
| 78939 | 16  | 
    Path.split_permissive_files(Isabelle_System.getenv("ISABELLE_REGISTRY"))
 | 
17  | 
||
| 78951 | 18  | 
lazy val global: Registry = load(global_files())  | 
| 
78942
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
19  | 
|
| 78950 | 20  | 
|
21  | 
/* interpreted entries */  | 
|
22  | 
||
| 
78942
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
23  | 
def err(msg: String, name: String): Nothing =  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
24  | 
error(msg + " for registry entry " + quote(name))  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
25  | 
|
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
26  | 
  abstract class Category[A](val prefix: String) {
 | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
27  | 
    override def toString: String = "Registry.Category(" + quote(prefix) + ")"
 | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
28  | 
def default_value: A  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
29  | 
def value(name: String, t: TOML.T): A  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
30  | 
}  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
31  | 
|
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
32  | 
  abstract class Table[A](prefix: String) extends Category[A](prefix) {
 | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
33  | 
def table_value(name: String, table: TOML.Table): A  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
34  | 
    override def default_value: A = table_value("", TOML.Table.empty)
 | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
35  | 
override def value(name: String, t: TOML.T): A =  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
36  | 
      t match {
 | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
37  | 
case table: TOML.Table => table_value(name, table)  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
38  | 
        case _ => err("Table expected", Long_Name.qualify(prefix, name))
 | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
39  | 
}  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
40  | 
}  | 
| 
78945
 
73162a487f94
build cluster host specifications are based on registry entries (table prefix "host");
 
wenzelm 
parents: 
78942 
diff
changeset
 | 
41  | 
|
| 78950 | 42  | 
|
43  | 
/* build cluster resources */  | 
|
44  | 
||
| 
78945
 
73162a487f94
build cluster host specifications are based on registry entries (table prefix "host");
 
wenzelm 
parents: 
78942 
diff
changeset
 | 
45  | 
  object Host extends Table[List[Options.Spec]]("host") {
 | 
| 
 
73162a487f94
build cluster host specifications are based on registry entries (table prefix "host");
 
wenzelm 
parents: 
78942 
diff
changeset
 | 
46  | 
def options_spec(a: TOML.Key, b: TOML.T): Option[Options.Spec] =  | 
| 78947 | 47  | 
TOML.Scalar.unapply(b).map(Options.Spec.eq(a, _))  | 
| 
78945
 
73162a487f94
build cluster host specifications are based on registry entries (table prefix "host");
 
wenzelm 
parents: 
78942 
diff
changeset
 | 
48  | 
|
| 
 
73162a487f94
build cluster host specifications are based on registry entries (table prefix "host");
 
wenzelm 
parents: 
78942 
diff
changeset
 | 
49  | 
override def table_value(a: String, t: TOML.Table): List[Options.Spec] =  | 
| 
 
73162a487f94
build cluster host specifications are based on registry entries (table prefix "host");
 
wenzelm 
parents: 
78942 
diff
changeset
 | 
50  | 
for ((a, b) <- t.any.values; s <- options_spec(a, b)) yield s  | 
| 
 
73162a487f94
build cluster host specifications are based on registry entries (table prefix "host");
 
wenzelm 
parents: 
78942 
diff
changeset
 | 
51  | 
}  | 
| 78939 | 52  | 
}  | 
53  | 
||
| 
78942
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
54  | 
class Registry private(val table: TOML.Table) {
 | 
| 78959 | 55  | 
override def toString: String =  | 
56  | 
    (for (a <- table.domain.toList.sorted.iterator) yield {
 | 
|
57  | 
val size =  | 
|
58  | 
        table.any.get(a) match {
 | 
|
59  | 
          case Some(t: TOML.Array) => "(" + t.length + ")"
 | 
|
60  | 
          case Some(t: TOML.Table) => "(" + t.domain.size + ")"
 | 
|
61  | 
case _ => ""  | 
|
62  | 
}  | 
|
63  | 
a + size  | 
|
64  | 
    }).mkString("Registry(", ", ", ")")
 | 
|
| 
78942
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
65  | 
|
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
66  | 
  def get[A](category: Registry.Category[A], name: String): A = {
 | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
67  | 
    table.any.get(category.prefix) match {
 | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
68  | 
case None => category.default_value  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
69  | 
case Some(t: TOML.Table) =>  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
70  | 
        t.any.get(name) match {
 | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
71  | 
case None => category.default_value  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
72  | 
case Some(u) => category.value(name, u)  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
73  | 
}  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
74  | 
      case Some(_) => Registry.err("Table expected", category.prefix)
 | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
75  | 
}  | 
| 
 
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
 
wenzelm 
parents: 
78940 
diff
changeset
 | 
76  | 
}  | 
| 78940 | 77  | 
}  |