summaryrefslogtreecommitdiff
path: root/lib/configuration/ast.ml
diff options
context:
space:
mode:
authorSébastien Dailly <sebastien@dailly.me>2026-11-19 09:57:49 +0100
committerSébastien Dailly <sebastien@dailly.me>2026-11-19 09:57:49 +0100
commite1bf7686f408b52a870d4ed4f3c565dbbcc3954f (patch)
treeee7e156032cc0c43ca10879051e64c3dfeab1515 /lib/configuration/ast.ml
parenta9628fda0fc027c54b5ed5313a0c41731d79e41f (diff)
Management of lists in the settings
Diffstat (limited to 'lib/configuration/ast.ml')
-rw-r--r--lib/configuration/ast.ml29
1 files changed, 19 insertions, 10 deletions
diff --git a/lib/configuration/ast.ml b/lib/configuration/ast.ml
index 607031e..6d29d0c 100644
--- a/lib/configuration/ast.ml
+++ b/lib/configuration/ast.ml
@@ -3,8 +3,10 @@ module Splay = Splay.Make (Model.Identifier)
let escaped = String.escaped
-type list' = { id : string; source : string }
-type setting = { mutable contents : Model.content Splay.t; lists : list' list }
+type setting = {
+ mutable contents : Model.content Splay.t;
+ lists : Model.List.t list;
+}
let init : unit -> setting = fun () -> { contents = Splay.empty (); lists = [] }
@@ -12,14 +14,16 @@ let init : unit -> setting = fun () -> { contents = Splay.empty (); lists = [] }
let get_content : setting -> Model.Identifier.t -> Model.content option =
fun settings name -> Splay.find name settings.contents
-(** Check whether a list with the given name is declared in the setting *)
-let has_list : setting -> Model.Identifier.t -> bool =
+(** Get the list declared with the given name, if any *)
+let get_list : setting -> Model.Identifier.t -> Model.List.t option =
fun setting name ->
- List.exists setting.lists ~f:(fun { id; _ } ->
- String.equal id (Model.Identifier.to_string name))
+ List.find_opt setting.lists ~f:(fun l ->
+ Model.Identifier.equal l.Model.List.id name)
+
+(** All the lists declared in the setting *)
+let lists : setting -> Model.List.t list = fun setting -> setting.lists
exception BrokenLink : ('a Type.Id.t * 'a * Model.Identifier.t) -> exn
-exception NotImplemented : ('a Type.Id.t * 'a * Model.Identifier.t) -> exn
(** Register a content and all the associated subcontent in the top level,
giving the possibility to fetch any content or subcontent by its name
@@ -35,7 +39,7 @@ let register_content : setting -> Model.content -> unit =
in
traverse content
-let register_list : setting -> list' -> setting =
+let register_list : setting -> Model.List.t -> setting =
fun t l -> { t with lists = l :: t.lists }
(** Force the evaluation of the field target and ensure it points to an existing
@@ -49,8 +53,13 @@ let get_reference_target : Model.field -> Model.content option =
| Text -> None
| Integer -> None
| MonoReference r | MultiReference r -> (
- try Some (Model.Reference.get r.Model.Typ.t)
- with BrokenLink _ as e -> raise_notrace e)
+ (* References to static lists are leaves of the dependency graph: they
+ are not followed here. *)
+ match r.Model.Typ.t with
+ | Model.Typ.List _ -> None
+ | Model.Typ.Content ref -> (
+ try Some (Model.Reference.get ref)
+ with BrokenLink _ as e -> raise_notrace e))
(** Extract the other contents pointed by a given content, and the field used
for it. *)