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
#[macro_use]
extern crate maplit;

#[macro_use]
extern crate lazy_static;

use crate::elements::special::Expression;
use crate::parsing::tokenizer::Tokenizer;
use crate::parsing::tree_parser::TreeParser;

pub mod elements;
pub mod format;
pub mod parsing;
pub mod tokens;
pub(crate) mod utils;

/// Parses the contents of a string into an AsciiMath expression.
///
/// This function first uses a tokenizer to parse the input string into
/// a sequence of tokens. Then it uses those tokens with the TreeParser to create
/// an Expression tree that can then be converted into MathML.
///
/// Example:
///
/// ```
/// let expression = asciimath_rs::parse("sin(2x) + 3".to_string());
/// ```
pub fn parse<S: AsRef<str>>(content: S) -> Expression {
    let mut tokenizer = Tokenizer::new(content);
    let tokens = tokenizer.parse();
    let mut tree_parser = TreeParser::new(tokens);

    tree_parser.parse()
}

#[cfg(test)]
mod tests;