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
use crate::parser::expression::{parse_expression, Expression};
use crate::parser::literals::sp;
use crate::parser::tokens::{parse_binary_operator, Operator, UnOperator};
use crate::parser::{Res, Span};
use nom::{
error::context,
sequence::{preceded, tuple},
};
#[derive(Clone, Debug, PartialEq)]
pub struct BinaryOp<'a> {
pub left: Expression<'a>,
pub right: Expression<'a>,
pub op: Operator,
}
pub(crate) fn parse_binary(input: Span) -> Res<BinaryOp> {
context(
"Binary",
tuple((
preceded(sp, parse_expression),
preceded(sp, parse_binary_operator),
preceded(sp, parse_expression),
)),
)(input)
.map(|(next_input, res)| {
(
next_input,
BinaryOp {
left: res.0,
right: res.2,
op: res.1,
},
)
})
}
#[derive(Clone, Debug, PartialEq)]
pub struct UnaryOp<'a> {
pub op: UnOperator,
pub operand: Expression<'a>,
}