From 34fcd19cd04248cad09a69bca1efc916fe13b8af Mon Sep 17 00:00:00 2001 From: Mike Gerwitz Date: Tue, 3 May 2022 09:17:38 -0400 Subject: [PATCH] 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 --- tamer/src/obj/xmlo/error.rs | 22 +++++++++++++++++----- tamer/src/obj/xmlo/reader.rs | 16 ++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/tamer/src/obj/xmlo/error.rs b/tamer/src/obj/xmlo/error.rs index d8d99bf3..2dc728a3 100644 --- a/tamer/src/obj/xmlo/error.rs +++ b/tamer/src/obj/xmlo/error.rs @@ -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(), } } } diff --git a/tamer/src/obj/xmlo/reader.rs b/tamer/src/obj/xmlo/reader.rs index 7cde6bc1..8a537883 100644 --- a/tamer/src/obj/xmlo/reader.rs +++ b/tamer/src/obj/xmlo/reader.rs @@ -242,7 +242,9 @@ impl 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)) + } } }