diff options
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 56 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 5 |
3 files changed, 52 insertions, 10 deletions
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index c848f52b3ea..09adcc66ea5 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -875,7 +875,6 @@ fn consume_whitespace(rdr: @mut StringReader) { mod test { use super::*; - use ast; use codemap::{BytePos, CodeMap, Span}; use diagnostic; use parse::token; diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 91ef55c78f6..37f2f8345cd 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -324,17 +324,10 @@ mod test { use abi; use parse::parser::Parser; use parse::token::{str_to_ident}; - use util::parser_testing::{string_to_tts_and_sess, string_to_parser}; + use util::parser_testing::{string_to_tts, string_to_parser}; use util::parser_testing::{string_to_expr, string_to_item}; use util::parser_testing::string_to_stmt; - // map a string to tts, return the tt without its parsesess - fn string_to_tts_only(source_str : @str) -> ~[ast::token_tree] { - let (tts,_ps) = string_to_tts_and_sess(source_str); - tts - } - - #[cfg(test)] fn to_json_str<E : Encodable<extra::json::Encoder>>(val: @E) -> ~str { do io::with_str_writer |writer| { let mut encoder = extra::json::Encoder(writer); @@ -395,8 +388,53 @@ mod test { string_to_expr(@"::abc::def::return"); } + // check the token-tree-ization of macros + #[test] fn string_to_tts_macro () { + let tts = string_to_tts(@"macro_rules! zip (($a)=>($a))"); + match tts { + [ast::tt_tok(_,_), + ast::tt_tok(_,token::NOT), + ast::tt_tok(_,_), + ast::tt_delim(delim_elts)] => + match *delim_elts { + [ast::tt_tok(_,token::LPAREN), + ast::tt_delim(first_set), + ast::tt_tok(_,token::FAT_ARROW), + ast::tt_delim(second_set), + ast::tt_tok(_,token::RPAREN)] => + match *first_set { + [ast::tt_tok(_,token::LPAREN), + ast::tt_tok(_,token::DOLLAR), + ast::tt_tok(_,_), + ast::tt_tok(_,token::RPAREN)] => + match *second_set { + [ast::tt_tok(_,token::LPAREN), + ast::tt_tok(_,token::DOLLAR), + ast::tt_tok(_,_), + ast::tt_tok(_,token::RPAREN)] => + assert_eq!("correct","correct"), + _ => assert_eq!("wrong 4","correct") + }, + _ => { + error!("failing value 3: %?",first_set); + assert_eq!("wrong 3","correct") + } + }, + _ => { + error!("failing value 2: %?",delim_elts); + assert_eq!("wrong","correct"); + } + + }, + _ => { + error!("failing value: %?",tts); + assert_eq!("wrong 1","correct"); + } + } + } + #[test] fn string_to_tts_1 () { - let (tts,_ps) = string_to_tts_and_sess(@"fn a (b : int) { b; }"); + let tts = string_to_tts(@"fn a (b : int) { b; }"); assert_eq!(to_json_str(@tts), ~"[\ {\ diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 72e70e11bcb..74447b5dae1 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2035,6 +2035,11 @@ impl Parser { // parse a single token tree from the input. pub fn parse_token_tree(&self) -> token_tree { + // FIXME #6994: currently, this is too eager. It + // parses token trees but also identifies tt_seq's + // and tt_nonterminals; it's too early to know yet + // whether something will be a nonterminal or a seq + // yet. maybe_whole!(deref self, nt_tt); // this is the fall-through for the 'match' below. |
