Syntax parser

This class helps with the parsing of a single BaseMessage using its header and optionally its body content (for MessageData). A syntax describes how positional and keyword values are extracted to a dictionary that can then be used as the base values to build a Reply or an Event.

class aiostem.utils.syntax.ReplySyntax[source]

Describe the syntax of a single reply item.

Important

args_min: int

Minimum number of required positional arguments.

args_max: int

Maximum number of positional arguments.

args_map: Sequence[str | None]

List of names for the positional arguments (None to ignore it).

kwargs_map: Mapping[str | None, str]

Correspondance map for keyword arguments.

kwargs_multi: Set[str]

These KW mapping keys can hold multiple values.

flags: ReplySyntaxFlag

List of parsing flags.

parse(message: BaseMessage) Mapping[str, Sequence[str | None] | str | None][source]

Parse the provided message.

Parameters:

message (BaseMessage) – A message or sub-message to parse with this syntax.

Returns:

Mapping[str, Sequence[str | None] | str | None] – A map of parsed values.

parse_string(string: str) Mapping[str, Sequence[str | None] | str | None][source]

Parse the provided string.

Parameters:

string (str) – A plain header to parse as if it was a message header.

Returns:

Mapping[str, Sequence[str | None] | str | None] – A map of parsed values.

class aiostem.utils.syntax.ReplySyntaxFlag[source]

Bases: IntFlag

All accepted flags for a reply syntax item.

POS_REMAIN = 1

Capture everything remaining in the last positional argument.

KW_ENABLE = 16

Enable the parsing of keyword arguments.

KW_QUOTED = 32

Whether the keyword value can be enclosed with quotes.

KW_EXTRA = 64

Whether we preserve unknown keyword arguments.

KW_OMIT_KEYS = 128

Keyword arguments can omit their key.

KW_OMIT_VALS = 256

Keyword arguments can omit their value.

KW_USE_DATA = 512

Use data from MessageData as a potential KW value.

KW_RAW = 1024

No quoting or escape is performed (whole line is a value).