pub trait Evaluate<T> {
// Required method
fn evaluate<'a>(&mut self, statement: &[Data<'a>]) -> T;
// Provided methods
fn interpret_single(&mut self, statement: &str) -> Result<T, ParseError> { ... }
fn interpret_multiple(&mut self, code: &str) -> Result<T, ParseError> { ... }
}
Expand description
Interpreter trait
Central trait to add the interpreter to your custom evaluator
Required Methods§
Provided Methods§
sourcefn interpret_single(&mut self, statement: &str) -> Result<T, ParseError>
fn interpret_single(&mut self, statement: &str) -> Result<T, ParseError>
Set up the parser and call evaluate on the result
This method expects 1 single statement, that is, it doesn’t take in a bunch of separate statements, but rather one single whole statement, even if it contains newlines, which are considered whitespace and skipped.
sourcefn interpret_multiple(&mut self, code: &str) -> Result<T, ParseError>
fn interpret_multiple(&mut self, code: &str) -> Result<T, ParseError>
Interpret several statements one-by-one
When calling this function, it will interpret
each individual statement,
Normally, this happens when a newline is found. If however that same line contains
an unclosed opening parenthesis, we will need to include some lines coming after this one
in order to complete the statement.