---
name: "Docstrings"
section: "3o"
platform: "linux"
package: "ocaml"
version: "5.5.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/Docstrings"
---

# Docstrings(3o)

Documentation comments

## NAME

Docstrings - Documentation comments

## Module

Module   Docstrings

## Documentation

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

Documentation comments

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

*val init* :  **unit -\> unit**

(Re)Initialise all docstring state

*val warn\_bad\_docstrings* :  **unit -\> unit**

Emit warnings for unattached and ambiguous docstrings

### Docstrings

*type docstring*

Documentation comments

*val docstring* :  **string -\> Location.t -\> docstring**

Create a docstring

*val register* :  **docstring -\> unit**

Register a docstring

*val docstring\_body* :  **docstring -\> string**

Get the text of a docstring

*val docstring\_loc* :  **docstring -\> Location.t**

Get the location of a docstring

### Set functions

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

*val set\_pre\_docstrings* :  **Lexing.position -\> docstring list -\> unit**

Docstrings immediately preceding a token

*val set\_post\_docstrings* :  **Lexing.position -\> docstring list -\> unit**

Docstrings immediately following a token

*val set\_floating\_docstrings* :  **Lexing.position -\> docstring list -\> unit**

Docstrings not immediately adjacent to a token

*val set\_pre\_extra\_docstrings* :  **Lexing.position -\> docstring list -\> unit**

Docstrings immediately following the token which precedes this one

*val set\_post\_extra\_docstrings* :  **Lexing.position -\> docstring list -\> unit**

Docstrings immediately preceding the token which follows this one

### 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 -\> Parsetree.attribute**

*val add\_docs\_attrs* :  **docs -\> Parsetree.attributes -\> Parsetree.attributes**

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

*val symbol\_docs* :  **unit -\> docs**

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

*val symbol\_docs\_lazy* :  **unit -\> docs Lazy.t**

*val rhs\_docs* :  **int -\> int -\> docs**

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

*val rhs\_docs\_lazy* :  **int -\> int -\> docs Lazy.t**

*val mark\_symbol\_docs* :  **unit -\> unit**

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

*val mark\_rhs\_docs* :  **int -\> int -\> unit**

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

### 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 -\> Parsetree.attribute**

*val add\_info\_attrs* :  **info -\> Parsetree.attributes -\> Parsetree.attributes**

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

*val symbol\_info* :  **unit -\> info**

Fetch the field info for the current symbol.

*val rhs\_info* :  **int -\> info**

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

### 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 -\> Parsetree.attribute**

*val add\_text\_attrs* :  **text -\> Parsetree.attributes -\> Parsetree.attributes**

Convert text to attributes and add them to an attribute list

*val symbol\_text* :  **unit -\> text**

Fetch the text preceding the current symbol.

*val symbol\_text\_lazy* :  **unit -\> text Lazy.t**

*val rhs\_text* :  **int -\> text**

Fetch the text preceding the symbol at the given position.

*val rhs\_text\_lazy* :  **int -\> text Lazy.t**

### 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 -\> text**

Fetch additional text preceding the current symbol

*val symbol\_post\_extra\_text* :  **unit -\> text**

Fetch additional text following the current symbol

*val rhs\_pre\_extra\_text* :  **int -\> text**

Fetch additional text preceding the symbol at the given position

*val rhs\_post\_extra\_text* :  **int -\> text**

Fetch additional text following the symbol at the given position

*val rhs\_post\_text* :  **int -\> text**

Fetch text following the symbol at the given position

*module WithMenhir :* **sig end**
