pomsky_syntax/exprs/
boundary.rs1use crate::Span;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
14#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
15pub struct Boundary {
16 pub kind: BoundaryKind,
17 pub unicode_aware: bool,
18 pub span: Span,
19}
20
21impl Boundary {
22 pub fn new(kind: BoundaryKind, unicode_aware: bool, span: Span) -> Self {
23 Boundary { kind, unicode_aware, span }
24 }
25
26 pub fn kind(&self) -> BoundaryKind {
27 self.kind
28 }
29
30 #[cfg(feature = "dbg")]
31 pub(super) fn pretty_print(&self, buf: &mut crate::PrettyPrinter) {
32 match self.kind {
33 BoundaryKind::Start => buf.push('^'),
34 BoundaryKind::End => buf.push('$'),
35 BoundaryKind::Word => buf.push('%'),
36 BoundaryKind::NotWord => buf.push_str("!%"),
37 BoundaryKind::WordStart => buf.push_str("<"),
38 BoundaryKind::WordEnd => buf.push_str(">"),
39 }
40 }
41}
42
43#[derive(Debug, Clone, Copy, PartialEq, Eq)]
44#[cfg_attr(feature = "arbitrary", derive(arbitrary::Arbitrary))]
45pub enum BoundaryKind {
46 Start,
48 End,
50 Word,
52 NotWord,
54 WordStart,
56 WordEnd,
58}