use crate::slice_file::Location;
use std::fmt;
pub type Token<'a> = (Location, TokenKind<'a>, Location);
pub type Error<'a> = (Location, ErrorKind<'a>, Location);
#[derive(Clone, Debug)]
pub enum TokenKind<'input> {
Identifier(&'input str),
Text(&'input str),
Newline,
ParamKeyword, ReturnsKeyword, ThrowsKeyword, SeeKeyword, LinkKeyword,
LeftBrace, RightBrace, Colon, DoubleColon, }
#[derive(Clone, Debug)]
pub enum ErrorKind<'input> {
UnknownSymbol { symbol: char },
UnknownTag { tag: &'input str },
MissingTag,
UnterminatedInlineTag,
IncorrectContextForTag { tag: &'input str, is_inline: bool },
}
impl fmt::Display for ErrorKind<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::UnknownSymbol { symbol } => write!(f, "unknown symbol '{symbol}'"),
Self::UnknownTag { tag } => write!(f, "unknown doc comment tag '{tag}'"),
Self::MissingTag => f.write_str("missing doc comment tag"),
Self::UnterminatedInlineTag => f.write_str("missing a closing '}' on an inline doc comment tag"),
Self::IncorrectContextForTag { tag, is_inline } => f.write_fmt(format_args!(
"doc comment tag '{tag}' cannot be used {}",
if *is_inline { "inline" } else { "to start a block" },
)),
}
}
}