diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2026-11-19 11:32:16 +0100 |
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2026-11-19 11:32:16 +0100 |
| commit | 8708171877054c98aad45079d85d4e699420f2fe (patch) | |
| tree | 2e580e6891708b7b70d07f7bec03bd0a76ae171b /lib/configuration/ast.ml | |
| parent | e1bf7686f408b52a870d4ed4f3c565dbbcc3954f (diff) | |
Added fields in lists
Diffstat (limited to 'lib/configuration/ast.ml')
| -rw-r--r-- | lib/configuration/ast.ml | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/lib/configuration/ast.ml b/lib/configuration/ast.ml index 6d29d0c..edf129f 100644 --- a/lib/configuration/ast.ml +++ b/lib/configuration/ast.ml @@ -5,23 +5,27 @@ let escaped = String.escaped type setting = { mutable contents : Model.content Splay.t; - lists : Model.List.t list; + mutable lists : Model.list Splay.t; } -let init : unit -> setting = fun () -> { contents = Splay.empty (); lists = [] } +let init : unit -> setting = + fun () -> { contents = Splay.empty (); lists = Splay.empty () } (** Get the content from the setting. *) let get_content : setting -> Model.Identifier.t -> Model.content option = fun settings name -> Splay.find name settings.contents (** 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.find_opt setting.lists ~f:(fun l -> - Model.Identifier.equal l.Model.List.id name) +let get_list : setting -> Model.Identifier.t -> Model.list option = + fun setting name -> Splay.find name setting.lists -(** All the lists declared in the setting *) -let lists : setting -> Model.List.t list = fun setting -> setting.lists +(** All the lists declared in the setting, in a deterministic (identifier) + order *) +let lists : setting -> Model.list list = + fun setting -> + Splay.fold (fun acc (_, list) -> list :: acc) [] setting.lists + |> List.sort ~cmp:(fun a b -> + Model.Identifier.compare a.Model.DataList.id b.Model.DataList.id) exception BrokenLink : ('a Type.Id.t * 'a * Model.Identifier.t) -> exn @@ -39,8 +43,12 @@ let register_content : setting -> Model.content -> unit = in traverse content -let register_list : setting -> Model.List.t -> setting = - fun t l -> { t with lists = l :: t.lists } +let register_list : setting -> Model.list -> setting = + fun setting list -> + let () = + setting.lists <- Splay.add list.Model.DataList.id list setting.lists + in + setting (** Force the evaluation of the field target and ensure it points to an existing content in the application. @@ -56,8 +64,8 @@ let get_reference_target : Model.field -> Model.content option = (* 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 -> ( + | Model.Reference.List _ -> None + | Model.Reference.Content ref -> ( try Some (Model.Reference.get ref) with BrokenLink _ as e -> raise_notrace e)) |
