1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//! Main Elemental processing library.

use std::collections::HashMap;

pub mod error;
mod tokenizer;
mod parser;
mod standard;
mod expression;
mod matrix;

pub use tokenizer::{
    Token,
    TokenClass,
    Tokenizer,
};

pub use parser::Parser;
pub use expression::Expression;
pub use matrix::Matrix;


/// Allows parselet files to easily access necessary
/// abstractions without long `use` statements.
/// 
/// For internal use only.
pub mod parselet_utils {
    pub use crate::parser::{
        Parser,
        InfixParselet,
        PrefixParselet,
    };
    pub use crate::tokenizer::{
        Token,
        Tokenizer,
        TokenClass,
    };
    pub use crate::Expression;
}


/// Interprets a `String` of code into an `Expression`.
/// 
/// Also returns a boolean value indicating whether or not the output should be displayed.
pub fn interpret(variables: &mut HashMap<String, Expression>, code: String) -> (Expression, bool) {
    // Create a token stream from the code input.
    let mut tokenizer = Tokenizer::from(code);
    let is_silent = tokenizer.chk_silent();

    // Create a parser and parse from the tokenizer.
    let parser = Parser::new();
    let expression = parser.parse(&mut tokenizer, 0);

    (expression.simplify(variables), is_silent)
}


#[test]
fn interpret_00() {
    let code = "3.1415".to_string();
    println!("{}", interpret(code));
}

#[test]
fn interpret_01() {
    let code = "x = 4".to_string();
    println!("{}", interpret(code));
}