From e1bf7686f408b52a870d4ed4f3c565dbbcc3954f Mon Sep 17 00:00:00 2001 From: Sébastien Dailly Date: Thu, 19 Nov 2026 09:57:49 +0100 Subject: Management of lists in the settings --- lib/configuration/ast.ml | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'lib/configuration/ast.ml') 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. *) -- cgit v1.2.3