nanoexpr 0.2.1

Fast no_std math expression parser and evaluator with zero heap allocation: formulas with variables and functions for microcontrollers, WebAssembly and C, in f32, f64, integers or calculator-exact decimals
Documentation
use nanoexpr::{Error, ErrorKind, Span};

const KINDS: [(ErrorKind, &str); 15] = [
    (ErrorKind::UnexpectedCharacter, "unexpected character"),
    (ErrorKind::UnexpectedToken, "unexpected token"),
    (ErrorKind::UnexpectedEnd, "unexpected end of expression"),
    (ErrorKind::UnclosedParenthesis, "unclosed parenthesis"),
    (ErrorKind::InvalidNumber, "invalid number"),
    (ErrorKind::UnknownVariable, "unknown variable"),
    (ErrorKind::UnknownFunction, "unknown function"),
    (ErrorKind::TooManyArguments, "too many arguments"),
    (ErrorKind::ArgumentCount, "wrong number of arguments"),
    (ErrorKind::DivisionByZero, "division by zero"),
    (ErrorKind::Domain, "operand out of domain"),
    (ErrorKind::Overflow, "overflow"),
    (ErrorKind::TooDeep, "expression nested too deeply"),
    (ErrorKind::Unsupported, "unsupported operation"),
    (ErrorKind::TooLong, "expression too long"),
];

#[test]
fn kinds_describe_themselves() {
    for (kind, description) in KINDS {
        assert_eq!(kind.description(), description);
        assert_eq!(kind.to_string(), description);
    }
}

#[test]
fn errors_display_their_span() {
    let error = Error::new(ErrorKind::Overflow, Span::new(3, 8));
    assert_eq!(error.to_string(), "overflow at 3..8");
    let source: &dyn core::error::Error = &error;
    assert!(source.source().is_none());
}