1
Fork 0

Refactor token collection to capture trailing token immediately

This commit is contained in:
Aaron Hill 2021-01-14 10:42:01 -05:00
parent dc1eee2f25
commit ccfc292999
No known key found for this signature in database
GPG key ID: B4087E510E98B164
5 changed files with 124 additions and 118 deletions

View file

@ -127,14 +127,10 @@ where
}
pub trait CreateTokenStream: sync::Send + sync::Sync {
fn add_trailing_semi(&self) -> Box<dyn CreateTokenStream>;
fn create_token_stream(&self) -> TokenStream;
}
impl CreateTokenStream for TokenStream {
fn add_trailing_semi(&self) -> Box<dyn CreateTokenStream> {
panic!("Cannot call `add_trailing_semi` on a `TokenStream`!");
}
fn create_token_stream(&self) -> TokenStream {
self.clone()
}
@ -151,13 +147,6 @@ impl LazyTokenStream {
LazyTokenStream(Lrc::new(Box::new(inner)))
}
/// Extends the captured stream by one token,
/// which must be a trailing semicolon. This
/// affects the `TokenStream` created by `make_tokenstream`.
pub fn add_trailing_semi(&self) -> LazyTokenStream {
LazyTokenStream(Lrc::new(self.0.add_trailing_semi()))
}
pub fn create_token_stream(&self) -> TokenStream {
self.0.create_token_stream()
}