Expand description
This module contains the fundamental parsers. These are the basic tokens from
proc_macro2/proc_macro
and a few other ones defined by unsynn. These are the terminal entities when parsing tokens.
Being able to parse TokenTree and TokenStream allows one to parse opaque entities where
internal details are left out. The Cached type is used to cache the string representation
of the parsed entity. The Nothing type is used to match without consuming any tokens.
The Except type is used to match when the next token does not match the given type.
The EndOfStream type is used to match the end of the stream when no tokens are left.
The HiddenState type is used to hold additional information that is not part of the parsed syntax.
Note: When the proc_macro2 feature is disabled, format macros (format_ident!,
format_literal!) are unavailable, but Cached<T> remains fully functional using
.to_string() from proc_macro types.
Structs§
- Cached
- Getting the underlying string expensive as it always allocates a new
String. This type caches the string representation of a given entity. Note that this is only reliable for fundamental entities that represent a single token. Spacing between composed tokens is not stable and should be considered informal only. - EndOf
Stream - Matches the end of the stream when no tokens are left.
- Except
- Succeeds when the next token does not match
T. Will not consume any tokens. Usually this has to be followed with a conjunctive match such asCons<Except<T>, U>or followed by another entry in a struct or tuple. - Expect
- Succeeds when the next token would match
T. Will not consume any tokens. This is similar to peeking. - Group
- A delimited token stream.
- Hidden
State - Sometimes one want to compose types or create structures for unsynn that have members that
are not part of the parsed syntax but add some additional information. This struct can be
used to hold such members while still using the
ParserandToTokenstrait implementations automatically generated by the [unsynn!{}] macro or composition syntax.HiddenStatewill not consume any tokens when parsing and will not emit any tokens when generating aTokenStream. On parsing it is initialized with a default value. It hasDerefandDerefMutimplemented to access the inner value. - Ident
- A word of Rust code, which may be a keyword or legal variable name.
- Invalid
- A unit that always fails to match. This is useful as default for generics.
See how
Either<A, B, C, D>uses this for unused alternatives. - Literal
- A literal string (
"hello"), byte string (b"hello"), character ('a'), byte character (b'a'), an integer or floating point number with or without a suffix (1,1u8,2.3,2.3f32). - NonEmpty
Token Stream - Since parsing a
TokenStreamsucceeds even when no tokens are left, this type is used to parse aTokenStreamthat is not empty. - NonParseable
- A unit that can not be parsed. This is useful as diagnostic placeholder for parsers that
are (yet) unimplemented. The
nonparseablefeature flag controls ifParserandToTokenswill be implemented for it. This is useful in release builds that should not have anyNonParseableleft behind. - Nothing
- A unit that always matches without consuming any tokens. This is required when one wants
to parse a
Repeatswithout a delimiter. Note that usingNothingas primary entity in aVec,LazyVec,DelimitedVecorRepeatswill result in an infinite loop. - Punct
- A
Punctis a single punctuation character like+,-or#. - Token
Stream - An abstract stream of tokens, or more concretely a sequence of token trees.
Enums§
- Token
Tree - A single token or a delimited sequence of token trees (e.g.
[1, (), ..]).
Type Aliases§
- Cached
Group Groupwith cached string representation.- Cached
Ident Identwith cached string representation.- Cached
Literal Literalwith cached string representation.- Cached
Literal Integer LiteralIntegerwith cached string representation.- Cached
Literal String LiteralStringwith cached string representation.- Cached
Punct Punctwith cached string representation.- Cached
Token Tree TokenTree(any token) with cached string representation.