summaryrefslogtreecommitdiff
path: root/lib/configuration/read_conf.ml
diff options
context:
space:
mode:
Diffstat (limited to 'lib/configuration/read_conf.ml')
-rw-r--r--lib/configuration/read_conf.ml59
1 files changed, 33 insertions, 26 deletions
diff --git a/lib/configuration/read_conf.ml b/lib/configuration/read_conf.ml
index bcd8f8a..c7149ae 100644
--- a/lib/configuration/read_conf.ml
+++ b/lib/configuration/read_conf.ml
@@ -34,19 +34,22 @@ module Make (S : Decoders.Decode.S) = struct
targets) and a type id (to attribute broken links to this parsing pass in
the error messages). *)
- (** Build the reference target for a field: a lazy thunk closing over the
- setting. The thunk is only forced by [Ast.check], once every content has
- been registered — this is what allows forward and cyclic references
- between contents. The raw value is kept to report broken links. *)
+ (** Build the reference target for a field. Lists are decoded before the
+ contents, so a declared list is matched eagerly; a content target is a
+ lazy thunk closing over the setting, only forced by [Ast.check] once every
+ content has been registered — this is what allows forward and cyclic
+ references between contents. The raw value is kept to report broken links.
+ *)
let link (env : env) (value : S.value) (name : Model.Identifier.t) :
- Model.Reference.t =
- Model.Reference.v (fun () ->
- match Ast.get_content env.settings name with
- | Some content -> content
- | None ->
- if Ast.has_list env.settings name then
- raise_notrace (Ast.NotImplemented (env.ty, value, name))
- else raise_notrace (Ast.BrokenLink (env.ty, value, name)))
+ Model.target =
+ match Ast.get_list env.settings name with
+ | Some list -> Model.Typ.List list
+ | None ->
+ Model.Typ.Content
+ (Model.Reference.v (fun () ->
+ match Ast.get_content env.settings name with
+ | Some content -> content
+ | None -> raise_notrace (Ast.BrokenLink (env.ty, value, name))))
let field_type (env : env) : Model.field_ex S.decoder =
let text_type : Model.field_ex S.decoder =
@@ -105,9 +108,23 @@ module Make (S : Decoders.Decode.S) = struct
in
S.succeed (Model.Content.v id sections subcontents))
- let list' : Ast.list' S.decoder =
- let* id = S.field "id" S.string and* source = S.field "source" S.string in
- S.succeed Ast.{ id; source }
+ let list_source : Model.List.source S.decoder =
+ (* The source is either a plain kind string ("csv"), or an object with a
+ "type" and an optional "file" path. *)
+ let as_object =
+ let* kind = S.field "type" S.string
+ and* file = S.field_opt "file" S.string in
+ S.succeed Model.List.{ kind; file }
+ in
+ let as_string =
+ S.map (fun kind -> Model.List.{ kind; file = None }) S.string
+ in
+ S.one_of [ ("object", as_object); ("string", as_string) ]
+
+ let list : Model.List.t S.decoder =
+ let* id = S.field "id" identifier
+ and* source = S.field "source" list_source in
+ S.succeed Model.List.{ id; source }
let t : Ast.setting S.decoder =
(* Register a type id to attribute broken links to this parsing pass *)
@@ -115,7 +132,7 @@ module Make (S : Decoders.Decode.S) = struct
(* Decode the lists first, then the contents: the reference targets are
lazy thunks closing over [settings], forced only by [Ast.check] once
every content has been registered. *)
- let* lists = S.field_opt_or ~default:[] "list" (S.list list') in
+ let* lists = S.field_opt_or ~default:[] "list" (S.list list) in
let settings =
List.fold_left lists ~init:(Ast.init ()) ~f:Ast.register_list
in
@@ -136,16 +153,6 @@ module Make (S : Decoders.Decode.S) = struct
^ "\". Expected existing list or content"
in
S.fail_with (Decoders.Error.make ~context message))
- | Error (Ast.NotImplemented (ty', context, name) as e) -> (
- match Type.Id.provably_equal ty ty' with
- | None -> raise e
- | Some Type.Equal ->
- let message =
- "Unsupported target \""
- ^ Model.Identifier.to_string name
- ^ "\". Lists as target are not implemented yet"
- in
- S.fail_with (Decoders.Error.make ~context message))
| Error (Graph_tree.Cycle contents) ->
let content_name =
List.map contents ~f:(fun c ->