Skip to main content

sieve/compiler/grammar/actions/
action_keep.rs

1/*
2 * SPDX-FileCopyrightText: 2020 Stalwart Labs Ltd <hello@stalw.art>
3 *
4 * SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
5 */
6
7
8
9use crate::compiler::{
10    grammar::{
11        instruction::{CompilerState, Instruction},
12        Capability,
13    },
14    lexer::{word::Word, Token},
15    CompileError, Value,
16};
17
18#[derive(Debug, Clone, PartialEq, Eq)]
19#[cfg_attr(
20    any(test, feature = "serde"),
21    derive(serde::Serialize, serde::Deserialize)
22)]
23#[cfg_attr(
24    feature = "rkyv",
25    derive(rkyv::Serialize, rkyv::Deserialize, rkyv::Archive)
26)]
27pub(crate) struct Keep {
28    pub flags: Vec<Value>,
29}
30
31impl CompilerState<'_> {
32    pub(crate) fn parse_keep(&mut self) -> Result<(), CompileError> {
33        let cmd = Instruction::Keep(Keep {
34            flags: match self.tokens.peek().map(|r| r.map(|t| &t.token)) {
35                Some(Ok(Token::Tag(Word::Flags))) => {
36                    let token_info = self.tokens.next().unwrap().unwrap();
37                    self.validate_argument(
38                        0,
39                        Capability::Imap4Flags.into(),
40                        token_info.line_num,
41                        token_info.line_pos,
42                    )?;
43                    self.parse_strings(false)?
44                }
45                _ => Vec::new(),
46            },
47        });
48        self.instructions.push(cmd);
49        Ok(())
50    }
51}