Parenthesized constant expressions
diff --git a/src/constant.rs b/src/constant.rs
index 1ebac7f..f0ec2c5 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -18,6 +18,8 @@
/// Variable reference, possibly containing `::` and/or type
/// parameters, e.g. foo::bar::<baz>.
Path(Path),
+ /// No-op: used solely so we can pretty-print faithfully
+ Paren(Box<ConstExpr>),
}
#[cfg(feature = "parsing")]
@@ -30,11 +32,13 @@
named!(pub const_expr -> ConstExpr, do_parse!(
mut e: alt!(
- expr_lit
- |
expr_unary
|
- path => { ConstExpr::Path }
+ expr_lit
+ |
+ expr_path
+ |
+ expr_paren
) >>
many0!(alt!(
tap!(args: and_call => {
@@ -70,6 +74,15 @@
named!(expr_lit -> ConstExpr, map!(lit, ConstExpr::Lit));
+ named!(expr_path -> ConstExpr, map!(path, ConstExpr::Path));
+
+ named!(expr_paren -> ConstExpr, do_parse!(
+ punct!("(") >>
+ e: const_expr >>
+ punct!(")") >>
+ (ConstExpr::Paren(Box::new(e)))
+ ));
+
named!(and_cast -> Ty, do_parse!(
keyword!("as") >>
ty: ty >>
@@ -107,6 +120,11 @@
ty.to_tokens(tokens);
}
ConstExpr::Path(ref path) => path.to_tokens(tokens),
+ ConstExpr::Paren(ref expr) => {
+ tokens.append("(");
+ expr.to_tokens(tokens);
+ tokens.append(")");
+ }
}
}
}