pub struct Expression<'a, T> {
pub on: T,
pub arguments: Vec<Expression<'a, T>, &'a Allocator>,
}Fields§
§on: T§arguments: Vec<Expression<'a, T>, &'a Allocator>Implementations§
Source§impl<'a, T> Expression<'a, T>where
T: Literal<'a>,
impl<'a, T> Expression<'a, T>where
T: Literal<'a>,
Sourcepub fn from_string(
source: &'a str,
config: &Configuration,
allocator: &'a Allocator,
) -> Self
pub fn from_string( source: &'a str, config: &Configuration, allocator: &'a Allocator, ) -> Self
Examples found in repository?
examples/wat.rs (line 16)
3fn main() {
4 let allocator = bumpalo::Bump::new();
5
6 let expression = "(module
7 (func (result i32)
8 (i32.const 42)
9 )
10 (export \"helloWorld\" (func 0))
11)";
12
13 let configuration = Configuration::default();
14
15 let expression: Expression<WASMValue> =
16 Expression::from_string(expression, &configuration, &allocator);
17
18 dbg!(expression);
19}More examples
examples/parse.rs (line 15)
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}examples/operations.rs (line 21)
3fn main() {
4 let multiply_operator = BinaryOperator { representation: "*", precedence: 4 };
5 let sources = &["3xy+rx", "3*x*y+r*x", "(x + t)(x + z)", "sin(-x)"];
6 let configuration = Configuration {
7 prefix_unary_operators: vec![UnaryOperator { representation: "-", precedence: 2 }],
8 binary_operators: vec![
9 BinaryOperator { representation: "^", precedence: 5 },
10 BinaryOperator { representation: "*", precedence: 4 },
11 multiply_operator,
12 BinaryOperator { representation: "+", precedence: 3 },
13 ],
14 adjacency: Some(Adjacency { operator: multiply_operator, functions: vec!["sin"] }),
15 ..Default::default()
16 };
17
18 for source in sources {
19 let allocator = bumpalo::Bump::new();
20 let expression: Expression<&str> =
21 Expression::from_string(source, &configuration, &allocator);
22 eprintln!("{expression:#?}");
23 }
24}pub fn from_reader( reader: &mut Lexer<'a>, config: &Configuration, allocator: &'a Allocator, ) -> Self
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> Freeze for Expression<'a, T>where
T: Freeze,
impl<'a, T> !RefUnwindSafe for Expression<'a, T>
impl<'a, T> !Send for Expression<'a, T>
impl<'a, T> !Sync for Expression<'a, T>
impl<'a, T> Unpin for Expression<'a, T>where
T: Unpin,
impl<'a, T> !UnwindSafe for Expression<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more