Parse None-delimited groups in types and expressions
diff --git a/src/ty.rs b/src/ty.rs
index e4e062e..3957ca9 100644
--- a/src/ty.rs
+++ b/src/ty.rs
@@ -66,6 +66,11 @@
pub paren_token: tokens::Paren,
pub ty: Box<Ty>,
}),
+ /// No-op: kept solely so that we can pretty-print faithfully
+ pub Group(TyGroup {
+ pub group_token: tokens::Group,
+ pub ty: Box<Ty>,
+ }),
/// TyKind::Infer means the type should be inferred instead of it having been
/// specified. This can appear anywhere in a type.
pub Infer(TyInfer {
@@ -341,6 +346,8 @@
}
named!(ambig_ty(allow_plus: bool) -> Ty, alt!(
+ syn!(TyGroup) => { Ty::Group }
+ |
// must be before mac
syn!(TyParen) => { Ty::Paren }
|
@@ -628,6 +635,16 @@
));
}
+ impl Synom for TyGroup {
+ named!(parse -> Self, do_parse!(
+ data: grouped!(syn!(Ty)) >>
+ (TyGroup {
+ group_token: data.1,
+ ty: Box::new(data.0),
+ })
+ ));
+ }
+
impl Synom for TyParen {
named!(parse -> Self, do_parse!(
data: parens!(syn!(Ty)) >>
@@ -910,6 +927,14 @@
}
}
+ impl ToTokens for TyGroup {
+ fn to_tokens(&self, tokens: &mut Tokens) {
+ self.group_token.surround(tokens, |tokens| {
+ self.ty.to_tokens(tokens);
+ });
+ }
+ }
+
impl ToTokens for TyParen {
fn to_tokens(&self, tokens: &mut Tokens) {
self.paren_token.surround(tokens, |tokens| {