tamer: xir: Format tokens without tt quotes
Whether or not quoting is appropriate depends on context, and that parent context is already performing the quoting. For example: error: expected `</rater>`, but found `<import>` --> /home/[...]/foo.xml:2:1 | 2 | <rater xmlns="http://www.lovullo.com/rater" | ------ note: element starts here --> /home/[...]/foo.xml:7:3 | 7 | <import package="/rater/core/base" /> | ^^^^^^^ error: expected `</rater>` In these cases (obviously I'm still working on the parser, since this is nonsense), the parser is responsible for quoting the token "<import>". DEV-7145main
parent
8778976018
commit
18803ea576
|
@ -33,6 +33,7 @@
|
|||
//! as opposed to "start" and "end" as used in the XML specification.
|
||||
//! TAMER uses a uniform terminology for all delimited data.
|
||||
|
||||
use crate::fmt::DisplayWrapper;
|
||||
use crate::span::{Span, SpanLenSize};
|
||||
use crate::sym::{
|
||||
st_as_sym, GlobalSymbolIntern, GlobalSymbolInternBytes, SymbolId,
|
||||
|
@ -51,6 +52,8 @@ pub use escape::{DefaultEscaper, Escaper};
|
|||
use error::SpanlessError;
|
||||
use st::qname::QNameCompatibleStaticSymbolId;
|
||||
|
||||
use self::fmt::{CloseXmlEle, OpenXmlEle, XmlAttr, XmlAttrValueQuote};
|
||||
|
||||
pub mod attr;
|
||||
pub mod flat;
|
||||
pub mod fmt;
|
||||
|
@ -597,21 +600,21 @@ impl Display for Token {
|
|||
// but the diagnostic system also quote source lines to provide
|
||||
// the necessary context.
|
||||
match self {
|
||||
Self::Open(qname, _) => write!(f, "`<{}>`", qname),
|
||||
Self::Close(Some(qname), _) => write!(f, "`</{}>`", qname),
|
||||
Self::Open(qname, _) => OpenXmlEle::fmt(qname, f),
|
||||
Self::Close(Some(qname), _) => CloseXmlEle::fmt(qname, f),
|
||||
// Its context is contained within the Open,
|
||||
// and hopefully any user-visible errors will display that instead.
|
||||
Self::Close(None, _) => {
|
||||
write!(f, "`/>`")
|
||||
}
|
||||
Self::AttrName(qname, _) => {
|
||||
write!(f, "`@{}`", qname)
|
||||
}
|
||||
Self::AttrValue(attr_val, _) => {
|
||||
write!(f, "attribute value `{}`", attr_val)
|
||||
write!(f, "/>")
|
||||
}
|
||||
Self::AttrName(qname, _) => XmlAttr::fmt(qname, f),
|
||||
Self::AttrValue(attr_val, _) => XmlAttrValueQuote::fmt(attr_val, f),
|
||||
Self::AttrValueFragment(attr_val, _) => {
|
||||
write!(f, "attribute value fragment `{}`", attr_val)
|
||||
write!(
|
||||
f,
|
||||
"value fragment {}",
|
||||
XmlAttrValueQuote::wrap(attr_val)
|
||||
)
|
||||
}
|
||||
Self::Comment(..) => write!(f, "comment"),
|
||||
Self::Text(..) => write!(f, "text"),
|
||||
|
|
|
@ -44,3 +44,6 @@ pub type TtCloseXmlEle = Tt<CloseXmlEle>;
|
|||
/// A choice of a list of opening XML tags.
|
||||
pub type OpenEleSumList =
|
||||
OrQualConjList<"element", "one of elements", TtOpenXmlEle>;
|
||||
|
||||
/// Quote an attribute value using double quotes.
|
||||
pub type XmlAttrValueQuote = Delim<"\"", "\"", Raw>;
|
||||
|
|
Loading…
Reference in New Issue