Skip to content

Commit

Permalink
feat(graindoc)!: Allow @since and @returns once per export
Browse files Browse the repository at this point in the history
  • Loading branch information
spotandjake committed Jan 2, 2024
1 parent 32b9639 commit 8b49ed8
Showing 1 changed file with 36 additions and 24 deletions.
60 changes: 36 additions & 24 deletions compiler/graindoc/docblock.re
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ exception

exception MissingParamType({name: string});
exception MissingReturnType;
exception AttributeAppearsMultipleTimes({attr: string});
exception
InvalidAttribute({
name: string,
Expand Down Expand Up @@ -106,6 +107,10 @@ let () =
| MissingReturnType =>
let msg = "Unable to find a return type. Please file an issue!";
Some(msg);
| AttributeAppearsMultipleTimes({attr}) =>
let msg =
Printf.sprintf("Attribute @%s is only allowed to appear once.", attr);
Some(msg);
| InvalidAttribute({name, attr}) =>
let msg = Printf.sprintf("Invalid attribute @%s on %s", attr, name);
Some(msg);
Expand Down Expand Up @@ -272,16 +277,18 @@ let for_value_description =
examples,
)
| Since({attr_version}) =>
// TODO(#787): Should we fail if more than one `@since` attribute?
(
deprecations,
Some({since_version: attr_version}),
history,
params,
returns,
throws,
examples,
)
switch (since) {
| Some(_) => raise(AttributeAppearsMultipleTimes({attr: "since"}))
| None => (
deprecations,
Some({since_version: attr_version}),
history,
params,
returns,
throws,
examples,
)
}
| History({attr_version: history_version, attr_desc: history_msg}) => (
deprecations,
since,
Expand Down Expand Up @@ -309,20 +316,25 @@ let for_value_description =
examples,
);
| Returns({attr_desc: returns_msg}) =>
let returns_type =
switch (return_type) {
| Some(typ) => Printtyp.string_of_type_sch(typ)
| None => raise(MissingReturnType)
};
(
deprecations,
since,
history,
params,
Some({returns_msg, returns_type}),
throws,
examples,
);
switch (returns) {
| Some(_) =>
raise(AttributeAppearsMultipleTimes({attr: "returns"}))
| None =>
let returns_type =
switch (return_type) {
| Some(typ) => Printtyp.string_of_type_sch(typ)
| None => raise(MissingReturnType)
};
(
deprecations,
since,
history,
params,
Some({returns_msg, returns_type}),
throws,
examples,
);
}
| Throws({attr_type: throw_type, attr_desc: throw_msg}) => (
deprecations,
since,
Expand Down

0 comments on commit 8b49ed8

Please sign in to comment.