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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
use super::super::combinator::*;
use crate::ast::*;
pub fn rel_op(input: &str) -> ParseResult<RelationOperator> {
alt((
value(RelationOperator::InstanceEqual, tag(":=:")),
value(RelationOperator::InstanceNotEqual, tag(":<>:")),
value(RelationOperator::Leq, tag("<=")),
value(RelationOperator::Geq, tag(">=")),
value(RelationOperator::Equal, tag("=")),
value(RelationOperator::NotEqual, tag("<>")),
value(RelationOperator::Lt, tag("<")),
value(RelationOperator::Gt, tag(">")),
))
.parse(input)
}
pub fn rel_op_extended(input: &str) -> ParseResult<RelationOperator> {
alt((
rel_op,
alt((
value(RelationOperator::In, tag("IN")),
value(RelationOperator::Like, tag("LIKE")),
)),
))
.parse(input)
}
pub fn unary_op(input: &str) -> ParseResult<UnaryOperator> {
alt((
value(UnaryOperator::Plus, tag("+")),
value(UnaryOperator::Minus, tag("-")),
value(UnaryOperator::Not, tag("NOT")),
))
.parse(input)
}
pub fn add_like_op(input: &str) -> ParseResult<BinaryOperator> {
use BinaryOperator::*;
alt((
value(Add, tag("+")),
value(Sub, tag("-")),
value(Or, tag("OR")),
value(Xor, tag("XOR")),
))
.parse(input)
}
pub fn multiplication_like_op(input: &str) -> ParseResult<BinaryOperator> {
alt((
value(BinaryOperator::Mul, tag("*")),
value(BinaryOperator::RealDiv, tag("/")),
value(BinaryOperator::IntegerDiv, tag("DIV")),
value(BinaryOperator::Mod, tag("MOD")),
value(BinaryOperator::And, tag("AND")),
value(BinaryOperator::ComplexEntityInstanceConstruction, tag("||")),
))
.parse(input)
}
pub fn power_op(input: &str) -> ParseResult<BinaryOperator> {
value(BinaryOperator::Power, tag("**")).parse(input)
}
pub fn interval_op(input: &str) -> ParseResult<IntervalOperator> {
alt((
value(IntervalOperator::LessThanEqual, tag("<=")),
value(IntervalOperator::LessThan, tag("<")),
))
.parse(input)
}
#[cfg(test)]
mod tests {
use nom::Finish;
#[test]
fn rel_op() {
let (res, (op, _remarks)) = super::rel_op("<=").finish().unwrap();
dbg!(op);
assert_eq!(res, "");
}
}