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
Parseimplementations. - NumGrammar
- Single-type numeric grammar parameterized by the literal type.
- Typed
- Wrapper for
Grammartypes that allows to convert the type to aParser. The resulting parser supports allFeatures. - Untyped
- Wrapper for
ParseLiteraltypes that allows to use them as aGrammarorParser. - With
Mocked Types - Decorator for a grammar that mocks type parsing.
Traits§
- Grammar
- Extension of
ParseLiteralthat parses type annotations. - Into
Input Span - Helper trait allowing
Parseto accept multiple types as inputs. - Mock
Types - 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.
- Parse
Literal - 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
f32literals. - F64Grammar
- Type alias for a grammar on
f64literals.