Skip to content

Commit

Permalink
auto merge of #9936 : madjar/rust/master, r=alexcrichton
Browse files Browse the repository at this point in the history
This should close #9468.

I removed the test stating that nested comments should not be implemented.

I had a little chicken-and-egg problem because a comment of the std contains "/*", and adding support for nested comment creates a backward incompatibility in that case, so I had to use a dirty hack to get stage1 and stage2 to compile. This part should be revert when this commit lands in a snapshot.

This is my first non-typo contribution, so I'm open to any comment.
  • Loading branch information
bors committed Oct 21, 2013
2 parents ece5028 + 1dc3d0b commit 6dd6623
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 75 deletions.
52 changes: 26 additions & 26 deletions src/libextra/glob.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,32 @@ pub struct GlobIterator {
priv todo: ~[(Path,uint)]
}

/**
* Return an iterator that produces all the Paths that match the given pattern,
* which may be absolute or relative to the current working directory.
*
* This method uses the default match options and is equivalent to calling
* `glob_with(pattern, MatchOptions::new())`. Use `glob_with` directly if you
* want to use non-default match options.
*
* # Example
*
* Consider a directory `/media/pictures` containing only the files `kittens.jpg`,
* `puppies.jpg` and `hamsters.gif`:
*
* ```rust
* for path in glob("/media/pictures/*.jpg") {
* println(path.to_str());
* }
* ```
*
* The above code will print:
*
* ```
* /media/pictures/kittens.jpg
* /media/pictures/puppies.jpg
* ```
*/
///
/// Return an iterator that produces all the Paths that match the given pattern,
/// which may be absolute or relative to the current working directory.
///
/// is method uses the default match options and is equivalent to calling
/// `glob_with(pattern, MatchOptions::new())`. Use `glob_with` directly if you
/// want to use non-default match options.
///
/// # Example
///
/// Consider a directory `/media/pictures` containing only the files `kittens.jpg`,
/// `puppies.jpg` and `hamsters.gif`:
///
/// ```rust
/// for path in glob("/media/pictures/*.jpg") {
/// println(path.to_str());
/// }
/// ```
///
/// The above code will print:
///
/// ```
/// /media/pictures/kittens.jpg
/// /media/pictures/puppies.jpg
/// ```
///
pub fn glob(pattern: &str) -> GlobIterator {
glob_with(pattern, MatchOptions::new())
}
Expand Down
6 changes: 0 additions & 6 deletions src/libstd/os.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,12 +546,6 @@ pub fn self_exe_path() -> Option<Path> {
load_self().and_then(|path| Path::new_opt(path).map(|mut p| { p.pop(); p }))
}


/**
* Returns the path to the user's home directory, if known.
}


/**
* Returns the path to the user's home directory, if known.
*
Expand Down
74 changes: 41 additions & 33 deletions src/libsyntax/parse/lexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,49 +373,49 @@ pub fn is_block_non_doc_comment(s: &str) -> bool {
fn consume_block_comment(rdr: @mut StringReader)
-> Option<TokenAndSpan> {
// block comments starting with "/**" or "/*!" are doc-comments
let res = if rdr.curr == '*' || rdr.curr == '!' {
let start_bpos = rdr.pos - BytePos(3u);
while !(rdr.curr == '*' && nextch(rdr) == '/') && !is_eof(rdr) {
bump(rdr);
}
let is_doc_comment = rdr.curr == '*' || rdr.curr == '!';
let start_bpos = rdr.pos - BytePos(if is_doc_comment {3u} else {2u});

let mut level: int = 1;
while level > 0 {
if is_eof(rdr) {
fatal_span(rdr, start_bpos, rdr.last_pos,
~"unterminated block doc-comment");
} else {
let msg = if is_doc_comment {
~"unterminated block doc-comment"
} else {
~"unterminated block comment"
};
fatal_span(rdr, start_bpos, rdr.last_pos, msg);
} else if rdr.curr == '/' && nextch(rdr) == '*' {
level += 1;
bump(rdr);
bump(rdr);
do with_str_from(rdr, start_bpos) |string| {
// but comments with only "*"s between two "/"s are not
if !is_block_non_doc_comment(string) {
Some(TokenAndSpan{
tok: token::DOC_COMMENT(str_to_ident(string)),
sp: codemap::mk_sp(start_bpos, rdr.pos)
})
} else {
None
}
}
} else if rdr.curr == '*' && nextch(rdr) == '/' {
level -= 1;
bump(rdr);
bump(rdr);
} else {
bump(rdr);
}
} else {
let start_bpos = rdr.last_pos - BytePos(2u);
loop {
if is_eof(rdr) {
fatal_span(rdr, start_bpos, rdr.last_pos,
~"unterminated block comment");
}
if rdr.curr == '*' && nextch(rdr) == '/' {
bump(rdr);
bump(rdr);
break;
}

let res = if is_doc_comment {
do with_str_from(rdr, start_bpos) |string| {
// but comments with only "*"s between two "/"s are not
if !is_block_non_doc_comment(string) {
Some(TokenAndSpan{
tok: token::DOC_COMMENT(str_to_ident(string)),
sp: codemap::mk_sp(start_bpos, rdr.pos)
})
} else {
bump(rdr);
None
}
}
} else {
None
};
// restart whitespace munch.

if res.is_some() { res } else { consume_whitespace_and_comments(rdr) }
// restart whitespace munch.
if res.is_some() { res } else { consume_whitespace_and_comments(rdr) }
}

fn scan_exponent(rdr: @mut StringReader, start_bpos: BytePos) -> Option<~str> {
Expand Down Expand Up @@ -1056,4 +1056,12 @@ mod test {
assert!(!is_line_non_doc_comment("/// blah"));
assert!(is_line_non_doc_comment("////"));
}

#[test] fn nested_block_comments() {
let env = setup(@"/* /* */ */'a'");
let TokenAndSpan {tok, sp: _} =
env.string_reader.next_token();
assert_eq!(tok,token::LIT_CHAR('a' as u32));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,12 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// error-pattern:

/* This is a test to ensure that we do _not_ support nested/balanced comments. I know you might be
thinking "but nested comments are cool", and that would be a valid point, but they are also a
thing that would make our lexical syntax non-regular, and we do not want that to be true.
omitting-things at a higher level (tokens) should be done via token-trees / macros,
not comments.
/* This test checks that nested comments are supported
/*
fail here
This should not fail
*/
*/

fn main() {
pub fn main() {
}

0 comments on commit 6dd6623

Please sign in to comment.