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
93
94
95
96
97
98
99
100
//! The IS-introduced predicate production shared by the general
//! comparison grammar and the simple-CASE `WHEN IS ...` operand.
use super::*;
impl<'a> Parser<'a> {
/// The IS-introduced predicate forms the general grammar and a simple
/// CASE `WHEN IS ...` operand share (`IS` and any `NOT` already
/// consumed): chronological comparison, `:: <type>`, `TYPED <type>`,
/// `[<normal form>] NORMALIZED` and `NULL`. Hands `operand` back as
/// `Err` when the next token starts none of them, so the caller can
/// apply its own label-predicate tail.
pub(super) fn parse_is_predicate_common(
&mut self,
operand: Expr,
negated: bool,
) -> ParseResult<Result<Expr, Expr>> {
if let Some(op) = self.peek_chronological_op() {
// a IS [NOT] BEFORE | AFTER | SAME INSTANT | SAME
// REPRESENTATION b (Cypher 25 chronological comparison; the
// four words are contextual identifiers, not reserved).
self.consume_chronological_op(op);
let right = self.parse_add_sub()?;
return Ok(Ok(Expr::ChronologicalCompare(Box::new(
ChronologicalCompareExpr {
left: operand,
op,
right,
negated,
},
))));
}
if self.peek_type() == TokenType::DoubleColon || self.peek_is_typed_keyword() {
// IS [NOT] :: <value type> | IS [NOT] TYPED <value type>
// (type predicate)
self.next_token();
let type_expr = self.parse_value_type()?;
return Ok(Ok(Expr::IsType(Box::new(IsTypeExpr {
expr: operand,
type_expr,
negated,
}))));
}
if self.peek_is_normal_form_or_normalized() {
// IS [NOT] [<normal form>] NORMALIZED
let form = self.try_consume_normal_form_keyword();
self.expect_keyword_ident("NORMALIZED")?;
return Ok(Ok(Expr::IsNormalized(Box::new(IsNormalizedExpr {
expr: operand,
form,
negated,
}))));
}
if self.peek_type() == TokenType::NULL {
// IS [NOT] NULL
self.next_token();
return Ok(Ok(Expr::IsNull(Box::new(IsNullExpr {
expr: operand,
negated,
}))));
}
Ok(Err(operand))
}
/// The general grammar's tail for an `IS [NOT]` suffix that is none of
/// [`Self::parse_is_predicate_common`]'s forms: `LABELED <label-expr>`
/// (strict), a bare `<label-expr>` (`IS NOT <label-expr>` is the
/// shorthand for `IS NOT LABELED`), else the missing-`NULL`
/// error.
pub(super) fn parse_is_label_tail(
&mut self,
operand: Expr,
negated: bool,
) -> ParseResult<Expr> {
if self.peek_is_labeled_keyword() {
self.next_token();
let label_expr = self.parse_label_expr_body(true, false)?.expr;
return Ok(Expr::HasLabel(Box::new(HasLabelExpr {
expr: operand,
label_expr,
negated,
strict: true,
})));
}
if self.peek_can_start_label_expr() {
let label_expr = self.parse_label_expr_body(true, false)?.expr;
return Ok(Expr::HasLabel(Box::new(HasLabelExpr {
expr: operand,
label_expr,
negated,
strict: negated,
})));
}
self.expect(TokenType::NULL)?;
Ok(Expr::IsNull(Box::new(IsNullExpr {
expr: operand,
negated,
})))
}
}