API reference

Parsing functions

These functions are intended as the main entry points to parsing something with a grammar defined with the Parser combinators. All parsing functions can also be directly imported from the bite package.

parse_functions.parse_bytes(grammar, data, *)

Parse an in-memory bytes object.

parse_functions.parse_incremental(grammar, ...)

Parse bytes from an asynchronous stream incrementally.

Parser combinators

These classes can be combined to create the desired parser for a given grammar. All parser combinators can also be directly imported from the bite package.

Parsing concrete bytes

parsers.CaselessLiteral

Parses a case-insensitive sequence of bytes.

parsers.CharacterSet

Parses a single byte from a given set.

parsers.FixedByteCount

Parses a fixed number of bytes.

parsers.Literal

Parses an exact sequence of bytes.

Combining parsers

Parser instances can also be combined with the following operators:

  • + (And): Apply parsers in sequence.

  • | (MatchFirst): Apply the first parser that succeeds parsing the input.

  • ~ (Not): Negative look-ahead.

parsers.And

Apply multiple parsers in sequence.

parsers.Combine

Combine parse tree leaves into a single node.

parsers.Forward

Forward declaration allowing the definition of recursive rules.

parsers.MatchFirst

Apply the first parser that succeeds parsing the input.

parsers.Not

Negative look-ahead.

Repetition of parsers

Repetition of a parser instance can also be declared with indexing/bracket notation as parser[x, y]. `` x`` must be a non-negative integer. y must be either a positive integer or the ellipsis ... to allow for unlimited repetitions.

parsers.Counted

Read a count and create a parser from it.

parsers.OneOrMore

Require a parser to apply one or more times.

parsers.Opt

Make a parser optional.

parsers.Repeat

Apply a parser repeatedly.

parsers.ZeroOrMore

Require a parser to apply zero or more times.

Transforming parsed values

transformers.Group

Group the values of a resulting parse tree node into a tuple.

transformers.Suppress

Suppresses a parse tree from the values.

transformers.Transform

Transform a resulting parse tree node to produce different values.

transformers.TransformValues

Transform parsed values.

Parse tree nodes

These classes define the structure of the parse tree returned from a parser. The general protocol of these classes is given by parsers.ParsedNode. Besides the fundamental class listed here, many parsers define their specialized implemenations.

parsers.ParsedLeaf

A leaf node in a parse tree.

parsers.ParsedNil

A leaf node in a parse tree representing a zero-length segment.

parsers.ParsedNode

A single node in a parse tree.

Module reference