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
//! Admin statement parsing (FLUSH).
use super::{extract_identifier, Rule};
use crate::velesql::ast::{AdminStatement, FlushStatement, Query};
use crate::velesql::error::ParseError;
use crate::velesql::Parser;
impl Parser {
/// Parses a `FLUSH [FULL] [collection]` statement.
///
/// Grammar:
/// ```text
/// FLUSH [FULL] [identifier]
/// ```
///
/// The `flush_full_kw` named rule emits a token when FULL is present,
/// allowing reliable detection via `as_rule()`. A negative lookahead
/// in the grammar prevents "fulltext" from matching as `FULL` + `text`.
///
/// Returns `Result` for `dispatch_statement()` uniformity even though
/// this variant never fails in practice.
#[allow(clippy::unnecessary_wraps)]
pub(crate) fn parse_flush_stmt(pair: pest::iterators::Pair<Rule>) -> Result<Query, ParseError> {
let mut full = false;
let mut collection: Option<String> = None;
for inner in pair.into_inner() {
match inner.as_rule() {
Rule::flush_full_kw => full = true,
Rule::identifier => collection = Some(extract_identifier(&inner)),
_ => {}
}
}
Ok(Query::new_admin(AdminStatement::Flush(FlushStatement {
full,
collection,
})))
}
}