Docstrings(3) OCaml library Docstrings(3)

# [NAME](#NAME)

Docstrings - Documentation comments

# [Module](#Module)

Module Docstrings

# [Documentation](#Documentation)

Module **Docstrings**  
: **sig end**

Documentation comments

Warning: this module is unstable and part of **Compiler\_libs** .

*val init* : **unit -&gt; unit**

(Re)Initialise all docstring state

*val warn\_bad\_docstrings* : **unit -&gt; unit**

Emit warnings for unattached and ambiguous docstrings

## [Docstrings](#Docstrings)

*type docstring*

Documentation comments

*val docstring* : **string -&gt; Location.t -&gt; docstring**

Create a docstring

*val register* : **docstring -&gt; unit**

Register a docstring

*val docstring\_body* : **docstring -&gt; string**

Get the text of a docstring

*val docstring\_loc* : **docstring -&gt; Location.t**

Get the location of a docstring

## [Set functions](#Set_functions)

These functions are used by the lexer to associate docstrings to the locations of tokens.

*val set\_pre\_docstrings* : **Lexing.position -&gt; docstring list -&gt; unit**

Docstrings immediately preceding a token

*val set\_post\_docstrings* : **Lexing.position -&gt; docstring list -&gt; unit**

Docstrings immediately following a token

*val set\_floating\_docstrings* : **Lexing.position -&gt; docstring list -&gt; unit**

Docstrings not immediately adjacent to a token

*val set\_pre\_extra\_docstrings* : **Lexing.position -&gt; docstring list -&gt; unit**

Docstrings immediately following the token which precedes this one

*val set\_post\_extra\_docstrings* : **Lexing.position -&gt; docstring list -&gt; unit**

Docstrings immediately preceding the token which follows this one

## [Items](#Items)

The **Docstrings.docs** type represents documentation attached to an item.

*type docs* = {  
docs\_pre : **docstring option** ;  
docs\_post : **docstring option** ;  
}

*val empty\_docs* : **docs**

*val docs\_attr* : **docstring -&gt; Parsetree.attribute**

*val add\_docs\_attrs* : **docs -&gt; Parsetree.attributes -&gt; Parsetree.attributes**

Convert item documentation to attributes and add them to an attribute list

*val symbol\_docs* : **unit -&gt; docs**

Fetch the item documentation for the current symbol. This also marks this documentation (for ambiguity warnings).

*val symbol\_docs\_lazy* : **unit -&gt; docs Lazy.t**

*val rhs\_docs* : **int -&gt; int -&gt; docs**

Fetch the item documentation for the symbols between two positions. This also marks this documentation (for ambiguity warnings).

*val rhs\_docs\_lazy* : **int -&gt; int -&gt; docs Lazy.t**

*val mark\_symbol\_docs* : **unit -&gt; unit**

Mark the item documentation for the current symbol (for ambiguity warnings).

*val mark\_rhs\_docs* : **int -&gt; int -&gt; unit**

Mark as associated the item documentation for the symbols between two positions (for ambiguity warnings)

## [Fields and constructors](#Fields_and_constructors)

The **Docstrings.info** type represents documentation attached to a field or constructor.

*type info* = **docstring option**

*val empty\_info* : **info**

*val info\_attr* : **docstring -&gt; Parsetree.attribute**

*val add\_info\_attrs* : **info -&gt; Parsetree.attributes -&gt; Parsetree.attributes**

Convert field info to attributes and add them to an attribute list

*val symbol\_info* : **unit -&gt; info**

Fetch the field info for the current symbol.

*val rhs\_info* : **int -&gt; info**

Fetch the field info following the symbol at a given position.

## [Unattached comments](#Unattached_comments)

The **Docstrings.text** type represents documentation which is not attached to anything.

*type text* = **docstring list**

*val empty\_text* : **text**

*val empty\_text\_lazy* : **text Lazy.t**

*val text\_attr* : **docstring -&gt; Parsetree.attribute**

*val add\_text\_attrs* : **text -&gt; Parsetree.attributes -&gt; Parsetree.attributes**

Convert text to attributes and add them to an attribute list

*val symbol\_text* : **unit -&gt; text**

Fetch the text preceding the current symbol.

*val symbol\_text\_lazy* : **unit -&gt; text Lazy.t**

*val rhs\_text* : **int -&gt; text**

Fetch the text preceding the symbol at the given position.

*val rhs\_text\_lazy* : **int -&gt; text Lazy.t**

## [Extra text](#Extra_text)

There may be additional text attached to the delimiters of a block (e.g. **struct** and **end** ). This is fetched by the following functions, which are applied to the contents of the block rather than the delimiters.

*val symbol\_pre\_extra\_text* : **unit -&gt; text**

Fetch additional text preceding the current symbol

*val symbol\_post\_extra\_text* : **unit -&gt; text**

Fetch additional text following the current symbol

*val rhs\_pre\_extra\_text* : **int -&gt; text**

Fetch additional text preceding the symbol at the given position

*val rhs\_post\_extra\_text* : **int -&gt; text**

Fetch additional text following the symbol at the given position

*val rhs\_post\_text* : **int -&gt; text**

Fetch text following the symbol at the given position

*module WithMenhir :* **sig end**

2026-10-01 OCamldoc

---

Document: Docstrings(3o) from ocaml 5.5.1-r1 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
