Pare down the Synom trait
I would like to make it clearer that parsing a string is second-class
functionality compared to parsing tokens.
diff --git a/tests/common/mod.rs b/tests/common/mod.rs
index fcb8c61..5ffeb84 100644
--- a/tests/common/mod.rs
+++ b/tests/common/mod.rs
@@ -1,9 +1,12 @@
+#![allow(dead_code)]
+
extern crate walkdir;
-use walkdir::DirEntry;
use std::env;
use std::u32;
+use self::walkdir::DirEntry;
+
macro_rules! errorf {
($($tt:tt)*) => {
{
diff --git a/tests/common/parse.rs b/tests/common/parse.rs
index 15c2faf..a0c54e5 100644
--- a/tests/common/parse.rs
+++ b/tests/common/parse.rs
@@ -1,4 +1,6 @@
+extern crate proc_macro2;
extern crate syn;
+extern crate synom;
extern crate syntex_syntax;
use self::syntex_syntax::ast;
@@ -8,6 +10,8 @@
use std::panic;
+use self::synom::{Synom, SynomBuffer};
+
pub fn syntex_expr(input: &str) -> Option<P<ast::Expr>> {
match panic::catch_unwind(|| {
let sess = ParseSess::new(FilePathMapping::empty());
@@ -37,7 +41,7 @@
}
pub fn syn_expr(input: &str) -> Option<syn::Expr> {
- match input.parse::<syn::Expr>() {
+ match syn::parse_str(input) {
Ok(e) => Some(e),
Err(msg) => {
errorf!("syn failed to parse\n{:?}\n", msg);
@@ -45,3 +49,20 @@
}
}
}
+
+pub fn syn<T: Synom>(tokens: proc_macro2::TokenStream) -> T {
+ let buf = SynomBuffer::new(tokens);
+ let result = T::parse(buf.begin());
+ match result {
+ Ok((rest, t)) => {
+ if rest.eof() {
+ t
+ } else if rest == buf.begin() {
+ panic!("failed to parse anything")
+ } else {
+ panic!("failed to parse all tokens")
+ }
+ }
+ Err(err) => panic!("failed to parse: {}", err),
+ }
+}
diff --git a/tests/common/respan.rs b/tests/common/respan.rs
index c9d12f5..0d5eeb3 100644
--- a/tests/common/respan.rs
+++ b/tests/common/respan.rs
@@ -1,19 +1,22 @@
+extern crate syntex_syntax;
+extern crate syntex_pos;
+
use std::rc::Rc;
-use syntex_syntax::ast::{Attribute, Expr, ExprKind, Field, FnDecl, FunctionRetTy, ImplItem,
+use self::syntex_syntax::ast::{Attribute, Expr, ExprKind, Field, FnDecl, FunctionRetTy, ImplItem,
ImplItemKind, ItemKind, Mac, MetaItem, MetaItemKind, MethodSig,
NestedMetaItem, NestedMetaItemKind, TraitItem, TraitItemKind, TyParam,
Visibility};
-use syntex_syntax::codemap::{self, Spanned};
-use syntex_syntax::fold::{self, Folder};
-use syntex_syntax::parse::token::{Lit, Token};
-use syntex_syntax::ptr::P;
-use syntex_syntax::symbol::Symbol;
-use syntex_syntax::tokenstream::{Delimited, TokenTree};
-use syntex_syntax::util::move_map::MoveMap;
-use syntex_syntax::util::small_vector::SmallVector;
+use self::syntex_syntax::codemap::{self, Spanned};
+use self::syntex_syntax::fold::{self, Folder};
+use self::syntex_syntax::parse::token::{Lit, Token};
+use self::syntex_syntax::ptr::P;
+use self::syntex_syntax::symbol::Symbol;
+use self::syntex_syntax::tokenstream::{Delimited, TokenTree};
+use self::syntex_syntax::util::move_map::MoveMap;
+use self::syntex_syntax::util::small_vector::SmallVector;
-use syntex_pos::{Span, DUMMY_SP};
-use syntex_syntax::ast;
+use self::syntex_pos::{Span, DUMMY_SP};
+use self::syntex_syntax::ast;
struct Respanner;