use crate::Span;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TokenKind {
LBrace,
RBrace,
LParen,
RParen,
Comma,
Gt,
At,
Tag,
BareScalar,
QuotedScalar,
RawScalar,
HeredocStart,
HeredocContent,
HeredocEnd,
LineComment,
DocComment,
Whitespace,
Newline,
Eof,
Error,
}
impl TokenKind {
pub fn is_trivia(&self) -> bool {
matches!(
self,
TokenKind::Whitespace | TokenKind::Newline | TokenKind::LineComment
)
}
pub fn is_scalar_start(&self) -> bool {
matches!(
self,
TokenKind::BareScalar
| TokenKind::QuotedScalar
| TokenKind::RawScalar
| TokenKind::HeredocStart
)
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Token<'src> {
pub kind: TokenKind,
pub span: Span,
pub text: &'src str,
}
impl<'src> Token<'src> {
pub fn new(kind: TokenKind, span: Span, text: &'src str) -> Self {
Self { kind, span, text }
}
}