Skip to content

pmc_parser

Parser for PMC (PTP Management Client) text output.

Classes:

  • ParseError

    Represents a parse failure with trace information.

  • Some

    Type representing a value in an option-like pattern.

Functions:

  • abbreviate

    Abbreviate long text for debug output.

  • consume

    Consume and parse a value of the given type from text.

  • indent

    Indent a message for debug logging.

  • parse

    Parse PMC output text into a list of messages.

  • parse_class_from_regex

    Parse a dataclass from string using its regex attribute.

  • parse_float

    Parse a float from string, supporting hex and decimal floats.

  • parse_int

    Parse an int from string, supporting hex and decimal ints.

ParseError dataclass

ParseError(trace: list[str], rest: str)

Represents a parse failure with trace information.

Attributes:

  • trace (list[str]) –

    Stack of parser contexts where the error occurred.

  • rest (str) –

    Remaining unparsed text.

Some dataclass

Some(x: Any)

Type representing a value in an option-like pattern.

Example
result: Some | None = Some(42)
match result:
    case Some(x):
        print(f"Got value: {x}")
    case None:
        print("No value")

Attributes:

  • x (Any) –

    The parsed value.

abbreviate

abbreviate(text: str)

Abbreviate long text for debug output.

consume

consume(
    typ, text: str, logger: Logger, level=0
) -> tuple[Some, str] | ParseError

Consume and parse a value of the given type from text.

indent

indent(msg: str, level: int)

Indent a message for debug logging.

parse

parse(
    text: str, logger: Logger | None = None
) -> list[Message]

Parse PMC output text into a list of messages.

Parameters:

  • text (str) –

    Raw PMC output text to parse.

  • logger (Logger | None, default: None ) –

    Optional logger for debug output.

Returns:

  • list[Message]

    List of parsed Message objects.

parse_class_from_regex

parse_class_from_regex(
    typ, string: str, logger: Logger, level: int
)

Parse a dataclass from string using its regex attribute.

parse_float

parse_float(string: str)

Parse a float from string, supporting hex and decimal floats.

parse_int

parse_int(string: str)

Parse an int from string, supporting hex and decimal ints.