diff options
| author | Gábor Lehel <glaebhoerl@gmail.com> | 2014-03-16 22:46:04 +0100 |
|---|---|---|
| committer | Sean McArthur <sean.monstar@gmail.com> | 2014-03-31 22:42:31 -0700 |
| commit | be673e77e75ece1611cdcf7b1b784ccd53cc9011 (patch) | |
| tree | 83f60a5f11809e936f289734e924d6918880d832 /src/libsyntax/parse/token.rs | |
| parent | b8ef9fd9c9f642ce7b8aed82782a1ed745d08d64 (diff) | |
| download | rust-be673e77e75ece1611cdcf7b1b784ccd53cc9011.tar.gz rust-be673e77e75ece1611cdcf7b1b784ccd53cc9011.zip | |
syntax: allow stmt/expr macro invocations to be delimited by [].
this is useful for macros like vec! which construct containers
Diffstat (limited to 'src/libsyntax/parse/token.rs')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 18 |
1 files changed, 7 insertions, 11 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 2c5698ddec4..ff1509fe23a 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -297,21 +297,17 @@ pub fn can_begin_expr(t: &Token) -> bool { } } -/// what's the opposite delimiter? -pub fn flip_delimiter(t: &token::Token) -> token::Token { +/// Returns the matching close delimiter if this is an open delimiter, +/// otherwise `None`. +pub fn close_delimiter_for(t: &Token) -> Option<Token> { match *t { - LPAREN => RPAREN, - LBRACE => RBRACE, - LBRACKET => RBRACKET, - RPAREN => LPAREN, - RBRACE => LBRACE, - RBRACKET => LBRACKET, - _ => fail!() + LPAREN => Some(RPAREN), + LBRACE => Some(RBRACE), + LBRACKET => Some(RBRACKET), + _ => None } } - - pub fn is_lit(t: &Token) -> bool { match *t { LIT_CHAR(_) => true, |
