diff --git a/tamer/src/pipeline.rs b/tamer/src/pipeline.rs index daa75997..648e9819 100644 --- a/tamer/src/pipeline.rs +++ b/tamer/src/pipeline.rs @@ -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; diff --git a/tamer/src/pipeline/macro.rs b/tamer/src/pipeline/macro.rs index 7192ad3b..488a0cfa 100644 --- a/tamer/src/pipeline/macro.rs +++ b/tamer/src/pipeline/macro.rs @@ -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, + 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, { 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, + ParsedObject, $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, + ParsedObject, $head, ER, >::lower_with_context::<_, EU>(