pub trait ParseIt {
type Lexer<'a>: Lexer<'a>;
type Output;
// Required method
fn parse_stream(
&self,
state: &ParserState<Self::Lexer<'_>>,
) -> Result<Self::Output, Error>;
// Provided method
fn parse(&self, input: &str) -> Result<Self::Output, Error> { ... }
}Expand description
A parser.
Required Associated Types§
Required Methods§
Sourcefn parse_stream(
&self,
state: &ParserState<Self::Lexer<'_>>,
) -> Result<Self::Output, Error>
fn parse_stream( &self, state: &ParserState<Self::Lexer<'_>>, ) -> Result<Self::Output, Error>
Parse from a ParserState.
Provided Methods§
Sourcefn parse(&self, input: &str) -> Result<Self::Output, Error>
fn parse(&self, input: &str) -> Result<Self::Output, Error>
Parse from a string.
Examples found in repository?
More examples
examples/calc.rs (line 50)
45fn main() {
46 let parser = parse::Expr::default();
47
48 let input = "11+(6-1-1)*(4/2/2)";
49
50 let result = match parser.parse(input) {
51 Ok(value) => value,
52 Err(err) => {
53 println!("span: {}..{}", err.span.start, err.span.end);
54 return;
55 }
56 };
57
58 println!("parser: {}", result);
59 assert_eq!(result, 15);
60}Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.