Parenthesized parameter data
diff --git a/src/expr.rs b/src/expr.rs
index 4f4dea8..8a41b42 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -422,6 +422,7 @@
named!(expr_vec -> Expr, do_parse!(
punct!("[") >>
elems: separated_list!(punct!(","), expr) >>
+ cond!(!elems.is_empty(), option!(punct!(","))) >>
punct!("]") >>
(Expr::Vec(elems))
));
@@ -429,6 +430,7 @@
named!(and_call -> Vec<Expr>, do_parse!(
punct!("(") >>
args: separated_list!(punct!(","), expr) >>
+ cond!(!args.is_empty(), option!(punct!(","))) >>
punct!(")") >>
(args)
));
@@ -436,13 +438,17 @@
named!(and_method_call -> (Ident, Vec<Ty>, Vec<Expr>), do_parse!(
punct!(".") >>
method: ident >>
- ascript: opt_vec!(delimited!(
- punct!("<"),
- separated_list!(punct!(","), ty),
- punct!(">")
+ ascript: opt_vec!(preceded!(
+ punct!("::"),
+ delimited!(
+ punct!("<"),
+ separated_list!(punct!(","), ty),
+ punct!(">")
+ )
)) >>
punct!("(") >>
args: separated_list!(punct!(","), expr) >>
+ cond!(!args.is_empty(), option!(punct!(","))) >>
punct!(")") >>
(method, ascript, args)
));
@@ -450,7 +456,7 @@
named!(expr_tup -> Expr, do_parse!(
punct!("(") >>
elems: separated_list!(punct!(","), expr) >>
- option!(punct!(",")) >>
+ cond!(!elems.is_empty(), option!(punct!(","))) >>
punct!(")") >>
(Expr::Tup(elems))
));
@@ -557,10 +563,11 @@
guard: option!(preceded!(keyword!("if"), expr)) >>
punct!("=>") >>
body: alt!(
- terminated!(expr, punct!(","))
- |
map!(block, |blk| Expr::Block(BlockCheckMode::Default, blk))
+ |
+ expr
) >>
+ option!(punct!(",")) >>
(Arm {
attrs: attrs,
pats: pats,
@@ -576,6 +583,7 @@
capture: capture_by >>
punct!("|") >>
inputs: separated_list!(punct!(","), closure_arg) >>
+ cond!(!inputs.is_empty(), option!(punct!(","))) >>
punct!("|") >>
ret_and_body: alt!(
do_parse!(
@@ -656,6 +664,7 @@
base: expr >>
(base)
)) >>
+ cond!(!fields.is_empty() && base.is_none(), option!(punct!(","))) >>
punct!("}") >>
(Expr::Struct(path, fields, base.map(Box::new)))
));
diff --git a/src/item.rs b/src/item.rs
index 1e4701f..16f7f30 100644
--- a/src/item.rs
+++ b/src/item.rs
@@ -427,6 +427,7 @@
generics: generics >>
punct!("(") >>
inputs: separated_list!(punct!(","), fn_arg) >>
+ cond!(!inputs.is_empty(), option!(punct!(","))) >>
punct!(")") >>
ret: option!(preceded!(punct!("->"), ty)) >>
where_clause: where_clause >>
@@ -525,6 +526,7 @@
generics: generics >>
punct!("(") >>
inputs: separated_list!(punct!(","), fn_arg) >>
+ cond!(!inputs.is_empty(), option!(punct!(","))) >>
punct!(")") >>
ret: option!(preceded!(punct!("->"), ty)) >>
where_clause: where_clause >>
@@ -702,6 +704,7 @@
generics: generics >>
punct!("(") >>
inputs: separated_list!(punct!(","), fn_arg) >>
+ cond!(!inputs.is_empty(), option!(punct!(","))) >>
punct!(")") >>
ret: option!(preceded!(punct!("->"), ty)) >>
where_clause: where_clause >>
@@ -845,6 +848,7 @@
generics: generics >>
punct!("(") >>
inputs: separated_list!(punct!(","), fn_arg) >>
+ cond!(!inputs.is_empty(), option!(punct!(","))) >>
punct!(")") >>
ret: option!(preceded!(punct!("->"), ty)) >>
where_clause: where_clause >>
diff --git a/src/ty.rs b/src/ty.rs
index 176a187..011f0f9 100644
--- a/src/ty.rs
+++ b/src/ty.rs
@@ -301,9 +301,17 @@
named!(ty_path -> Ty, do_parse!(
qpath: qpath >>
+ parenthesized: cond!(
+ qpath.1.segments.last().unwrap().parameters == PathParameters::none(),
+ option!(parenthesized_parameter_data)
+ ) >>
bounds: many0!(preceded!(punct!("+"), ty_param_bound)) >>
({
- let path = Ty::Path(qpath.0, qpath.1);
+ let (qself, mut path) = qpath;
+ if let Some(Some(parenthesized)) = parenthesized {
+ path.segments.last_mut().unwrap().parameters = parenthesized;
+ }
+ let path = Ty::Path(qself, path);
if bounds.is_empty() {
path
} else {
@@ -312,6 +320,23 @@
})
));
+ named!(parenthesized_parameter_data -> PathParameters, do_parse!(
+ punct!("(") >>
+ inputs: separated_list!(punct!(","), ty) >>
+ cond!(!inputs.is_empty(), option!(punct!(","))) >>
+ punct!(")") >>
+ output: option!(preceded!(
+ punct!("->"),
+ ty
+ )) >>
+ (PathParameters::Parenthesized(
+ ParenthesizedParameterData {
+ inputs: inputs,
+ output: output,
+ },
+ ))
+ ));
+
named!(pub qpath -> (Option<QSelf>, Path), alt!(
map!(path, |p| (None, p))
|
@@ -433,9 +458,19 @@
named!(pub poly_trait_ref -> PolyTraitRef, do_parse!(
bound_lifetimes: bound_lifetimes >>
trait_ref: path >>
- (PolyTraitRef {
- bound_lifetimes: bound_lifetimes,
- trait_ref: trait_ref,
+ parenthesized: cond!(
+ trait_ref.segments.last().unwrap().parameters == PathParameters::none(),
+ option!(parenthesized_parameter_data)
+ ) >>
+ ({
+ let mut trait_ref = trait_ref;
+ if let Some(Some(parenthesized)) = parenthesized {
+ trait_ref.segments.last_mut().unwrap().parameters = parenthesized;
+ }
+ PolyTraitRef {
+ bound_lifetimes: bound_lifetimes,
+ trait_ref: trait_ref,
+ }
})
));