Struct flexi_parse::group::Group
source · pub struct Group<D> { /* private fields */ }
Expand description
A delimited group.
For more information, see the module documentation.
Implementations§
source§impl<D: Delimiters> Group<D>
impl<D: Delimiters> Group<D>
sourcepub fn into_token_stream(self) -> TokenStream
pub fn into_token_stream(self) -> TokenStream
Returns the contained TokenStream
.
Examples found in repository?
examples/calc.rs (line 89)
81 82 83 84 85 86 87 88 89 90 91 92 93
fn primary(input: ParseStream) -> Result<Expr> {
let lookahead = input.lookahead();
if lookahead.peek(token::LitFloat) {
Ok(Expr::Num(input.parse::<token::LitFloat>()?.value()))
} else if lookahead.peek(token::LitInt) {
Ok(Expr::Num(input.parse::<token::LitInt>()?.value() as f64))
} else if lookahead.peek(token::LeftParen) {
let group: Group<Parentheses> = input.parse()?;
parse(group.into_token_stream())
} else {
Err(lookahead.error())
}
}
More examples
examples/lox/main.rs (line 438)
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
fn parse(input: ParseStream) -> Result<Self> {
let name: Ident = input.parse()?;
let mut contents: Group<Parentheses> = input.parse()?;
contents.remove_whitespace();
let Parentheses(span) = contents.delimiters();
let tokens = contents.into_token_stream();
let params: Vec<Ident> = if tokens.is_empty() {
vec![]
} else {
let params: Punctuated<Ident, Punct![","]> =
Punctuated::parse_separated.parse(tokens)?;
params.into_iter().collect()
};
if params.len() >= 255 {
input.add_error(input.new_error(
"Can't have more than 254 parameters".to_string(),
span,
error_codes::TOO_MANY_ARGS,
));
}
let mut contents: Group<Braces> = input.parse()?;
contents.remove_whitespace();
let body = block.parse(contents.into_token_stream())?;
Ok(Function { name, params, body })
}
sourcepub fn delimiters(&self) -> D
pub fn delimiters(&self) -> D
Returns a token representing the delimiters of this group.
Examples found in repository?
examples/lox/main.rs (line 437)
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
fn parse(input: ParseStream) -> Result<Self> {
let name: Ident = input.parse()?;
let mut contents: Group<Parentheses> = input.parse()?;
contents.remove_whitespace();
let Parentheses(span) = contents.delimiters();
let tokens = contents.into_token_stream();
let params: Vec<Ident> = if tokens.is_empty() {
vec![]
} else {
let params: Punctuated<Ident, Punct![","]> =
Punctuated::parse_separated.parse(tokens)?;
params.into_iter().collect()
};
if params.len() >= 255 {
input.add_error(input.new_error(
"Can't have more than 254 parameters".to_string(),
span,
error_codes::TOO_MANY_ARGS,
));
}
let mut contents: Group<Braces> = input.parse()?;
contents.remove_whitespace();
let body = block.parse(contents.into_token_stream())?;
Ok(Function { name, params, body })
}
sourcepub fn remove_whitespace(&mut self)
pub fn remove_whitespace(&mut self)
Removes all whitespace from the TokenStream
in self
.
Examples found in repository?
examples/lox/main.rs (line 436)
433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
fn parse(input: ParseStream) -> Result<Self> {
let name: Ident = input.parse()?;
let mut contents: Group<Parentheses> = input.parse()?;
contents.remove_whitespace();
let Parentheses(span) = contents.delimiters();
let tokens = contents.into_token_stream();
let params: Vec<Ident> = if tokens.is_empty() {
vec![]
} else {
let params: Punctuated<Ident, Punct![","]> =
Punctuated::parse_separated.parse(tokens)?;
params.into_iter().collect()
};
if params.len() >= 255 {
input.add_error(input.new_error(
"Can't have more than 254 parameters".to_string(),
span,
error_codes::TOO_MANY_ARGS,
));
}
let mut contents: Group<Braces> = input.parse()?;
contents.remove_whitespace();
let body = block.parse(contents.into_token_stream())?;
Ok(Function { name, params, body })
}
sourcepub fn without_whitespace(self) -> Group<D>
pub fn without_whitespace(self) -> Group<D>
Consumes self
, returning a new Group<D>
with all whitespace
removed.
Trait Implementations§
source§impl<D: Delimiters> Parse for Group<D>
impl<D: Delimiters> Parse for Group<D>
source§impl<D> PartialEq for Group<D>
impl<D> PartialEq for Group<D>
source§impl<D> PartialOrd for Group<D>
impl<D> PartialOrd for Group<D>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<D> Eq for Group<D>
Auto Trait Implementations§
impl<D> RefUnwindSafe for Group<D>where
D: RefUnwindSafe,
impl<D> Send for Group<D>where
D: Send,
impl<D> Sync for Group<D>where
D: Sync,
impl<D> Unpin for Group<D>where
D: Unpin,
impl<D> UnwindSafe for Group<D>where
D: UnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more