diff options
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 2 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 22 |
3 files changed, 27 insertions, 9 deletions
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 5bace75a5ea..93fdcb41d2b 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -32,7 +32,7 @@ pub trait Reader { fn dup(&self) -> ~Reader:; } -#[deriving(Clone, Eq)] +#[deriving(Clone, Eq, Show)] pub struct TokenAndSpan { tok: token::Token, sp: Span, diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 9d0c9d0f4d3..6bcb7afb120 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -312,7 +312,7 @@ mod test { } #[test] fn path_exprs_1() { - assert_eq!(string_to_expr(~"a"), + assert!(string_to_expr(~"a") == @ast::Expr{ id: ast::DUMMY_NODE_ID, node: ast::ExprPath(ast::Path { @@ -331,7 +331,7 @@ mod test { } #[test] fn path_exprs_2 () { - assert_eq!(string_to_expr(~"::a::b"), + assert!(string_to_expr(~"::a::b") == @ast::Expr { id: ast::DUMMY_NODE_ID, node: ast::ExprPath(ast::Path { @@ -542,7 +542,7 @@ mod test { } #[test] fn ret_expr() { - assert_eq!(string_to_expr(~"return d"), + assert!(string_to_expr(~"return d") == @ast::Expr{ id: ast::DUMMY_NODE_ID, node:ast::ExprRet(Some(@ast::Expr{ @@ -565,7 +565,7 @@ mod test { } #[test] fn parse_stmt_1 () { - assert_eq!(string_to_stmt(~"b;"), + assert!(string_to_stmt(~"b;") == @Spanned{ node: ast::StmtExpr(@ast::Expr { id: ast::DUMMY_NODE_ID, @@ -592,7 +592,7 @@ mod test { #[test] fn parse_ident_pat () { let mut parser = string_to_parser(~"b"); - assert_eq!(parser.parse_pat(), + assert!(parser.parse_pat() == @ast::Pat{id: ast::DUMMY_NODE_ID, node: ast::PatIdent( ast::BindByValue(ast::MutImmutable), @@ -615,7 +615,7 @@ mod test { // check the contents of the tt manually: #[test] fn parse_fundecl () { // this test depends on the intern order of "fn" and "int" - assert_eq!(string_to_item(~"fn a (b : int) { b; }"), + assert!(string_to_item(~"fn a (b : int) { b; }") == Some( @ast::Item{ident:str_to_ident("a"), attrs:~[], diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 528eb7d54f3..edc5e613f91 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -23,7 +23,7 @@ use std::local_data; use std::path::BytesContainer; #[allow(non_camel_case_types)] -#[deriving(Clone, Encodable, Decodable, Eq, Hash)] +#[deriving(Clone, Encodable, Decodable, Eq, Hash, Show)] pub enum BinOp { PLUS, MINUS, @@ -38,7 +38,7 @@ pub enum BinOp { } #[allow(non_camel_case_types)] -#[deriving(Clone, Encodable, Decodable, Eq, Hash)] +#[deriving(Clone, Encodable, Decodable, Eq, Hash, Show)] pub enum Token { /* Expression-operator symbols. */ EQ, @@ -118,6 +118,24 @@ pub enum Nonterminal { NtMatchers(~[ast::Matcher]) } +impl fmt::Show for Nonterminal { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + match *self { + NtItem(..) => f.pad("NtItem(..)"), + NtBlock(..) => f.pad("NtBlock(..)"), + NtStmt(..) => f.pad("NtStmt(..)"), + NtPat(..) => f.pad("NtPat(..)"), + NtExpr(..) => f.pad("NtExpr(..)"), + NtTy(..) => f.pad("NtTy(..)"), + NtIdent(..) => f.pad("NtIdent(..)"), + NtAttr(..) => f.pad("NtAttr(..)"), + NtPath(..) => f.pad("NtPath(..)"), + NtTT(..) => f.pad("NtTT(..)"), + NtMatchers(..) => f.pad("NtMatchers(..)"), + } + } +} + pub fn binop_to_str(o: BinOp) -> ~str { match o { PLUS => ~"+", |
