pub fn parse<T: Parse>(tokens: TokenStream) -> Result<T>
Expand description
Parses the given tokens into the syntax tree node T
.
This function ignores all whitespace.
ยงErrors
Forwards any error from T::parse
.
Examples found in repository?
examples/calc.rs (line 89)
81fn primary(input: ParseStream) -> Result<Expr> {
82 let lookahead = input.lookahead();
83 if lookahead.peek(token::LitFloat) {
84 Ok(Expr::Num(input.parse::<token::LitFloat>()?.value()))
85 } else if lookahead.peek(token::LitInt) {
86 Ok(Expr::Num(input.parse::<token::LitInt>()?.value() as f64))
87 } else if lookahead.peek(token::LeftParen) {
88 let group: Group<Parentheses> = input.parse()?;
89 parse(group.into_token_stream())
90 } else {
91 Err(lookahead.error())
92 }
93}