myst_parser.parsers.options#

Parser for directive options.

This is a highly restricted parser for YAML, which only allows a subset of YAML to be used for directive options:

  • Only block mappings are allowed at the top level

  • Mapping keys are parsed as strings (plain or quoted)

  • Mapping values are parsed as strings (plain, quoted, literal |, folded >)

  • # Comments are allowed and blank lines

Adapted from: yaml/pyyaml

For a good description of multi-line YAML strings, see: https://stackoverflow.com/a/21699210/5033292

1.  Module Contents#

1.1.  Classes#

Position

Position of a character in a stream.

StreamBuffer

A buffer for a stream of characters.

Token

A parsed token from a directive option stream.

KeyToken

ValueToken

ColonToken

State

1.2.  Functions#

options_to_items

Parse a directive option block into (key, value) tuples.

1.3.  API#

class myst_parser.parsers.options.Position[源代码]#

Position of a character in a stream.

index: int = None#
line: int = None#
column: int = None#
class myst_parser.parsers.options.StreamBuffer(stream: str)[源代码]#

A buffer for a stream of characters.

Initialization

property index: int#
property line: int#
property column: int#
peek(index: int = 0) str[源代码]#
prefix(length: int = 1) str[源代码]#
forward(length: int = 1) None[源代码]#
get_position() myst_parser.parsers.options.Position[源代码]#
class myst_parser.parsers.options.Token[源代码]#

A parsed token from a directive option stream.

id: ClassVar[str] = '<unknown>'#
start: myst_parser.parsers.options.Position = None#
end: myst_parser.parsers.options.Position = None#
class myst_parser.parsers.options.KeyToken[源代码]#

Bases: myst_parser.parsers.options.Token

id: ClassVar[str] = '<key>'#
value: str = None#
style: Literal[None, ', "] = None#

The original style of the string.

class myst_parser.parsers.options.ValueToken[源代码]#

Bases: myst_parser.parsers.options.Token

id: ClassVar[str] = '<value>'#
value: str = None#
style: Literal[None, ', ", |, >] = None#

The original style of the string.

class myst_parser.parsers.options.ColonToken[源代码]#

Bases: myst_parser.parsers.options.Token

id: ClassVar[str] = '<colon>'#
exception myst_parser.parsers.options.TokenizeError(problem: str, problem_mark: myst_parser.parsers.options.Position, context: str | None = None, context_mark: myst_parser.parsers.options.Position | None = None)[源代码]#

Bases: Exception

clone(line_offset: int, column_offset: int) myst_parser.parsers.options.TokenizeError[源代码]#

Clone the error with the given line and column offsets.

class myst_parser.parsers.options.State[源代码]#
has_comments: bool = False#
myst_parser.parsers.options.options_to_items(text: str, line_offset: int = 0, column_offset: int = 0) tuple[list[tuple[str, str]], myst_parser.parsers.options.State][源代码]#

Parse a directive option block into (key, value) tuples.

参数:
  • text -- The directive option text.

  • line_offset -- The line offset to apply to the error positions.

  • column_offset -- The column offset to apply to the error positions.

Raises:

TokenizeError