@@ -233,6 +233,90 @@ function copy_to(dest, src)
233233 )
234234end
235235
236+ """
237+ @_documented_enum(args...)
238+
239+ A utility macro for writing `@enum`s with inline documentation strings.
240+
241+ The even arguments are forwarded to the `@enum` macro, and the odd arguments are
242+ used as the docstring for the corresponding even argument.
243+
244+ ## Example
245+
246+ ```julia
247+ julia> MOI.@_documented_enum(
248+ \"\"\"
249+ MyDocumentedEnum
250+
251+ This is an example for the documentation.
252+ \"\"\" ,
253+ MyDocumentedEnum,
254+ \" A country down-under\" ,
255+ AUSTRALIA,
256+ \" Another country down-under\" ,
257+ NEW_ZEALAND,
258+ )
259+ MyDocumentedEnum
260+
261+ help?> MyDocumentedEnum
262+ search: MyDocumentedEnum
263+
264+ MyDocumentedEnum
265+
266+ This is an example for the documentation.
267+
268+ Values
269+ ========
270+
271+ Possible values are:
272+
273+ • AUSTRALIA: A country down-under
274+
275+ • NEW_ZEALAND: Another country down-under
276+
277+ help?> AUSTRALIA
278+ search: AUSTRALIA
279+
280+ AUSTRALIA::MyDocumentedEnum
281+
282+ An instance of the MyDocumentedEnum enum.
283+
284+ AUSTRALIA: A country down-under
285+ ```
286+ """
287+ macro _documented_enum (args... )
288+ @assert iseven (length (args))
289+ code = quote
290+ $ (Expr (:macrocall , Symbol (" @enum" ), __source__, args[2 : 2 : end ]. .. ))
291+ end
292+ main_doc, enum = args[1 ], args[2 ]
293+ main_doc *= " \n ## Values\n\n Possible values are:\n\n "
294+ for i in 3 : 2 : length (args)
295+ docstr, value = args[i], args[i+ 1 ]
296+ doc = """
297+ $value ::$enum
298+
299+ An instance of the [`$enum `](@ref) enum.\n\n `$value `: $docstr
300+ """
301+ push! (
302+ code. args,
303+ Expr (:macrocall , Symbol (" @doc" ), __source__, doc, Meta. quot (value)),
304+ )
305+ main_doc *= " * [`$value `](@ref): $docstr \n "
306+ end
307+ push! (
308+ code. args,
309+ Expr (
310+ :macrocall ,
311+ Symbol (" @doc" ),
312+ __source__,
313+ main_doc,
314+ Meta. quot (args[2 ]),
315+ ),
316+ )
317+ return esc (code)
318+ end
319+
236320include (" error.jl" )
237321include (" indextypes.jl" )
238322include (" functions.jl" )
0 commit comments