Merge If and Special variants

This commit is contained in:
Chris Wong 2018-05-29 19:18:30 +12:00
parent ac934bae4e
commit 254ac54103
3 changed files with 12 additions and 8 deletions

View file

@ -21,10 +21,9 @@ pub enum Markup {
Let { Let {
tokens: TokenStream, tokens: TokenStream,
}, },
If { Special {
segments: Vec<Special>, segments: Vec<Special>,
}, },
Special(Special),
Match { Match {
head: TokenStream, head: TokenStream,
arms: Vec<Special>, arms: Vec<Special>,

View file

@ -51,12 +51,11 @@ impl Generator {
Markup::Splice { expr } => build.push_tokens(self.splice(expr)), Markup::Splice { expr } => build.push_tokens(self.splice(expr)),
Markup::Element { name, attrs, body } => self.element(name, attrs, body, build), Markup::Element { name, attrs, body } => self.element(name, attrs, body, build),
Markup::Let { tokens } => build.push_tokens(tokens), Markup::Let { tokens } => build.push_tokens(tokens),
Markup::If { segments } => { Markup::Special { segments } => {
for segment in segments { for segment in segments {
build.push_tokens(self.special(segment)); build.push_tokens(self.special(segment));
} }
}, },
Markup::Special(special) => build.push_tokens(self.special(special)),
Markup::Match { head, arms, arms_span } => { Markup::Match { head, arms, arms_span } => {
build.push_tokens({ build.push_tokens({
let body = arms let body = arms
@ -178,7 +177,9 @@ fn desugar_classes_or_ids(
span: toggler.cond_span, span: toggler.cond_span,
}; };
let head = desugar_toggler(toggler); let head = desugar_toggler(toggler);
markups.push(Markup::Special(Special { head, body })); markups.push(Markup::Special {
segments: vec![Special { head, body }],
});
} }
Some(Attribute { Some(Attribute {
name: TokenStream::from(TokenTree::Ident(Ident::new(attr_name, Span::call_site()))), name: TokenStream::from(TokenTree::Ident(Ident::new(attr_name, Span::call_site()))),

View file

@ -122,7 +122,7 @@ impl Parser {
"if" => { "if" => {
let mut segments = Vec::new(); let mut segments = Vec::new();
self.if_expr(vec![keyword], &mut segments)?; self.if_expr(vec![keyword], &mut segments)?;
ast::Markup::If { segments } ast::Markup::Special { segments }
}, },
"while" => self.while_expr(keyword)?, "while" => self.while_expr(keyword)?,
"for" => self.for_expr(keyword)?, "for" => self.for_expr(keyword)?,
@ -242,7 +242,9 @@ impl Parser {
None => return self.error("unexpected end of @while expression"), None => return self.error("unexpected end of @while expression"),
} }
}; };
Ok(ast::Markup::Special(ast::Special { head: head.into_iter().collect(), body })) Ok(ast::Markup::Special {
segments: vec![ast::Special { head: head.into_iter().collect(), body }],
})
} }
/// Parses a `@for` expression. /// Parses a `@for` expression.
@ -269,7 +271,9 @@ impl Parser {
None => return self.error("unexpected end of @for expression"), None => return self.error("unexpected end of @for expression"),
} }
}; };
Ok(ast::Markup::Special(ast::Special { head: head.into_iter().collect(), body })) Ok(ast::Markup::Special {
segments: vec![ast::Special { head: head.into_iter().collect(), body }],
})
} }
/// Parses a `@match` expression. /// Parses a `@match` expression.