tamer: xir::parse::ele: Remove `*Error_` types
A type alias was added for BC before errors were hoisted out in a previous commit, but they are unnecessary because of the associated type on `ParseState`. This also corrects the long-existing issue of using generated identifiers in tests. DEV-7145main
parent
071c94790f
commit
f9bdcc2775
|
@ -62,6 +62,8 @@
|
|||
// when `log10` et al. were renamed to `ilog10` et al:
|
||||
// <https://github.com/rust-lang/rust/pull/100332>
|
||||
#![feature(int_log)]
|
||||
// Enabled for qualified paths in `matches!`.
|
||||
#![feature(more_qualified_paths)]
|
||||
// Used for const params like `&'static str` in `crate::fmt`.
|
||||
// If this is not stabalized,
|
||||
// then we can do without by changing the abstraction;
|
||||
|
|
|
@ -584,16 +584,12 @@ macro_rules! ele_parse {
|
|||
}
|
||||
}
|
||||
|
||||
// Used by superstate sum type.
|
||||
#[doc(hidden)]
|
||||
type [<$nt Error_>] = crate::xir::parse::NtError<$nt>;
|
||||
|
||||
impl crate::parse::ParseState for $nt {
|
||||
type Token = crate::xir::flat::XirfToken<
|
||||
crate::xir::flat::RefinedText
|
||||
>;
|
||||
type Object = $objty;
|
||||
type Error = [<$nt Error_>];
|
||||
type Error = crate::xir::parse::NtError<$nt>;
|
||||
type Context = crate::xir::parse::StateStackContext<Self::Super>;
|
||||
type Super = $super;
|
||||
|
||||
|
@ -666,7 +662,7 @@ macro_rules! ele_parse {
|
|||
Transition(Self(
|
||||
RecoverEleIgnore(qname, span, depth)
|
||||
)).err(
|
||||
[<$nt Error_>]::UnexpectedEle(
|
||||
Self::Error::UnexpectedEle(
|
||||
qname, span.name_span()
|
||||
)
|
||||
)
|
||||
|
@ -876,7 +872,7 @@ macro_rules! ele_parse {
|
|||
Transition(Self(
|
||||
CloseRecoverIgnore(meta, unexpected_tok.span())
|
||||
)).err(
|
||||
[<$nt Error_>]::CloseExpected(qname, otspan, unexpected_tok)
|
||||
Self::Error::CloseExpected(qname, otspan, unexpected_tok)
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -1019,16 +1015,12 @@ macro_rules! ele_parse {
|
|||
}
|
||||
}
|
||||
|
||||
// Used by superstate sum type.
|
||||
#[doc(hidden)]
|
||||
type [<$nt Error_>] = crate::xir::parse::SumNtError<$nt>;
|
||||
|
||||
impl crate::parse::ParseState for $nt {
|
||||
type Token = crate::xir::flat::XirfToken<
|
||||
crate::xir::flat::RefinedText
|
||||
>;
|
||||
type Object = $objty;
|
||||
type Error = [<$nt Error_>];
|
||||
type Error = crate::xir::parse::SumNtError<$nt>;
|
||||
type Context = crate::xir::parse::StateStackContext<Self::Super>;
|
||||
type Super = $super;
|
||||
|
||||
|
@ -1248,13 +1240,15 @@ macro_rules! ele_parse {
|
|||
#[derive(Debug, PartialEq)]
|
||||
$vis enum [<$super Error_>] {
|
||||
$(
|
||||
$nt([<$nt Error_>]),
|
||||
$nt(<$nt as crate::parse::ParseState>::Error),
|
||||
)*
|
||||
}
|
||||
|
||||
$(
|
||||
impl From<[<$nt Error_>]> for [<$super Error_>] {
|
||||
fn from(e: [<$nt Error_>]) -> Self {
|
||||
impl From<<$nt as crate::parse::ParseState>::Error>
|
||||
for [<$super Error_>]
|
||||
{
|
||||
fn from(e: <$nt as crate::parse::ParseState>::Error) -> Self {
|
||||
[<$super Error_>]::$nt(e)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,11 +221,12 @@ fn empty_element_ns_prefix_nomatch() {
|
|||
|
||||
let err = sut.next().unwrap().unwrap_err();
|
||||
assert_eq!(
|
||||
// TODO: This references generated identifiers.
|
||||
ParseError::StateError(SutError_::Root(RootError_::UnexpectedEle(
|
||||
unexpected,
|
||||
span.name_span()
|
||||
))),
|
||||
ParseError::StateError(<Sut as ParseState>::Error::Root(
|
||||
<Root as ParseState>::Error::UnexpectedEle(
|
||||
unexpected,
|
||||
span.name_span()
|
||||
)
|
||||
)),
|
||||
err,
|
||||
);
|
||||
}
|
||||
|
@ -270,13 +271,14 @@ fn empty_element_ns_prefix_invalid_close_contains_matching_qname() {
|
|||
// since we were not expecting a child.
|
||||
let err = sut.next().unwrap().unwrap_err();
|
||||
assert_eq!(
|
||||
// TODO: This references generated identifiers.
|
||||
ParseError::StateError(SutError_::Root(RootError_::CloseExpected(
|
||||
// Verify that the error includes the QName that actually matched.
|
||||
QN_C_EQ,
|
||||
OpenSpan(S1, N),
|
||||
XirfToken::Open(unexpected, span_unexpected, Depth(1)),
|
||||
))),
|
||||
ParseError::StateError(<Sut as ParseState>::Error::Root(
|
||||
<Root as ParseState>::Error::CloseExpected(
|
||||
// Verify that the error includes the QName that actually matched.
|
||||
QN_C_EQ,
|
||||
OpenSpan(S1, N),
|
||||
XirfToken::Open(unexpected, span_unexpected, Depth(1)),
|
||||
)
|
||||
)),
|
||||
err,
|
||||
);
|
||||
}
|
||||
|
@ -427,7 +429,9 @@ fn element_with_failed_attr_parsing() {
|
|||
let err = sut.next().unwrap().unwrap_err();
|
||||
assert_matches!(
|
||||
err,
|
||||
ParseError::StateError(SutError_::Root(RootError_::Attrs(..))),
|
||||
ParseError::StateError(<Sut as ParseState>::Error::Root(
|
||||
<Root as ParseState>::Error::Attrs(..)
|
||||
)),
|
||||
); // [Root] Child Open (>LA)
|
||||
|
||||
// The remaining tokens should be ignored and we should finish parsing.
|
||||
|
@ -584,11 +588,12 @@ fn unexpected_element() {
|
|||
// but to the fact that the name was not the one expected.
|
||||
let err = sut.next().unwrap().unwrap_err();
|
||||
assert_eq!(
|
||||
// TODO: This references generated identifiers.
|
||||
ParseError::StateError(SutError_::Root(RootError_::UnexpectedEle(
|
||||
unexpected,
|
||||
span.name_span()
|
||||
))),
|
||||
ParseError::StateError(<Sut as ParseState>::Error::Root(
|
||||
<Root as ParseState>::Error::UnexpectedEle(
|
||||
unexpected,
|
||||
span.name_span()
|
||||
)
|
||||
)),
|
||||
err,
|
||||
);
|
||||
|
||||
|
@ -980,11 +985,12 @@ fn child_error_and_recovery() {
|
|||
let err = sut.next().unwrap().unwrap_err();
|
||||
assert_eq!(
|
||||
err,
|
||||
// TODO: This references generated identifiers.
|
||||
ParseError::StateError(SutError_::ChildB(ChildBError_::UnexpectedEle(
|
||||
unexpected,
|
||||
span.name_span(),
|
||||
))),
|
||||
ParseError::StateError(<Sut as ParseState>::Error::ChildB(
|
||||
<ChildB as ParseState>::Error::UnexpectedEle(
|
||||
unexpected,
|
||||
span.name_span(),
|
||||
)
|
||||
)),
|
||||
);
|
||||
|
||||
// TODO: Can't deal with this until we know exactly what error we'll
|
||||
|
@ -1098,12 +1104,13 @@ fn child_error_and_recovery_at_close() {
|
|||
// since we do not want to reprocess bad input.
|
||||
let err = sut.next().unwrap().unwrap_err();
|
||||
assert_eq!(
|
||||
// TODO: This references generated identifiers.
|
||||
ParseError::StateError(SutError_::Root(RootError_::CloseExpected(
|
||||
QN_PACKAGE,
|
||||
OpenSpan(S1, N),
|
||||
XirfToken::Open(unexpected_a, span_a, Depth(1)),
|
||||
))),
|
||||
ParseError::StateError(<Sut as ParseState>::Error::Root(
|
||||
<Root as ParseState>::Error::CloseExpected(
|
||||
QN_PACKAGE,
|
||||
OpenSpan(S1, N),
|
||||
XirfToken::Open(unexpected_a, span_a, Depth(1)),
|
||||
)
|
||||
)),
|
||||
err,
|
||||
);
|
||||
|
||||
|
@ -1425,12 +1432,13 @@ fn sum_nonterminal_error_recovery() {
|
|||
let err = sut.next().unwrap().unwrap_err();
|
||||
assert_eq!(
|
||||
err,
|
||||
// TODO: This references generated identifiers.
|
||||
ParseError::StateError(SutError_::Root(RootError_::UnexpectedEle(
|
||||
unexpected,
|
||||
OpenSpan(S1, N).name_span(),
|
||||
Default::default(),
|
||||
))),
|
||||
ParseError::StateError(<Sut as ParseState>::Error::Root(
|
||||
<Root as ParseState>::Error::UnexpectedEle(
|
||||
unexpected,
|
||||
OpenSpan(S1, N).name_span(),
|
||||
Default::default(),
|
||||
)
|
||||
)),
|
||||
);
|
||||
|
||||
// Diagnostic message should describe the name of the element.
|
||||
|
@ -1661,8 +1669,11 @@ fn child_nt_sequence_no_prev_after_next() {
|
|||
Ok(Incomplete), // [B] B Open (<LA)
|
||||
Ok(Object(Foo::Open(QN_B))), // [B@] B Close (>LA)
|
||||
Ok(Object(Foo::Close(QN_B))), // [B] B Close (<LA)
|
||||
Err(ParseError::StateError(SutError_::B(
|
||||
BError_::UnexpectedEle(QN_A, OpenSpan(S6, N).name_span())
|
||||
Err(ParseError::StateError(<Sut as ParseState>::Error::B(
|
||||
<B as ParseState>::Error::UnexpectedEle(
|
||||
QN_A,
|
||||
OpenSpan(S6, N).name_span()
|
||||
)
|
||||
))), // [B!] A Open
|
||||
Ok(Incomplete), // [B!] A Close
|
||||
Ok(Object(Foo::Close(QN_ROOT))), // [Root] Root Close
|
||||
|
@ -1743,10 +1754,14 @@ fn child_repetition_invalid_tok_dead() {
|
|||
// and so the error will occur on `Child`.
|
||||
assert_eq!(
|
||||
next(),
|
||||
Some(Err(ParseError::StateError(SutError_::Child(
|
||||
// TODO: This references generated identifiers.
|
||||
ChildError_::UnexpectedEle(unexpected, OpenSpan(S2, N).name_span())
|
||||
)))),
|
||||
Some(Err(ParseError::StateError(
|
||||
<Sut as ParseState>::Error::Child(
|
||||
<Child as ParseState>::Error::UnexpectedEle(
|
||||
unexpected,
|
||||
OpenSpan(S2, N).name_span()
|
||||
)
|
||||
)
|
||||
))),
|
||||
);
|
||||
|
||||
// This next token is also ignored as part of recovery.
|
||||
|
|
Loading…
Reference in New Issue