tamer: xir::parse::ele: Adjust diagnostic display of expected element list

This does two things:

  1. Places the expected list on a separate help line as a footnote where
     it'll be a bit more tolerable when it inevitably overflows the terminal
     width in certain contexts (we may wrap in the future); and
  2. Removes angled brackets from the element names so that they (a) better
     correspond with the span which highlights only the element name and (b)
     do not imply that the elements take no attributes.

DEV-7145
main
Mike Gerwitz 2022-08-11 01:33:24 -04:00
parent 67ee914505
commit b95ec5a9d8
2 changed files with 14 additions and 13 deletions

View File

@ -20,7 +20,7 @@
//! XIR formatting types for use with [`crate::fmt`]
use crate::fmt::{
AndQualConjList, Delim, OrQualConjList, Prefix, Raw, Suffix, Tt,
AndQualConjList, Delim, OrQualConjList, Prefix, Raw, Suffix, Tt, TtQuote,
};
/// Denote an XML attribute by prefixing the value with `@`.
@ -49,9 +49,8 @@ pub type TtOpenXmlEle = Tt<OpenXmlEle>;
/// (for use in sentences).
pub type TtCloseXmlEle = Tt<CloseXmlEle>;
/// A choice of a list of opening XML tags.
pub type OpenEleSumList =
OrQualConjList<"element", "one of elements", TtOpenXmlEle>;
/// A choice of a list of XML elements by name.
pub type EleSumList = OrQualConjList<"element", "one of elements", TtQuote>;
/// Quote an attribute value using double quotes.
pub type XmlAttrValueQuote = Delim<"\"", "\"", Raw>;

View File

@ -932,7 +932,7 @@ macro_rules! ele_parse {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
use crate::{
fmt::{DisplayWrapper, ListDisplayWrapper, TtQuote},
xir::fmt::OpenEleSumList,
xir::fmt::EleSumList,
};
let ntrefs = [
@ -940,7 +940,7 @@ macro_rules! ele_parse {
$ntref::matcher(),
)*
];
let expected = OpenEleSumList::wrap(&ntrefs);
let expected = EleSumList::wrap(&ntrefs);
match self {
Self::Expecting_(_) => {
@ -999,7 +999,7 @@ macro_rules! ele_parse {
use crate::{
diagnose::Annotate,
fmt::{DisplayWrapper, ListDisplayWrapper, TtQuote},
xir::fmt::OpenEleSumList,
xir::fmt::EleSumList,
};
let ntrefs = [
@ -1007,15 +1007,17 @@ macro_rules! ele_parse {
$ntref::matcher(),
)*
];
let expected = OpenEleSumList::wrap(&ntrefs);
let expected = EleSumList::wrap(&ntrefs);
match self {
Self::UnexpectedEle_(qname, span) => {
span.error(format!(
"element {name} cannot appear here \
(expecting {expected})",
name = TtQuote::wrap(qname),
)).into()
span
.error(format!(
"element {name} cannot appear here",
name = TtQuote::wrap(qname),
))
.with_help(format!("expecting {expected}"))
.into()
},
}
}