Trait gameshell::Evaluate

source ·
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§

source

fn evaluate<'a>(&mut self, statement: &[Data<'a>]) -> T

Evaluate a single statement

Statements are line-separated pieces of code turned into fixed data segments. See interpret_single and interpret_multiple on how to parse statements.

Provided Methods§

source

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.

source

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.

Implementors§

source§

impl<'a, C> Evaluate<Result<String, String>> for Evaluator<'a, C>