Module

lexer.classifiers.directive

Directive classifier mixin.

Classes

DirectiveClassifierMixin 8
Mixin providing MyST-style directive classification. Handles :::{name} and ::::{name} syntax with …

Mixin providing MyST-style directive classification.

Handles :::{name} and ::::{name} syntax with nesting support.

Attributes

Name Type Description
_mode LexerMode
_directive_stack list[tuple[int, str]]

Methods

Internal Methods 6
_location_from 3 SourceLocation
Get source location from saved position. Implemented by Lexer.
def _location_from(self, start_pos: int, start_col: int | None = None, end_pos: int | None = None) -> SourceLocation
Parameters
Name Type Description
start_pos
start_col Default:None
end_pos Default:None
Returns
SourceLocation
_try_classify_directive_start 3 Iterator[Token] | None
Try to classify content as directive start. Detects :::{name} or ::::{name} sy…
def _try_classify_directive_start(self, content: str, line_start: int, indent: int = 0) -> Iterator[Token] | None

Try to classify content as directive start.

Detects :::{name} or ::::{name} syntax (MyST-style fenced directives).

Supports:

  • Nested directives via colon count (:::: > :::)
  • Named closers (:::{/name})
  • Optional title after name
Parameters
Name Type Description
content

Line content with leading whitespace stripped

line_start

Position in source where line starts

indent

Number of leading spaces (for line_indent)

Default:0
Returns
Iterator[Token] | None Iterator of tokens if valid directive, None otherwise.
_emit_directive_tokens 6 Iterator[Token]
Emit directive tokens and update state.
def _emit_directive_tokens(self, colon_count: int, name: str, title: str, is_closer: bool, line_start: int, indent: int = 0) -> Iterator[Token]
Parameters
Name Type Description
colon_count

Number of colons in the fence

name

Directive name

title

Optional title after the name

is_closer

Whether this is a named closer (:::{/name})

line_start

Position in source where line starts

indent

Number of leading spaces (for line_indent)

Default:0
Returns
Iterator[Token]
_try_classify_directive_close 3 Iterator[Token] | None
Check if content is a directive closing fence. **Valid closing:** - ::: (simpl…
def _try_classify_directive_close(self, content: str, line_start: int, indent: int = 0) -> Iterator[Token] | None

Check if content is a directive closing fence.

Valid closing:

  • ::: (simple close, 3+ colons matching or exceeding opener)
  • :::{/name} (named close)
Parameters
Name Type Description
content

Line content starting with :::

line_start

Position in source where line starts

indent

Number of leading spaces (for line_indent)

Default:0
Returns
Iterator[Token] | None Iterator of tokens if valid close, None otherwise.
_emit_directive_close 4 Iterator[Token]
Emit directive close token and update state.
def _emit_directive_close(self, colon_count: int, name: str | None, line_start: int, indent: int = 0) -> Iterator[Token]
Parameters
Name Type Description
colon_count

Number of colons in the closing fence

name

Optional directive name for named closers

line_start

Position in source where line starts

indent

Number of leading spaces (for line_indent)

Default:0
Returns
Iterator[Token]
_try_classify_directive_option 3 Token | None
Try to classify content as directive option. Format: :key: value
def _try_classify_directive_option(self, content: str, line_start: int, indent: int = 0) -> Token | None
Parameters
Name Type Description
content

Line content starting with :

line_start

Position in source where line starts

indent

Number of leading spaces (for line_indent)

Default:0
Returns
Token | None DIRECTIVE_OPTION token if valid, None otherwise.