| author | wenzelm |
| Sat, 11 Nov 2023 19:36:59 +0100 | |
| changeset 78942 | 409442cb7814 |
| parent 78940 | 4cb67b3895b9 |
| child 78945 | 73162a487f94 |
| 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 {
|
|
11 |
def files(): List[Path] = |
|
12 |
Path.split_permissive_files(Isabelle_System.getenv("ISABELLE_REGISTRY"))
|
|
13 |
||
14 |
lazy val global: Registry = new Registry(TOML.parse_files(files())) |
|
|
78942
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
15 |
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
16 |
def err(msg: String, name: String): Nothing = |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
17 |
error(msg + " for registry entry " + quote(name)) |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
18 |
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
19 |
abstract class Category[A](val prefix: String) {
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
20 |
override def toString: String = "Registry.Category(" + quote(prefix) + ")"
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
21 |
def default_value: A |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
22 |
def value(name: String, t: TOML.T): A |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
23 |
} |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
24 |
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
25 |
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
|
26 |
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
|
27 |
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
|
28 |
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
|
29 |
t match {
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
30 |
case table: TOML.Table => table_value(name, table) |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
31 |
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
|
32 |
} |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
33 |
} |
| 78939 | 34 |
} |
35 |
||
|
78942
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
36 |
class Registry private(val table: TOML.Table) {
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
37 |
override def toString: String = TOML.Format(table) |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
38 |
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
39 |
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
|
40 |
table.any.get(category.prefix) match {
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
41 |
case None => category.default_value |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
42 |
case Some(t: TOML.Table) => |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
43 |
t.any.get(name) match {
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
44 |
case None => category.default_value |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
45 |
case Some(u) => category.value(name, u) |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
46 |
} |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
47 |
case Some(_) => Registry.err("Table expected", category.prefix)
|
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
48 |
} |
|
409442cb7814
support interpreted/typed entries via Registry.Category and Registry.Table;
wenzelm
parents:
78940
diff
changeset
|
49 |
} |
| 78940 | 50 |
} |