use solar_ast::{
Base, StrKind,
token::{BinOpToken, Delimiter},
};
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct RawToken {
pub kind: RawTokenKind,
pub len: u32,
}
impl RawToken {
pub const EOF: Self = Self::new(RawTokenKind::Eof, 0);
#[inline]
pub const fn new(kind: RawTokenKind, len: u32) -> Self {
Self { kind, len }
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RawTokenKind {
LineComment { is_doc: bool },
BlockComment { is_doc: bool, terminated: bool },
Whitespace,
Ident,
Literal { kind: RawLiteralKind },
Eq,
Lt,
Le,
EqEq,
Ne,
Ge,
Gt,
AndAnd,
OrOr,
Not,
Tilde,
Walrus,
PlusPlus,
MinusMinus,
StarStar,
BinOp(BinOpToken),
BinOpEq(BinOpToken),
At,
Dot,
Comma,
Semi,
Colon,
Arrow,
FatArrow,
Question,
OpenDelim(Delimiter),
CloseDelim(Delimiter),
Unknown,
Eof,
}
impl RawTokenKind {
#[inline]
pub const fn is_eof(&self) -> bool {
matches!(self, Self::Eof)
}
#[inline]
pub const fn is_comment(&self) -> bool {
matches!(self, Self::LineComment { .. } | Self::BlockComment { .. })
}
#[inline]
pub const fn is_trivial(&self) -> bool {
matches!(self, Self::Whitespace | Self::LineComment { .. } | Self::BlockComment { .. })
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum RawLiteralKind {
Int { base: Base, empty_int: bool },
Rational { base: Base, empty_exponent: bool },
Str { kind: StrKind, terminated: bool },
}