Tentative beginning to implementing Parse for Expr types
diff --git a/src/expr.rs b/src/expr.rs
index a5f0e3a..35bb3ea 100644
--- a/src/expr.rs
+++ b/src/expr.rs
@@ -1910,6 +1910,17 @@
}
#[cfg(feature = "full")]
+ impl Parse for ExprRange {
+ fn parse(input: ParseStream) -> Result<Self> {
+ let expr: Expr = input.parse()?;
+ match expr {
+ Expr::Range(expr_range) => Ok(expr_range),
+ _ => Err(input.error("expected range expression"))
+ }
+ }
+ }
+
+ #[cfg(feature = "full")]
fn expr_try_block(input: ParseStream) -> Result<ExprTryBlock> {
Ok(ExprTryBlock {
attrs: Vec::new(),
diff --git a/tests/test_parse.rs b/tests/test_parse.rs
new file mode 100644
index 0000000..b99ef2b
--- /dev/null
+++ b/tests/test_parse.rs
@@ -0,0 +1,28 @@
+extern crate proc_macro2;
+extern crate syn;
+
+use std::str::FromStr;
+
+use proc_macro2::TokenStream;
+use syn::{Expr, parse2};
+
+#[test]
+fn test_expr_parse() {
+ macro_rules! test_equiv {
+ ($code:ident, $old:ident, $new:ident) => (
+ let tt = TokenStream::from_str($code).unwrap();
+ //println!("--- tt ---\n{:?}\n", tt);
+ let ast1: Expr = parse2(tt.clone()).unwrap();
+ //println!("--- ast1 ---\n{:?}\n", ast1);
+ let ast2: syn::$new = parse2(tt).unwrap();
+ //println!("--- ast2 ---\n{:?}\n", ast2);
+ assert_eq!(ast1, Expr::$old(ast2));
+ )
+ }
+
+ let code = "match foo { Bar::Qux => (), _ => panic!() }";
+ test_equiv!(code, Match, ExprMatch);
+
+ let code = "..100u32";
+ test_equiv!(code, Range, ExprRange);
+}