Module flexi_parse::group
source · Expand description
Streams of tokens delimited by punctuation.
The core of this module is the Group type, which represents a delimited
group of tokens.
Basic usage
let group: Group<Parentheses> = parse_string("(3)".to_string()).unwrap();
let lit: LitInt = parse(group.into_token_stream()).unwrap();
assert_eq!(lit.value(), 3);The Delimiter trait
The Delimiter trait is used to provide information to Group on how to
parse the delimiters. It is typically implemented for newtype structs
wrapping a span.
Example
Below is an example of a custom set of delimiters.
struct AtDelimiters(Span);
impl From<Span> for AtDelimiters {
fn from(value: Span) -> Self {
AtDelimiters(value)
}
}
impl Delimiters for AtDelimiters {
type Start = Punct!["@"];
type End = Punct!["@"];
const CAN_NEST: bool = false;
fn span(&self) -> &Span {
&self.0
}
}
let group: Group<AtDelimiters> = parse_string("@hello@".to_string()).unwrap();
let hello: Ident = parse(group.into_token_stream()).unwrap();
assert_eq!(hello.string(), "hello");Structs
- The delimiters
<>. - The delimiters
{}. - The delimiters
[]. - The delimiters
"". - A delimited group.
- The delimiters
(). - The delimiters
''.
Traits
- A trait for types that represent the delimiters of a group.