formula 0.1.0

A parser and evaluator of spreadsheet-like formulas
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
use crate::{error::Error, Expr, Formula, Result, Rule};
use pest::iterators::Pairs;

impl Formula<'_> {
    pub(crate) fn get_formula(args: &mut Pairs<Rule>, rule_name: &str) -> Result<Expr> {
        Self::parse_pair(args.next().ok_or_else(|| Error::Parser(rule_name.to_owned()))?)
    }

    pub(crate) fn get_opt_formula_with_default(args: &mut Pairs<Rule>, default: Expr) -> Result<Expr> {
        args.next().map_or(Ok(default), Self::parse_pair)
    }
}