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::*;

/// 282 rel_op = `<` | `>` | `<=` | `>=` | `<>` | `=` | `:<>:` | `:=:` .
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)
}

/// 283 rel_op_extended = [rel_op] | `IN` | `LIKE` .
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)
}

/// 331 unary_op = `+` | `-` | `NOT` .
pub fn unary_op(input: &str) -> ParseResult<UnaryOperator> {
    alt((
        value(UnaryOperator::Plus, tag("+")),
        value(UnaryOperator::Minus, tag("-")),
        value(UnaryOperator::Not, tag("NOT")),
    ))
    .parse(input)
}

/// 168 add_like_op = `+` | `-` | `OR` | `XOR` .
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)
}

/// 257 multiplication_like_op = `*` | `/` | `DIV` | `MOD` | `AND` | `||` .
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)
}

/// 999 power_op = `**`
///
/// Additional trivial rule for managing operators uniformly
pub fn power_op(input: &str) -> ParseResult<BinaryOperator> {
    value(BinaryOperator::Power, tag("**")).parse(input)
}

/// 247 interval_op = `<` | `<=` .
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, "");
    }
}