Expand description
Recursive-descent RST parser with docutils-0.22.4 fidelity (M2 wave 1: block grammar only — the inline parser arrives in wave 2).
Fidelity contract: output pformat() is byte-identical to
docutils.parsers.rst.Parser parse-layer output for the construct set in
tests/fixtures/doctree_differential.json. Transforms (doctitle
promotion, target propagation, transition hoisting, message filtering)
are explicitly NOT applied here; they arrive as separate components in
later waves. Behavior sources: the committed differential fixture and the
probe notes in docs/superpowers/plans/2026-08-07-m2-wave1-probes.md.
Modules§
- inline
- The inline parser (M2 wave 2): a port of docutils
states.py Inlinerfor emphasis/strong/literal recognition, escape semantics, and the problematic/unclosed machinery. References, roles, and footnote references extend this module in later wave-2 tasks. - lines
- Line preprocessing: docutils
statemachine.string2lines(tab_width=8, convert_whitespace=True)equivalent, producing the parser’s line stream as index-basedLineRecrecords over a processed source text.
Structs§
- Directive
Record - Pre-conversion directive tuple mirroring the M1 validation scanner’s
semantics (whitespace-split args, inline-admonition content routing,
raw string options) — the feed for
DirectiveValidationSystem. - Object
Registration - One
StandardDomain.note_objectcall the parse layer made (GenericObject/ConfigurationValue.add_target_and_index). - Parse
LogWarning - One
logger.warninga directive raised during the parse. - Parse
Options - Parse
Output - Everything a parse produces: the doctree plus the flat records the build pipeline consumes without re-walking raw source.
- Program
Option Record - One
Cmdoption.add_target_and_indexcall the parse layer made (sphinx/domains/std/__init__.py:308-315). - PyModule
Record - One
PythonDomain.note_modulecall (PyModule.run,domains/python/__init__.py:515-521) — the modname →ModuleEntryregistration feeding the env layer and, later, the py-modindex. - PyObject
Record - One
PythonDomain.note_objectcall the parse layer made (PyObject.add_target_and_index,domains/python/_object.py:415-437, orPyModule.run,__init__.py:522) — the fullname →ObjectEntryregistration the env layer replays, plus the provenance the duplicate-description warning needs. - Registry
Export - What the parse layer hands the environment besides the doctree itself:
state that lives in the parser (the docutils id/name registry, Sphinx’s
env.ref_context) and dies with it, but that env collectors need. - Role
Record - A role occurrence (sphinx mode): validation + nitpicky feed.
- Toctree
Entry Record - Toctree
Record - A toctree directive occurrence (sphinx mode).
Constants§
- DEFAULT_
SOURCE_ ENCODING - Sphinx’s default
source_encoding(config.py:244).
Functions§
- parse_
rst - Parse RST source into a doctree. Total: never panics, never errors —
problems become
system_messagenodes, exactly like docutils. - parse_
rst_ full