On this page:
docmodule
doc
nonterminal
nontermref
fun
operator
def
enum
expr.macro
defn.macro
decl.macro
decl.nestable_  macro
annot.macro
bind.macro
repet.macro
reducer.macro
unquote_  bind.macro
for_  clause.macro
class_  clause.macro
interface_  clause.macro
veneer_  clause.macro
syntax_  class_  clause.macro
pattern_  clause.macro
entry_  point.macro
immediate_  callee.macro
impo.macro
expo.macro
impo.modifier
expo.modifier
class
interface
method
property
dot
syntax_  class
doc
space.enforest
space.transform
key_  comp.def
Parameter.def
grammar
8.15.0.2

3.2 Documenting Bindings🔗ℹ

declaration

docmodule(option, ...,

          mod_path)

 

option

 = 

~lang

 | 

~no_declare

 | 

~use_sources:

  mod_path

  ...

A declaration to set the context of doc documentation forms that appear later in the same section or nested subsections. The bindings will be documented as exports from mod_path.

If the ~lang option is specified, then the module is documented as a language module for use with #lang.

If the ~no_declare option is specified, then the module declaration is rendered in the document, but it does not set context for doc forms.

The ~use_sources option declares modules that should be treated as exporting modules for hyperlinking purposes, even though the rendered documentation says that the bindings originate from the main mod_path. Use ~use_sources when bindings are reexported from multiple documented modules, and where bindings accessed via all of those modules should be linked to the docs in this section.

The docmodule form must be used only once without ~no_declare within a section, but a section’s docmodule can be shadowed by a declaration in a subsection.

expression

doc (prep,

     ...,

     entry,

     ...,

     [description, ...])

 

entry

 = 

fun fun_spec

 | 

operator op_spec

 | 

def def_spec

 | 

enum enum_spec

 | 

expr.macro macro_spec

 | 

defn.macro macro_spec

 | 

decl.macro macro_spec

 | 

annot.macro macro_spec

 | 

bind.macro macro_spec

 | 

repet.macro macro_spec

 | 

class class_spec

 | 

interface interface_spec

 | 

grammar grammar_spec

 | 

other_doc_entry_form

 | 

~include mod_path:

  id ...

  ...

 

prep

 = 

~nonterminal:

  id: nt_key_ref

  ...

 | 

~nonterminal_key: nt_key

 | 

~literal:

  id ...

  ...

 | 

~meta

 | 

~also_meta

 

nt_key_ref

 = 

op_or_id_name

 | 

op_or_id_name nonterm_op_or_id_name

 | 

op_or_id_name space

 | 

op_or_id_name nonterm_op_or_id_name space

 

nt_key

 = 

op_or_id_name

 | 

op_or_id_name space

 

space

 = 

builtin_space

 | 

~at space_name

Documents a set of bindings. A documented binding needs to be imported into the document’s implementation using meta_label. meanwhile, an enclosing section needs to include a docmodule to select the module that is documented to export the binding—typically a module that reexports from the original implementing module. A binding should be documented by at most one doc form, but multiple entrys in the same doc form can describe the same binding.

Each entry clause is typical a doc entry form. For example, use the fun doc entry form to document a function. An entry can also be ~include to extract documentation attached to a definition (e.g., extracted from a fun or enum definition that includes ~doc). New doc entry forms can be defined with doc.bridge. All of the documented forms are shown together as one documentation box in the rendered document.

Each pre-defined doc entry form has the same name and basic shape as a Rhombus definition form. For example, the fun doc entry form can be used to document functions that are implemented using fun. A doc entry form may not have exactly the same syntax as the definition form, however. For example, the fun doc entry form supports only a single function case, and multiple cases are meant to be documented with multiple uses of the fun doc entry form. A doc entry form typically also does not require the body part of the corresponding definition form, but it will typically allow the body to be written and typeset that body literally. The set of doc entry forms listed in entry is merely representative, because new forms can be added (and not even all of the predefined ones are listed there).

The list of descriptions to describe the documented bindings is usually written inside {} using @ notation. For example, the following use of doc defines Widget, ok_button, and make_panel all together:

@doc(

  annot.macro 'Widget'

  def ok_button :: Widget

  fun make_panel(label :: String,

                 [child :: Widget, ...]) :: Widget

){

  A @rhombus(Widget, ~annot) is an interactive thing, and the

  constant @rhombus(ok_button) is a stock widget. Use @rhombus(make_panel)

  to combine several widgets into a titled panel, where @rhombus(label)

  provide the panel's title.

}

Doc entry forms like fun and annot.macro are responsible for extracting the relevant name that is being documented via doc. They also extract names that should be treated as metavariables in the documentation, such as the argument label to make_panel, so that when @rhombus(label) is used in the description, it renders as a metavariable there.

Each entry is otherwise typeset as in rhombusblock content, which means that #, can be used to escape from literal typesetting and write an expression that produces a Scribble element. to replace the #,(expr) escape.

Before doc entry forms, a prep declaration can bind identifiers to customize their treatment in typesetting:

definition

nonterminal:

  id: nt_key_ref

  ...

 

expression

nontermref(id)

The nonterminal and nontermref forms provide a way to bind nonterminal metavariables outside of a doc form. That is, using nonterminal is analogous to using ~nonterminal within doc.

