parse/
parse.rs

1use general_parser::{BinaryOperator, Configuration, Expression};
2
3fn main() {
4	let configuration = Configuration {
5		binary_operators: vec![
6			BinaryOperator { representation: "*", precedence: 4 },
7			BinaryOperator { representation: "+", precedence: 3 },
8		],
9		..Default::default()
10	};
11
12	if let Some(source) = std::env::args().nth(1) {
13		let allocator = bumpalo::Bump::new();
14		let expression: Expression<&str> =
15			Expression::from_string(&source, &configuration, &allocator);
16		eprintln!("{expression:#?}");
17	} else {
18		let sources: &[&str] = &["(x (a * b) (d * 2 + e))", "(x (a b) (c d e))"];
19
20		for source in sources {
21			let allocator = bumpalo::Bump::new();
22			let expression: Expression<&str> =
23				Expression::from_string(source, &configuration, &allocator);
24			eprintln!("{expression:#?}");
25		}
26	}
27}