diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2014-03-20 11:21:17 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-03-20 18:51:52 -0700 |
| commit | 84a91b860330c2b83fd0546b33a949079d422166 (patch) | |
| tree | 1ef0a81e5d7d6c076ac9669a16fab8faa3c80b34 /src | |
| parent | 4e00cf613428d24d305a89e4f8e79b70ea8e8322 (diff) | |
| download | rust-84a91b860330c2b83fd0546b33a949079d422166.tar.gz rust-84a91b860330c2b83fd0546b33a949079d422166.zip | |
syntax: Tidy up parsing the new attribute syntax
Diffstat (limited to 'src')
| -rw-r--r-- | src/compiletest/compiletest.rs | 1 | ||||
| -rw-r--r-- | src/libarena/lib.rs | 1 | ||||
| -rw-r--r-- | src/libgreen/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustuv/lib.rs | 1 | ||||
| -rw-r--r-- | src/libsyntax/parse/attr.rs | 46 | ||||
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 12 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 30 | ||||
| -rw-r--r-- | src/libtest/lib.rs | 1 | ||||
| -rw-r--r-- | src/test/compile-fail/attr.rs | 4 | ||||
| -rw-r--r-- | src/test/compile-fail/column-offset-1-based.rs | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/issue-1655.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/attr-mix-new.rs | 2 | ||||
| -rw-r--r-- | src/test/run-pass/attr-shebang.rs | 5 | ||||
| -rw-r--r-- | src/test/run-pass/attr.rs | 2 |
14 files changed, 56 insertions, 54 deletions
diff --git a/src/compiletest/compiletest.rs b/src/compiletest/compiletest.rs index ae7f3246272..855bc1e5852 100644 --- a/src/compiletest/compiletest.rs +++ b/src/compiletest/compiletest.rs @@ -12,6 +12,7 @@ #[feature(phase)]; #[allow(non_camel_case_types)]; +#[allow(deprecated_owned_vector)]; // NOTE: remove after stage0 #[deny(warnings)]; extern crate test; diff --git a/src/libarena/lib.rs b/src/libarena/lib.rs index 2cc41dd7085..dbebb8fb2bc 100644 --- a/src/libarena/lib.rs +++ b/src/libarena/lib.rs @@ -24,6 +24,7 @@ html_root_url = "http://static.rust-lang.org/doc/master")]; #[allow(missing_doc)]; #[feature(managed_boxes)]; +#[allow(deprecated_owned_vector)]; // NOTE: remove after stage0 extern crate collections; diff --git a/src/libgreen/lib.rs b/src/libgreen/lib.rs index a23d2d4f3a5..b9846c9c3a2 100644 --- a/src/libgreen/lib.rs +++ b/src/libgreen/lib.rs @@ -174,6 +174,7 @@ // NB this does *not* include globs, please keep it that way. #[feature(macro_rules, phase)]; #[allow(visible_private_types)]; +#[allow(deprecated_owned_vector)]; // NOTE: remove after stage0 #[cfg(test)] #[phase(syntax, link)] extern crate log; extern crate rand; diff --git a/src/librustuv/lib.rs b/src/librustuv/lib.rs index 890f44faabc..ee4f15e7954 100644 --- a/src/librustuv/lib.rs +++ b/src/librustuv/lib.rs @@ -42,6 +42,7 @@ via `close` and `delete` methods. #[feature(macro_rules)]; #[deny(unused_result, unused_must_use)]; #[allow(visible_private_types)]; +#[allow(deprecated_owned_vector)]; // NOTE: remove after stage0 #[cfg(test)] extern crate green; diff --git a/src/libsyntax/parse/attr.rs b/src/libsyntax/parse/attr.rs index 92b93fd88dd..8f7fb5749a1 100644 --- a/src/libsyntax/parse/attr.rs +++ b/src/libsyntax/parse/attr.rs @@ -58,41 +58,40 @@ impl<'a> ParserAttr for Parser<'a> { return attrs; } - // matches attribute = # [ meta_item ] + // matches attribute = # ! [ meta_item ] // - // if permit_inner is true, then a trailing `;` indicates an inner + // if permit_inner is true, then a leading `!` indicates an inner // attribute fn parse_attribute(&mut self, permit_inner: bool) -> ast::Attribute { debug!("parse_attributes: permit_inner={:?} self.token={:?}", permit_inner, self.token); - let mut warned = false; - let (span, value) = match self.token { + let (span, value, mut style) = match self.token { INTERPOLATED(token::NtAttr(attr)) => { assert!(attr.node.style == ast::AttrOuter); self.bump(); - (attr.span, attr.node.value) + (attr.span, attr.node.value, ast::AttrOuter) } token::POUND => { let lo = self.span.lo; self.bump(); - if self.eat(&token::NOT) { + let style = if self.eat(&token::NOT) { if !permit_inner { - self.fatal("an inner attribute was not permitted in this context."); + self.span_err(self.span, + "an inner attribute is not permitted in \ + this context"); } + ast::AttrInner } else { - warned = true; - // NOTE: uncomment this after a stage0 snap - //self.warn("The syntax for inner attributes have changed. - // Use `#![lang(foo)]` instead."); - } + ast::AttrOuter + }; self.expect(&token::LBRACKET); let meta_item = self.parse_meta_item(); self.expect(&token::RBRACKET); let hi = self.span.hi; - (mk_sp(lo, hi), meta_item) + (mk_sp(lo, hi), meta_item, style) } _ => { let token_str = self.this_token_to_str(); @@ -101,21 +100,12 @@ impl<'a> ParserAttr for Parser<'a> { } }; - let style = if permit_inner { - - if self.eat(&token::SEMI) { - // Only warn the user once if the syntax is the old one. - if !warned { - // NOTE: uncomment this after a stage0 snap - //self.warn("This uses the old attribute syntax. Semicolons - // are not longer required."); - } - } - - ast::AttrInner - } else { - ast::AttrOuter - }; + if permit_inner && self.eat(&token::SEMI) { + // NOTE: uncomment this after a stage0 snap + //self.warn("This uses the old attribute syntax. Semicolons + // are not longer required."); + style = ast::AttrInner; + } return Spanned { span: span, 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"); } diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index 061d460af5e..ca2fbd24587 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -18,9 +18,10 @@ use parse::token::{str_to_ident}; use std::cell::{Cell, RefCell}; use std::char; -use std::rc::Rc; use std::mem::replace; use std::num::from_str_radix; +use std::rc::Rc; +use std::str; pub use ext::tt::transcribe::{TtReader, new_tt_reader}; @@ -272,16 +273,6 @@ pub fn bump(rdr: &StringReader) { } } -// 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() } @@ -298,6 +289,21 @@ pub fn nextch_is(rdr: &StringReader, c: char) -> bool { nextch(rdr) == Some(c) } +pub fn nextnextch(rdr: &StringReader) -> Option<char> { + let offset = byte_offset(rdr, rdr.pos.get()).to_uint(); + let s = rdr.filemap.deref().src.as_slice(); + if offset >= s.len() { return None } + let str::CharRange { next, .. } = s.char_range_at(offset); + if next < s.len() { + Some(s.char_at(next)) + } else { + None + } +} +pub fn nextnextch_is(rdr: &StringReader, c: char) -> bool { + nextnextch(rdr) == Some(c) +} + fn hex_digit_val(c: Option<char>) -> int { let d = c.unwrap_or('\x00'); @@ -384,7 +390,7 @@ fn consume_any_line_comment(rdr: &StringReader) if nextch_is(rdr, '!') { // Parse an inner attribute. - if peek(rdr, 2).unwrap() == '[' { + if nextnextch_is(rdr, '[') { return None; } diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 3ec80d97d06..ec7d48cf12b 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -33,6 +33,7 @@ html_root_url = "http://static.rust-lang.org/doc/master")]; #[feature(asm, macro_rules)]; +#[allow(deprecated_owned_vector)]; // NOTE: remove after stage0 extern crate collections; extern crate getopts; diff --git a/src/test/compile-fail/attr.rs b/src/test/compile-fail/attr.rs index 4107c84c472..b1f7a791f09 100644 --- a/src/test/compile-fail/attr.rs +++ b/src/test/compile-fail/attr.rs @@ -10,5 +10,5 @@ fn main() {} -#![lang(foo)] //~ ERROR An inner attribute was not permitted in this context. -fn foo() {} \ No newline at end of file +#![lang(foo)] //~ ERROR an inner attribute is not permitted in this context +fn foo() {} diff --git a/src/test/compile-fail/column-offset-1-based.rs b/src/test/compile-fail/column-offset-1-based.rs index 5b38b17ad95..3a6594f64f3 100644 --- a/src/test/compile-fail/column-offset-1-based.rs +++ b/src/test/compile-fail/column-offset-1-based.rs @@ -8,4 +8,4 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -# //~ ERROR 11:1: 11:2 error: expected item +# //~ ERROR 11:1: 11:2 error: expected `[` but found `<eof>` diff --git a/src/test/compile-fail/issue-1655.rs b/src/test/compile-fail/issue-1655.rs index 37cfc642405..e2810b854f7 100644 --- a/src/test/compile-fail/issue-1655.rs +++ b/src/test/compile-fail/issue-1655.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:expected item +// error-pattern:expected `[` but found `~` mod blade_runner { #~[doc( brief = "Blade Runner is probably the best movie ever", diff --git a/src/test/run-pass/attr-mix-new.rs b/src/test/run-pass/attr-mix-new.rs index 397b49df915..af615912f28 100644 --- a/src/test/run-pass/attr-mix-new.rs +++ b/src/test/run-pass/attr-mix-new.rs @@ -13,4 +13,4 @@ mod foo { #![feature(globs)] } -fn main() {} \ No newline at end of file +pub fn main() {} diff --git a/src/test/run-pass/attr-shebang.rs b/src/test/run-pass/attr-shebang.rs index 12f568dd472..f4919f768b9 100644 --- a/src/test/run-pass/attr-shebang.rs +++ b/src/test/run-pass/attr-shebang.rs @@ -1,4 +1,5 @@ #![allow(unknown_features)] #![feature(bogus)] -fn main() { } -// ignore-license \ No newline at end of file +pub fn main() { } +// ignore-license +// ignore-fast diff --git a/src/test/run-pass/attr.rs b/src/test/run-pass/attr.rs index 2f30eb8154f..6a19a44e074 100644 --- a/src/test/run-pass/attr.rs +++ b/src/test/run-pass/attr.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +// ignore-fast + #[main] fn foo() { } |
