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
/// Tree-sitter-compatible parse status flags modeled as link metadata.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub struct LinkFlags {
bits: u8,
}
impl LinkFlags {
const IS_ERROR: u8 = 0b0001;
const HAS_ERROR: u8 = 0b0010;
const IS_MISSING: u8 = 0b0100;
const IS_EXTRA: u8 = 0b1000;
/// Clean link flags.
#[must_use]
pub const fn clean() -> Self {
Self { bits: 0 }
}
/// Flags for an error link.
#[must_use]
pub const fn error() -> Self {
Self {
bits: Self::IS_ERROR,
}
}
/// Flags for a link that contains an error below it.
#[must_use]
pub const fn containing_error() -> Self {
Self {
bits: Self::HAS_ERROR,
}
}
/// Flags for a missing link.
#[must_use]
pub const fn missing() -> Self {
Self {
bits: Self::IS_MISSING,
}
}
/// Flags for an extra/trivia link.
#[must_use]
pub const fn extra() -> Self {
Self {
bits: Self::IS_EXTRA,
}
}
/// Whether this link is an error link.
#[must_use]
pub const fn is_error(self) -> bool {
self.bits & Self::IS_ERROR != 0
}
/// Whether this link contains an error below it.
#[must_use]
pub const fn has_error(self) -> bool {
self.bits & Self::HAS_ERROR != 0
}
/// Whether this link is missing from the source text.
#[must_use]
pub const fn is_missing(self) -> bool {
self.bits & Self::IS_MISSING != 0
}
/// Whether this link is extra source trivia.
#[must_use]
pub const fn is_extra(self) -> bool {
self.bits & Self::IS_EXTRA != 0
}
}