Module grammars

Source
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§

Features
Parsing features used to configure Parse implementations.
NumGrammar
Single-type numeric grammar parameterized by the literal type.
Typed
Wrapper for Grammar types that allows to convert the type to a Parser. The resulting parser supports all Features.
Untyped
Wrapper for ParseLiteral types that allows to use them as a Grammar or Parser.
WithMockedTypes
Decorator for a grammar that mocks type parsing.

Traits§

Grammar
Extension of ParseLiteral that parses type annotations.
IntoInputSpan
Helper trait allowing Parse to accept multiple types as inputs.
MockTypes
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.
NumLiteral
Numeric literal used in NumGrammars.
Parse
Unites all necessary parsers to form a complete grammar definition.
ParseLiteral
Encapsulates parsing literals in a grammar.

Functions§

ensure_no_overlap
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§

F32Grammar
Type alias for a grammar on f32 literals.
F64Grammar
Type alias for a grammar on f64 literals.