#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ParserDiagnosticKind {
NotAJSDocBlock,
UnclosedBlockComment,
SpanOverflow,
UnclosedInlineTag,
UnclosedTypeExpression,
UnclosedFence,
InvalidTagStart,
InvalidInlineTagStart,
}
#[must_use]
pub const fn parser_diagnostic_message(kind: ParserDiagnosticKind) -> &'static str {
match kind {
ParserDiagnosticKind::NotAJSDocBlock => "input is not a JSDoc block comment",
ParserDiagnosticKind::UnclosedBlockComment => "JSDoc block comment is not closed",
ParserDiagnosticKind::SpanOverflow => "JSDoc comment span exceeds u32 byte offset range",
ParserDiagnosticKind::UnclosedInlineTag => "inline tag is not closed",
ParserDiagnosticKind::UnclosedTypeExpression => "type expression is not closed",
ParserDiagnosticKind::UnclosedFence => "fenced code block is not closed",
ParserDiagnosticKind::InvalidTagStart => "invalid block tag start",
ParserDiagnosticKind::InvalidInlineTagStart => "invalid inline tag start",
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TypeDiagnosticKind {
NoParsletFound,
ExpectedToken,
UnclosedGeneric,
UnclosedParenthesis,
UnclosedTuple,
UnclosedObject,
UnclosedTemplateLiteral,
InvalidTypeExpression,
EarlyEndOfParse,
}
#[must_use]
pub const fn type_diagnostic_message(kind: TypeDiagnosticKind) -> &'static str {
match kind {
TypeDiagnosticKind::NoParsletFound => "unexpected token in type expression",
TypeDiagnosticKind::ExpectedToken => "expected token in type expression",
TypeDiagnosticKind::UnclosedGeneric => "generic type parameter list is not closed",
TypeDiagnosticKind::UnclosedParenthesis => "parenthesized type is not closed",
TypeDiagnosticKind::UnclosedTuple => "tuple type is not closed",
TypeDiagnosticKind::UnclosedObject => "object type is not closed",
TypeDiagnosticKind::UnclosedTemplateLiteral => "template literal type is not closed",
TypeDiagnosticKind::InvalidTypeExpression => "invalid type expression",
TypeDiagnosticKind::EarlyEndOfParse => "unexpected token after type expression",
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum DiagnosticKind {
Parser(ParserDiagnosticKind),
Type(TypeDiagnosticKind),
}
impl DiagnosticKind {
#[inline]
#[must_use]
pub const fn message(self) -> &'static str {
match self {
Self::Parser(k) => parser_diagnostic_message(k),
Self::Type(k) => type_diagnostic_message(k),
}
}
}