tamer: obj::xmlo::reader: Replace todo! with error

These are no longer TODOs---they represent invalid tokens.

I'm going to put effort into providing further context with the diagnostic
system [right now] because these are internal errors caused by either
miscompilation or an incomplete reader.

DEV-10936
main
Mike Gerwitz 2022-05-03 09:17:38 -04:00
parent c4828e7e7a
commit 34fcd19cd0
2 changed files with 29 additions and 9 deletions

View File

@ -60,6 +60,12 @@ pub enum XmloError {
UnassociatedFragment(Span),
/// A `preproc:fragment` element was found, but is missing `text()`.
MissingFragmentText(SymbolId, Span),
/// A token of input was unexpected.
///
/// Ideally we would provide a better error depending on the context,
/// but this serves as a fallback if the input is completely
/// unexpected.
UnexpectedToken(XirfToken),
}
impl Display for XmloError {
@ -106,8 +112,10 @@ impl Display for XmloError {
UnassociatedFragment(_) => write!(fmt, "unassociated fragment"),
MissingFragmentText(sym, _) => {
write!(fmt, "missing fragment text for symbol `{sym}`",)
write!(fmt, "missing fragment text for symbol `{sym}`")
}
UnexpectedToken(tok) => write!(fmt, "unexpected {tok}"),
}
}
}
@ -123,7 +131,7 @@ impl Diagnostic for XmloError {
use XmloError::*;
let malformed = "this `xmlo` file is malformed or corrupt; \
try removing it to force it to be rebuilt,
try removing it to force it to be rebuilt, \
and please report this error";
// Note that these errors _could_ potentially be more descriptive
@ -172,9 +180,7 @@ impl Diagnostic for XmloError {
.into(),
MapFromMultiple(_sym, span) => span
.internal_error(
"this is an unexpected extra `preproc:from` for `{sym}`",
)
.internal_error("extra `preproc:from` here")
.with_help(malformed)
.into(),
@ -197,6 +203,12 @@ impl Diagnostic for XmloError {
.internal_error("missing fragment text")
.with_help(malformed)
.into(),
UnexpectedToken(tok) => tok
.span()
.internal_error("unknown or unexpected token")
.with_help(malformed)
.into(),
}
}
}

View File

@ -242,7 +242,9 @@ impl<SS: XmloState, SD: XmloState, SF: XmloState> ParseState
// TODO: For whitespace, which can be stripped by XIRF.
(st, Xirf::Text(..)) => Transition(st).incomplete(),
todo => todo!("{todo:?}"),
(st, unknown) => {
Transition(st).err(XmloError::UnexpectedToken(unknown))
}
}
}
@ -364,7 +366,9 @@ impl ParseState for SymtableState {
// TODO: For whitespace, which can be stripped by XIRF.
(st, Xirf::Text(..)) => Transition(st).incomplete(),
todo => todo!("{todo:?}"),
(st, unknown) => {
Transition(st).err(XmloError::UnexpectedToken(unknown))
}
}
}
@ -594,7 +598,9 @@ impl ParseState for SymDepsState {
// TODO: For whitespace, which can be stripped by XIRF.
(st, Xirf::Text(..)) => Transition(st).incomplete(),
todo => todo!("sym-deps {todo:?}"),
(st, unknown) => {
Transition(st).err(XmloError::UnexpectedToken(unknown))
}
}
}
@ -680,7 +686,9 @@ impl ParseState for FragmentsState {
Transition(Ready).incomplete()
}
todo => todo!("{todo:?}"),
(st, unknown) => {
Transition(st).err(XmloError::UnexpectedToken(unknown))
}
}
}