Skip to main content

omena_parser/
recovery.rs

1//! Recovery token sets used by the parser.
2//!
3//! These constants define the public recovery policy for top-level, selector,
4//! and declaration parsing entry points.
5
6use omena_syntax::SyntaxKind;
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq)]
9pub struct TokenSet {
10    kinds: &'static [SyntaxKind],
11}
12
13impl TokenSet {
14    pub const fn new(kinds: &'static [SyntaxKind]) -> Self {
15        Self { kinds }
16    }
17
18    pub fn contains(self, kind: SyntaxKind) -> bool {
19        self.kinds.contains(&kind)
20    }
21
22    pub fn len(self) -> usize {
23        self.kinds.len()
24    }
25
26    pub fn is_empty(self) -> bool {
27        self.kinds.is_empty()
28    }
29}
30
31pub const RECOVERY_TOP: TokenSet = TokenSet::new(&[
32    SyntaxKind::AtKeyword,
33    SyntaxKind::Dot,
34    SyntaxKind::Hash,
35    SyntaxKind::RightBrace,
36    SyntaxKind::Semicolon,
37]);
38
39pub const RECOVERY_DECLARATION: TokenSet =
40    TokenSet::new(&[SyntaxKind::Semicolon, SyntaxKind::RightBrace]);
41
42pub const RECOVERY_SELECTOR: TokenSet = TokenSet::new(&[
43    SyntaxKind::Comma,
44    SyntaxKind::LeftBrace,
45    SyntaxKind::RightBrace,
46]);