Empty path segments
diff --git a/src/expr.rs b/src/expr.rs
index 65a3902..e0cf9aa 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -334,12 +334,12 @@
#[cfg(feature = "parsing")]
pub mod parsing {
use super::*;
- use {FnArg, FnDecl, FunctionRetTy, Ident, Lifetime, Path, QSelf, Ty};
+ use {FnArg, FnDecl, FunctionRetTy, Ident, Lifetime, Ty};
use attr::parsing::outer_attr;
use generics::parsing::lifetime;
use ident::parsing::ident;
use lit::parsing::lit;
- use ty::parsing::{mutability, path, path_segment, ty};
+ use ty::parsing::{mutability, qpath, ty};
named!(pub expr -> Expr, do_parse!(
mut e: alt!(
@@ -373,8 +373,6 @@
expr_block
|
expr_path
- |
- expr_qpath
// TODO: AddrOf
|
expr_break
@@ -677,34 +675,7 @@
}))
));
- named!(expr_path -> Expr, map!(path, |p| Expr::Path(None, p)));
-
- named!(expr_qpath -> Expr, do_parse!(
- punct!("<") >>
- this: map!(ty, Box::new) >>
- path: option!(preceded!(
- keyword!("as"),
- path
- )) >>
- punct!(">") >>
- punct!("::") >>
- rest: separated_nonempty_list!(punct!("::"), path_segment) >>
- ({
- match path {
- Some(mut path) => {
- let pos = path.segments.len();
- path.segments.extend(rest);
- Expr::Path(Some(QSelf { ty: this, position: pos }), path)
- }
- None => {
- Expr::Path(Some(QSelf { ty: this, position: 0 }), Path {
- global: false,
- segments: rest,
- })
- }
- }
- })
- ));
+ named!(expr_path -> Expr, map!(qpath, |(qself, path)| Expr::Path(qself, path)));
named!(pub block -> Block, do_parse!(
punct!("{") >>
@@ -753,7 +724,8 @@
pat_ident
// TODO: Struct
// TODO: TupleStruct
- // TODO: Path
+ |
+ pat_path
// TODO: Tuple
// TODO: Box
// TODO: Ref
@@ -781,6 +753,8 @@
))
));
+ named!(pat_path -> Pat, map!(qpath, |(qself, path)| Pat::Path(qself, path)));
+
named!(capture_by -> CaptureBy, alt!(
keyword!("move") => { |_| CaptureBy::Value }
|
@@ -801,8 +775,26 @@
match *self {
Expr::Box(ref _inner) => unimplemented!(),
Expr::Vec(ref _inner) => unimplemented!(),
- Expr::Call(ref _func, ref _args) => unimplemented!(),
- Expr::MethodCall(ref _ident, ref _ascript, ref _args) => unimplemented!(),
+ Expr::Call(ref func, ref args) => {
+ func.to_tokens(tokens);
+ tokens.append("(");
+ tokens.append_separated(args, ",");
+ tokens.append(")");
+ }
+ Expr::MethodCall(ref ident, ref ascript, ref args) => {
+ args[0].to_tokens(tokens);
+ tokens.append(".");
+ ident.to_tokens(tokens);
+ if ascript.len() > 0 {
+ tokens.append("::");
+ tokens.append("<");
+ tokens.append_separated(ascript, ",");
+ tokens.append(">");
+ }
+ tokens.append("(");
+ tokens.append_separated(&args[1..], ",");
+ tokens.append(")");
+ }
Expr::Tup(ref fields) => {
tokens.append("(");
tokens.append_separated(fields, ",");
diff --git a/src/ty.rs b/src/ty.rs
index ec26c0d..7cba5f9 100644
--- a/src/ty.rs
+++ b/src/ty.rs
@@ -204,8 +204,6 @@
|
ty_path
|
- ty_qpath
- |
ty_impl_trait
|
ty_paren
@@ -285,33 +283,37 @@
(Ty::Tup(elems))
));
- named!(ty_path -> Ty, map!(path, |p| Ty::Path(None, p)));
+ named!(ty_path -> Ty, map!(qpath, |(qself, p)| Ty::Path(qself, p)));
- named!(ty_qpath -> Ty, do_parse!(
- punct!("<") >>
- this: map!(ty, Box::new) >>
- path: option!(preceded!(
- keyword!("as"),
- path
- )) >>
- punct!(">") >>
- punct!("::") >>
- rest: separated_nonempty_list!(punct!("::"), path_segment) >>
- ({
- match path {
- Some(mut path) => {
- let pos = path.segments.len();
- path.segments.extend(rest);
- Ty::Path(Some(QSelf { ty: this, position: pos }), path)
+ named!(pub qpath -> (Option<QSelf>, Path), alt!(
+ map!(path, |p| (None, p))
+ |
+ do_parse!(
+ punct!("<") >>
+ this: map!(ty, Box::new) >>
+ path: option!(preceded!(
+ keyword!("as"),
+ path
+ )) >>
+ punct!(">") >>
+ punct!("::") >>
+ rest: separated_nonempty_list!(punct!("::"), path_segment) >>
+ ({
+ match path {
+ Some(mut path) => {
+ let pos = path.segments.len();
+ path.segments.extend(rest);
+ (Some(QSelf { ty: this, position: pos }), path)
+ }
+ None => {
+ (Some(QSelf { ty: this, position: 0 }), Path {
+ global: false,
+ segments: rest,
+ })
+ }
}
- None => {
- Ty::Path(Some(QSelf { ty: this, position: 0 }), Path {
- global: false,
- segments: rest,
- })
- }
- }
- })
+ })
+ )
));
named!(ty_impl_trait -> Ty, do_parse!(
@@ -342,9 +344,9 @@
})
));
- named!(pub path_segment -> PathSegment, alt!(
+ named!(path_segment -> PathSegment, alt!(
do_parse!(
- id: ident >>
+ id: option!(ident) >>
punct!("<") >>
lifetimes: separated_list!(punct!(","), lifetime) >>
types: opt_vec!(preceded!(
@@ -360,7 +362,7 @@
)) >>
punct!(">") >>
(PathSegment {
- ident: id,
+ ident: id.unwrap_or_else(|| "".into()),
parameters: PathParameters::AngleBracketed(
AngleBracketedParameterData {
lifetimes: lifetimes,