Because nonterminal names tend to be short and easily confused with other uses, however, nonterminal names bound with nonterminal are not recognized by rhombus. Instead, nontermref must be used to explicitly refer to the nonterminal (with a link to its definition).

doc entry

fun id_name(arg, ...) term ...

 

doc entry

operator (op_or_id_name arg) term ...

 

doc entry

operator (arg_term op_or_id_name arg_term) term ...

A doc entry form to document a function id_name or operator op_or_id_name. Extra terms can be anything, but would typically show a return annotation, if any.

Each arg is parsed like a fun argument to infer argument bindings as metavariables. Referencing a metavariable in the description body of doc with rhombus typesets the name in the same way as the argument variable. Similarly, each arg_term is parsed as for an operator argument.

To document a function or operator with multiple cases, uses fun or operator multiple times with the same id_name or op_or_id_name in the same doc form.

doc entry

def id_name term ...

A doc entry form to document id_name. Extra terms can be anything, but would typically show a return annotation, if any.

doc entry

enum id_name:

  enum_clause

  ...

A doc entry form to document an enumeration. In addition to id_name itself as an annotation and namespace, each binding within the namespace described by enum_clause is also documented.

doc entry

expr.macro 'op_or_id_name quoted_term ...' term ...

 

doc entry

expr.macro '$ op_or_id_name id_name quoted_term ...' term ...

 

doc entry

defn.macro 'id_name quoted_term ...' term ...

 

doc entry

decl.macro 'id_name quoted_term ...' term ...

 

doc entry

decl.nestable_macro 'id_name term ...' term ...

 

doc entry

annot.macro 'op_or_id_name term ...' term ...

 

doc entry

annot.macro '$ op_or_id_name id_name term ...' term ...

 

doc entry

bind.macro 'op_or_id_name term ...' term ...

 

doc entry

bind.macro '$ op_or_id_name id_name term ...' term ...

 

doc entry

repet.macro 'op_or_id_name term ...' term ...

 

doc entry

repet.macro '$ op_or_id_name id_name term ...' term ...

A doc entry form to documents an expression, definition, declaration, annotation, binding, or repetition macro op_or_id_name or id_name.

In the quoted_terms, a use of $ indicates that the subsequent identifier is a metavariable, as opposed to a literal. The $ itself will not be rendered, but the identifier will be rendered as a metavariable. Furthermore, it may refer to a nonterminal that is defined using grammar or bound with a ~nonterminal preparation in the enclosing doc form.

The following example demonstrates documenting a widget expression macro with a metavariable direction that is specified via grammar. Meanwhile, ~nonterminal is used to make widget_expr hyperlink to the expr nonterminal that is defined in the Rhombus manual.

@doc(

  ~nonterminal:

    widget_expr: block expr

  expr.macro 'widget:

                ~label: $expr

                $direction

                $widget_expr

                ...'

  grammar direction:

    ~horiz

    ~vert

){

  Creates a widget, where each @rhombus(widget_expr) supplies a

  child widget for the combined widget.

}

doc entry

reducer.macro 'id_name quoted_term ...' term ...

 

doc entry

unquote_bind.macro 'id_name quoted_term ...' term ...

 

doc entry

for_clause.macro 'id_name quoted_term ...' term ...

 

doc entry

class_clause.macro 'id_name quoted_term ...' term ...

 

doc entry

interface_clause.macro 'id_name quoted_term ...' term ...

 

doc entry

veneer_clause.macro 'id_name quoted_term ...' term ...

 

doc entry

syntax_class_clause.macro 'id_name quoted_term ...' term ...

 

doc entry

pattern_clause.macro 'id_name quoted_term ...' term ...

 

doc entry

entry_point.macro 'id_name quoted_term ...' term ...

 

doc entry

immediate_callee.macro 'id_name quoted_term ...' term ...

 

doc entry

impo.macro 'id_name quoted_term ...' term ...

 

doc entry

expo.macro 'id_name quoted_term ...' term ...

 

doc entry

impo.modifier 'id_name quoted_term ...' term ...

 

doc entry

expo.modifier 'id_name quoted_term ...' term ...

More doc entry forms along the same lines as defn.macro.

doc entry

class id_name(arg, ...) term ...

 

doc entry

interface id_name term ...

 

doc entry

method (id :: in_id_name) . method_id(arg, ...) term ...

 

doc entry

property (id :: in_id_name) . property_id term ...

 

doc entry

dot (id :: in_id_name) . dot_id term ...

A doc entry forms to document a class id_name, interface id_name, method method_id in in_id_name, property property_id in in_id_name, or dot-accessed dot_id in in_id_name.

Note that methods and properties are defined standalone, as opposed to being inside class or interface. That’s why a in_id_name is needed to identify the enclosing class or interface. The id before in_id_name is treated as a metavariable.

doc entry

syntax_class id_name term ...

A doc entry form to document a syntax class.

doc entry

doc 'id_name quoted_term ...' term ...

A doc entry form to document doc entry forms.

doc entry

space.enforest id_name:

  term ...

  ...

 

doc entry

space.transform id_name:

  term ...

  ...

Doc entry forms to document spaces.

doc entry

key_comp.def id_name term ...

 

doc entry

Parameter.def id_name term ...

More doc entry forms.

doc entry

grammar id:

  quoted_term ...

  ...

Defines a metavariable id as a nonterminal. Each quoted_term sequence is typeset as in expr.macro, where $ can prefix an identifier to make it a metavariable instead of a literal.