Expand description

Grammar functionality and a collection of standard grammars.

Defining grammars

To define a Grammar, you’ll need a ParseLiteral implementation, which defines how literals are parsed (numbers, strings, chars, hex- / base64-encoded byte sequences, etc.). There are standard impls for floating-point number parsing and the complex numbers (if the relevant feature is on).

You may define how to parse type annotations by implementing Grammar explicitly. Alternatively, if you don’t need type annotations, a Grammar can be obtained from a ParseLiteral impl by wrapping it into Untyped.

Once you have a Grammar, you can supply it as a Base for Parse. Parse methods allow to parse complete or streaming Blocks of statements. Note that Untyped and Typed wrappers allow to avoid an explicit Parse impl.

See ParseLiteral, Grammar and Parse docs for the examples of various grammar definitions.

Structs

Traits

  • Extension of ParseLiteral that parses type annotations.
  • Helper trait allowing Parse to accept multiple types as inputs.
  • Trait allowing to mock out type annotation support together with WithMockedTypes. It specifies recognized type annotations; if any other annotation is used, an error will be raised.
  • Numeric literal used in NumGrammars.
  • Unites all necessary parsers to form a complete grammar definition.
  • Encapsulates parsing literals in a grammar.

Functions

  • Ensures that the child parser does not consume a part of a larger expression by rejecting if the part following the input is an alphanumeric char or _.

Type Aliases

  • Type alias for a grammar on f32 literals.
  • Type alias for a grammar on f64 literals.