diff options
| author | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-10-22 16:37:20 +1100 |
|---|---|---|
| committer | Brendan Zabarauskas <bjzaba@yahoo.com.au> | 2014-10-26 09:53:29 +1100 |
| commit | 971d776aa5a678672eb3d37f2f507664aacd2440 (patch) | |
| tree | 050e68a9c76a8bf969778396b42c44060671c241 /src/libsyntax/parse/mod.rs | |
| parent | 80e5fe1a56bb95e8e89d5f8f0ff5122583bb5336 (diff) | |
| download | rust-971d776aa5a678672eb3d37f2f507664aacd2440.tar.gz rust-971d776aa5a678672eb3d37f2f507664aacd2440.zip | |
Add Span and separate open/close delims to TTDelim
This came up when working [on the gl-rs generator extension](https://github.com/bjz/gl-rs/blob/990383de801bd2e233159d5be07c9b5622827620/src/gl_generator/lib.rs#L135-L146). The new definition of `TTDelim` adds an associated `Span` that covers the whole token tree and enforces the invariant that a delimited sequence of token trees must have an opening and closing delimiter. A `get_span` method has also been added to `TokenTree` type to make it easier to implement better error messages for syntax extensions.
Diffstat (limited to 'src/libsyntax/parse/mod.rs')
| -rw-r--r-- | src/libsyntax/parse/mod.rs | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/src/libsyntax/parse/mod.rs b/src/libsyntax/parse/mod.rs index 2d7d32cd9ea..1c99b608f7a 100644 --- a/src/libsyntax/parse/mod.rs +++ b/src/libsyntax/parse/mod.rs @@ -788,35 +788,34 @@ mod test { } // check the token-tree-ization of macros - #[test] fn string_to_tts_macro () { + #[test] + fn string_to_tts_macro () { let tts = string_to_tts("macro_rules! zip (($a)=>($a))".to_string()); let tts: &[ast::TokenTree] = tts.as_slice(); match tts { - [ast::TTTok(_,_), - ast::TTTok(_,token::NOT), - ast::TTTok(_,_), - ast::TTDelim(ref delim_elts)] => { + [ast::TTTok(_, _), + ast::TTTok(_, token::NOT), + ast::TTTok(_, _), + ast::TTDelim(_, ast::TTTok(_, token::LPAREN), + ref delim_elts, + ast::TTTok(_, token::RPAREN))] => { let delim_elts: &[ast::TokenTree] = delim_elts.as_slice(); match delim_elts { - [ast::TTTok(_,token::LPAREN), - ast::TTDelim(ref first_set), - ast::TTTok(_,token::FAT_ARROW), - ast::TTDelim(ref second_set), - ast::TTTok(_,token::RPAREN)] => { + [ast::TTDelim(_, ast::TTTok(_, token::LPAREN), + ref first_set, + ast::TTTok(_, token::RPAREN)), + ast::TTTok(_, token::FAT_ARROW), + ast::TTDelim(_, ast::TTTok(_, token::LPAREN), + ref second_set, + ast::TTTok(_, token::RPAREN))] => { let first_set: &[ast::TokenTree] = first_set.as_slice(); match first_set { - [ast::TTTok(_,token::LPAREN), - ast::TTTok(_,token::DOLLAR), - ast::TTTok(_,_), - ast::TTTok(_,token::RPAREN)] => { + [ast::TTTok(_, token::DOLLAR), ast::TTTok(_, _)] => { let second_set: &[ast::TokenTree] = second_set.as_slice(); match second_set { - [ast::TTTok(_,token::LPAREN), - ast::TTTok(_,token::DOLLAR), - ast::TTTok(_,_), - ast::TTTok(_,token::RPAREN)] => { + [ast::TTTok(_, token::DOLLAR), ast::TTTok(_, _)] => { assert_eq!("correct","correct") } _ => assert_eq!("wrong 4","correct") @@ -837,7 +836,7 @@ mod test { _ => { error!("failing value: {}",tts); assert_eq!("wrong 1","correct"); - } + }, } } |
