Crate lexper

Crate lexper 

Source
Expand description

Simple expression evaluation crate with custom lexer and parser. Currently doesn’t have support for a factorial, but this feature is in TODO list.

let result = lexper::eval("sin(2) + 20^2").unwrap();
assert_eq!(f64::round(result), 401.0);

Re-exports§

pub use error::Error;

Modules§

error

Macros§

eval
Simple macro to insert variables into an expression in compile-time via format! macro

Structs§

Interpreter
Lexer
This struct is responsible for “turning” source string into a list of tokens
Tokens makes sense only for the Parser struct
Parser
The heart struct of the lexper. It parses the token vector into a nested AST of Expressions.
Token
Represents some valuable information for our Parser, operators, literals etc.

Enums§

Expression
Expression type, represents… an expression.
It could be everything, from just a number like 2 till a function call
OperatorType
Type introduced to avoid pasting a lot of types into TokenType, operators moved to a sub-enum, here it is.
TokenType
The token type, literal, operator, parenthesis etc.

Functions§

eval