tamer: pipeline: Remove explicit source token type specification
Like the previous commit's removal of the error type, this eliminates the explicit source token type since we're able to infer it from the pipeline definition. DEV-13162main
parent
0e0f3e658d
commit
65c1b2d083
|
@ -41,7 +41,7 @@
|
|||
//! see [`Lower`].
|
||||
|
||||
use crate::{
|
||||
asg::{air::AirAggregate, visit::TreeWalkRel, AsgTreeToXirf},
|
||||
asg::{air::AirAggregate, AsgTreeToXirf},
|
||||
diagnose::Diagnostic,
|
||||
nir::{InterpolateNir, NirToAir, TplShortDesugar, XirfToNir},
|
||||
obj::xmlo::{XmloReader, XmloToAir, XmloToken},
|
||||
|
@ -52,7 +52,6 @@ use crate::{
|
|||
xir::{
|
||||
autoclose::XirfAutoClose,
|
||||
flat::{PartialXirToXirf, RefinedText, Text, XirToXirf, XirfToXir},
|
||||
Token as XirToken,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -71,7 +70,7 @@ lower_pipeline! {
|
|||
/// TODO: To re-use this in `tamec` we want to be able to ignore fragments.
|
||||
///
|
||||
/// TODO: More documentation once this has been further cleaned up.
|
||||
pub load_xmlo(XirToken)
|
||||
pub load_xmlo
|
||||
|> PartialXirToXirf<4, Text>
|
||||
|> XmloReader
|
||||
|> XmloToAir[xmlo_ctx], until (XmloToken::Eoh(..))
|
||||
|
@ -81,7 +80,7 @@ lower_pipeline! {
|
|||
/// source language.
|
||||
///
|
||||
/// TODO: More documentation once this has been further cleaned up.
|
||||
pub parse_package_xml(XirToken)
|
||||
pub parse_package_xml
|
||||
|> XirToXirf<64, RefinedText>
|
||||
|> XirfToNir
|
||||
|> TplShortDesugar
|
||||
|
@ -93,7 +92,7 @@ lower_pipeline! {
|
|||
/// `xmli` file.
|
||||
///
|
||||
/// TODO: More documentation once this has been further cleaned up.
|
||||
pub lower_xmli<'a>(TreeWalkRel)
|
||||
pub lower_xmli<'a>
|
||||
|> AsgTreeToXirf<'a>[asg]
|
||||
|> XirfAutoClose
|
||||
|> XirfToXir<Text>;
|
||||
|
|
|
@ -42,12 +42,16 @@
|
|||
macro_rules! lower_pipeline {
|
||||
($(
|
||||
$(#[$meta:meta])*
|
||||
$vis:vis $fn:ident$(<$l:lifetime>)?($srcobj:ty)
|
||||
$vis:vis $fn:ident$(<$l:lifetime>)?
|
||||
$(|> $lower:ty $([$ctx:ident])? $(, until ($until:pat))?)*;
|
||||
)*) => {$(
|
||||
$(#[$meta])*
|
||||
$vis fn $fn<$($l,)? ES: Diagnostic, ER: Diagnostic, EU: Diagnostic>(
|
||||
src: impl LowerSource<UnknownToken, $srcobj, ES>,
|
||||
src: impl LowerSource<
|
||||
UnknownToken,
|
||||
lower_pipeline!(@first_tok_ty $($lower),*),
|
||||
ES
|
||||
>,
|
||||
$(
|
||||
// Each parser may optionally receive context from an
|
||||
// earlier run.
|
||||
|
@ -93,7 +97,7 @@ macro_rules! lower_pipeline {
|
|||
EU: From<FinalizeError>,
|
||||
{
|
||||
let lower_pipeline!(@ret_pat $($($ctx)?)*) = lower_pipeline!(
|
||||
@body_head(src, $srcobj, sink)
|
||||
@body_head(src, sink)
|
||||
$((|> $lower $([$ctx])? $(, until ($until))?))*
|
||||
)?;
|
||||
|
||||
|
@ -107,6 +111,13 @@ macro_rules! lower_pipeline {
|
|||
<$lower as ParseState>::PubContext
|
||||
};
|
||||
|
||||
// We are able to determine the necessary type of the source token
|
||||
// stream by observing what token is expected by the first parser in the
|
||||
// pipeline.
|
||||
(@first_tok_ty $lower:ty, $($rest:ty),+) => {
|
||||
<$lower as ParseState>::Token
|
||||
};
|
||||
|
||||
// The last object type enters the sink.
|
||||
(@last_obj_ty $lower:ty, $($rest:ty),+) => {
|
||||
lower_pipeline!(@last_obj_ty $($rest),+)
|
||||
|
@ -131,11 +142,11 @@ macro_rules! lower_pipeline {
|
|||
// This doesn't support context or `until`;
|
||||
// it can be added if ever it is needed.
|
||||
(
|
||||
@body_head($src:ident, $srcobj:ty, $sink:ident)
|
||||
@body_head($src:ident, $sink:ident)
|
||||
(|> $head:ty) $($rest:tt)*
|
||||
) => {
|
||||
Lower::<
|
||||
ParsedObject<UnknownToken, $srcobj, ES>,
|
||||
ParsedObject<UnknownToken, _, ES>,
|
||||
$head,
|
||||
ER,
|
||||
>::lower::<_, EU>(&mut $src.map(|result| result.map_err(ER::from)), |next| {
|
||||
|
@ -148,11 +159,11 @@ macro_rules! lower_pipeline {
|
|||
|
||||
// TODO: Roll this into the above
|
||||
(
|
||||
@body_head($src:ident, $srcobj:ty, $sink:ident)
|
||||
@body_head($src:ident, $sink:ident)
|
||||
(|> $head:ty [$ctx:ident]) $($rest:tt)*
|
||||
) => {
|
||||
Lower::<
|
||||
ParsedObject<UnknownToken, $srcobj, ES>,
|
||||
ParsedObject<UnknownToken, _, ES>,
|
||||
$head,
|
||||
ER,
|
||||
>::lower_with_context::<_, EU>(
|
||||
|
|
Loading…
Reference in New Issue