parse

Function parse 

Source
pub fn parse(input: &str) -> Result<Expr, String>
Expand description

First parse function performs a lexical analysis of the given input string to transform the input into readable tokens then a parse tree is generated from the tokens using operator-precedence parsing.

The parser uses the following grammar (EBNF):

::= | ‘+’ | ‘-’

::= | <expr ‘d’

::= | ‘+’ | ‘-’ | ‘d’

::= { } ::= ‘0’ .. ‘9’ ::= ‘1’ .. ‘9’

§Example

Basic Usage:

use droll::parser::{parse};
use droll::ast::{binary_roll_expr, binary_expr, numeric_literal, Operator};

let dice_notation = "1d20+10";
let parse_tree = parse(dice_notation).unwrap();

assert_eq!(binary_expr(binary_roll_expr(1, 20), numeric_literal(10), Operator::Plus), parse_tree);