titleformat_rs/
types.rs

1use std::fmt;
2use std::result;
3
4use crate::environment::Value;
5
6pub type Result = result::Result<Expr, Error>;
7
8#[derive(Debug, PartialEq)]
9pub enum Error {
10    InvalidNativeFunctionArgs(String, usize),
11    UndefinedFunction(String),
12    OutOfRange,
13    ParseError,
14}
15
16use crate::types::Error::*;
17
18impl fmt::Display for Error {
19    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
20        match *self {
21            InvalidNativeFunctionArgs(ref native_fn_name, ref actual) => {
22                write!(
23                    f,
24                    "Syntax Error: Native function '{}' called with the wrong number of arguments {}",
25                    native_fn_name,
26                    actual
27                )
28            }
29            UndefinedFunction(ref varname) => write!(f, "Undefined Function: {}", varname),
30            ParseError => write!(f, "Unable the parse the input. Please recheck."),
31            OutOfRange => write!(f, "Computed value out of range"),
32        }
33    }
34}
35
36#[derive(Clone, Debug, PartialEq)]
37pub enum Expr {
38    Literal(String),
39    Variable(String),                 /* %variable% */
40    Conditional(Vec<Expr>),           /* [expression] */
41    FuncCall(String, Vec<Vec<Expr>>), /* $func(args) */
42    ExprValue(Value),                 /* program internal value for resolved expressions */
43}