about summary refs log tree commit diff
path: root/src/libsyntax/parse/comments.rs
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2014-03-20 11:21:17 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-03-20 18:51:52 -0700
commit84a91b860330c2b83fd0546b33a949079d422166 (patch)
tree1ef0a81e5d7d6c076ac9669a16fab8faa3c80b34 /src/libsyntax/parse/comments.rs
parent4e00cf613428d24d305a89e4f8e79b70ea8e8322 (diff)
downloadrust-84a91b860330c2b83fd0546b33a949079d422166.tar.gz
rust-84a91b860330c2b83fd0546b33a949079d422166.zip
syntax: Tidy up parsing the new attribute syntax
Diffstat (limited to 'src/libsyntax/parse/comments.rs')
-rw-r--r--src/libsyntax/parse/comments.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs
index 1221d8401be..43ae9b97350 100644
--- a/src/libsyntax/parse/comments.rs
+++ b/src/libsyntax/parse/comments.rs
@@ -12,7 +12,7 @@ use ast;
 use codemap::{BytePos, CharPos, CodeMap, Pos};
 use diagnostic;
 use parse::lexer::{is_whitespace, with_str_from, Reader};
-use parse::lexer::{StringReader, bump, peek, is_eof, nextch_is, TokenAndSpan};
+use parse::lexer::{StringReader, bump, is_eof, nextch_is, TokenAndSpan};
 use parse::lexer::{is_line_non_doc_comment, is_block_non_doc_comment};
 use parse::lexer;
 use parse::token;
@@ -319,7 +319,9 @@ fn read_block_comment(rdr: &StringReader,
 fn peeking_at_comment(rdr: &StringReader) -> bool {
     return (rdr.curr_is('/') && nextch_is(rdr, '/')) ||
          (rdr.curr_is('/') && nextch_is(rdr, '*')) ||
-         (rdr.curr_is('#') && nextch_is(rdr, '!'));
+         // consider shebangs comments, but not inner attributes
+         (rdr.curr_is('#') && nextch_is(rdr, '!') &&
+          !lexer::nextnextch_is(rdr, '['));
 }
 
 fn consume_comment(rdr: &StringReader,
@@ -331,11 +333,7 @@ fn consume_comment(rdr: &StringReader,
     } else if rdr.curr_is('/') && nextch_is(rdr, '*') {
         read_block_comment(rdr, code_to_the_left, comments);
     } else if rdr.curr_is('#') && nextch_is(rdr, '!') {
-        // Make sure the following token is **not** the beginning
-        // of an inner attribute, which starts with the same syntax.
-        if peek(rdr, 2).unwrap() != '[' {
-            read_shebang_comment(rdr, code_to_the_left, comments);
-        }
+        read_shebang_comment(rdr, code_to_the_left, comments);
     } else { fail!(); }
     debug!("<<< consume comment");
 }