about summary refs log tree commit diff
path: root/src/libsyntax/parse/lexer.rs
diff options
context:
space:
mode:
authorDaniel Fagnan <dnfagnan@gmail.com>2014-02-24 19:42:40 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-03-20 18:06:53 -0700
commit4e00cf613428d24d305a89e4f8e79b70ea8e8322 (patch)
tree183c414832596437bfc0e6a04b81f8542cbd53c0 /src/libsyntax/parse/lexer.rs
parent6eae7df43cd21b76fe91eeaf6ef2af9bd2a8fafc (diff)
downloadrust-4e00cf613428d24d305a89e4f8e79b70ea8e8322.tar.gz
rust-4e00cf613428d24d305a89e4f8e79b70ea8e8322.zip
Added new attribute syntax with backward compatibility.
Signed-off-by: Daniel Fagnan <dnfagnan@gmail.com>
Diffstat (limited to 'src/libsyntax/parse/lexer.rs')
-rw-r--r--src/libsyntax/parse/lexer.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs
index 58ec6acc3ac..061d460af5e 100644
--- a/src/libsyntax/parse/lexer.rs
+++ b/src/libsyntax/parse/lexer.rs
@@ -271,9 +271,21 @@ pub fn bump(rdr: &StringReader) {
         rdr.curr.set(None);
     }
 }
+
+// EFFECT: Peek 'n' characters ahead.
+pub fn peek(rdr: &StringReader, n: uint) -> Option<char> {
+    let offset = byte_offset(rdr, rdr.pos.get()).to_uint() + (n - 1);
+    if offset < (rdr.filemap.src).len() {
+        Some(rdr.filemap.src.char_at(offset))
+    } else {
+        None
+    }
+}
+
 pub fn is_eof(rdr: &StringReader) -> bool {
     rdr.curr.get().is_none()
 }
+
 pub fn nextch(rdr: &StringReader) -> Option<char> {
     let offset = byte_offset(rdr, rdr.pos.get()).to_uint();
     if offset < rdr.filemap.deref().src.len() {
@@ -370,6 +382,12 @@ fn consume_any_line_comment(rdr: &StringReader)
         }
     } else if rdr.curr_is('#') {
         if nextch_is(rdr, '!') {
+
+            // Parse an inner attribute.
+            if peek(rdr, 2).unwrap() == '[' {
+                return None;
+            }
+
             // I guess this is the only way to figure out if
             // we're at the beginning of the file...
             let cmap = CodeMap::new();