diff options
| author | bors <bors@rust-lang.org> | 2014-02-08 00:26:30 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-02-08 00:26:30 -0800 |
| commit | 95483e30a2fd18ddb72c50a17a87cf8439c8f2bd (patch) | |
| tree | 4510ca2aed050f97a950954d5ba0d8b14cd0d066 /src/libsyntax/parse/comments.rs | |
| parent | b2c1a8164905e4130200287d5c38063f242a2ab1 (diff) | |
| parent | 5e2de79b3054a815a45b9f4c641d7f1356f2291b (diff) | |
| download | rust-95483e30a2fd18ddb72c50a17a87cf8439c8f2bd.tar.gz rust-95483e30a2fd18ddb72c50a17a87cf8439c8f2bd.zip | |
auto merge of #12086 : huonw/rust/safe-json, r=kballard
The lexer and json were using `transmute(-1): char` as a sentinel value for EOF, which is invalid since `char` is strictly a unicode codepoint. Fixing this allows for range asserts on chars since they always lie between 0 and 0x10FFFF.
Diffstat (limited to 'src/libsyntax/parse/comments.rs')
| -rw-r--r-- | src/libsyntax/parse/comments.rs | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/src/libsyntax/parse/comments.rs b/src/libsyntax/parse/comments.rs index 77b047a63c3..138f9d71640 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, is_eof, nextch, 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; @@ -136,11 +136,11 @@ pub fn strip_doc_comment_decoration(comment: &str) -> ~str { fn read_to_eol(rdr: &StringReader) -> ~str { let mut val = ~""; - while rdr.curr.get() != '\n' && !is_eof(rdr) { - val.push_char(rdr.curr.get()); + while !rdr.curr_is('\n') && !is_eof(rdr) { + val.push_char(rdr.curr.get().unwrap()); bump(rdr); } - if rdr.curr.get() == '\n' { bump(rdr); } + if rdr.curr_is('\n') { bump(rdr); } return val; } @@ -152,7 +152,7 @@ fn read_one_line_comment(rdr: &StringReader) -> ~str { } fn consume_non_eol_whitespace(rdr: &StringReader) { - while is_whitespace(rdr.curr.get()) && rdr.curr.get() != '\n' && + while is_whitespace(rdr.curr.get()) && !rdr.curr_is('\n') && !is_eof(rdr) { bump(rdr); } @@ -171,7 +171,7 @@ fn push_blank_line_comment(rdr: &StringReader, comments: &mut ~[Comment]) { fn consume_whitespace_counting_blank_lines(rdr: &StringReader, comments: &mut ~[Comment]) { while is_whitespace(rdr.curr.get()) && !is_eof(rdr) { - if rdr.col.get() == CharPos(0u) && rdr.curr.get() == '\n' { + if rdr.col.get() == CharPos(0u) && rdr.curr_is('\n') { push_blank_line_comment(rdr, &mut *comments); } bump(rdr); @@ -196,7 +196,7 @@ fn read_line_comments(rdr: &StringReader, code_to_the_left: bool, debug!(">>> line comments"); let p = rdr.last_pos.get(); let mut lines: ~[~str] = ~[]; - while rdr.curr.get() == '/' && nextch(rdr) == '/' { + while rdr.curr_is('/') && nextch_is(rdr, '/') { let line = read_one_line_comment(rdr); debug!("{}", line); if is_doc_comment(line) { // doc-comments are not put in comments @@ -261,9 +261,9 @@ fn read_block_comment(rdr: &StringReader, let mut curr_line = ~"/*"; // doc-comments are not really comments, they are attributes - if rdr.curr.get() == '*' || rdr.curr.get() == '!' { - while !(rdr.curr.get() == '*' && nextch(rdr) == '/') && !is_eof(rdr) { - curr_line.push_char(rdr.curr.get()); + if rdr.curr_is('*') || rdr.curr_is('!') { + while !(rdr.curr_is('*') && nextch_is(rdr, '/')) && !is_eof(rdr) { + curr_line.push_char(rdr.curr.get().unwrap()); bump(rdr); } if !is_eof(rdr) { @@ -281,20 +281,20 @@ fn read_block_comment(rdr: &StringReader, if is_eof(rdr) { rdr.fatal(~"unterminated block comment"); } - if rdr.curr.get() == '\n' { + if rdr.curr_is('\n') { trim_whitespace_prefix_and_push_line(&mut lines, curr_line, col); curr_line = ~""; bump(rdr); } else { - curr_line.push_char(rdr.curr.get()); - if rdr.curr.get() == '/' && nextch(rdr) == '*' { + curr_line.push_char(rdr.curr.get().unwrap()); + if rdr.curr_is('/') && nextch_is(rdr, '*') { bump(rdr); bump(rdr); curr_line.push_char('*'); level += 1; } else { - if rdr.curr.get() == '*' && nextch(rdr) == '/' { + if rdr.curr_is('*') && nextch_is(rdr, '/') { bump(rdr); bump(rdr); curr_line.push_char('/'); @@ -310,7 +310,7 @@ fn read_block_comment(rdr: &StringReader, let mut style = if code_to_the_left { Trailing } else { Isolated }; consume_non_eol_whitespace(rdr); - if !is_eof(rdr) && rdr.curr.get() != '\n' && lines.len() == 1u { + if !is_eof(rdr) && !rdr.curr_is('\n') && lines.len() == 1u { style = Mixed; } debug!("<<< block comment"); @@ -318,20 +318,20 @@ fn read_block_comment(rdr: &StringReader, } fn peeking_at_comment(rdr: &StringReader) -> bool { - return ((rdr.curr.get() == '/' && nextch(rdr) == '/') || - (rdr.curr.get() == '/' && nextch(rdr) == '*')) || - (rdr.curr.get() == '#' && nextch(rdr) == '!'); + return (rdr.curr_is('/') && nextch_is(rdr, '/')) || + (rdr.curr_is('/') && nextch_is(rdr, '*')) || + (rdr.curr_is('#') && nextch_is(rdr, '!')); } fn consume_comment(rdr: &StringReader, code_to_the_left: bool, comments: &mut ~[Comment]) { debug!(">>> consume comment"); - if rdr.curr.get() == '/' && nextch(rdr) == '/' { + if rdr.curr_is('/') && nextch_is(rdr, '/') { read_line_comments(rdr, code_to_the_left, comments); - } else if rdr.curr.get() == '/' && nextch(rdr) == '*' { + } else if rdr.curr_is('/') && nextch_is(rdr, '*') { read_block_comment(rdr, code_to_the_left, comments); - } else if rdr.curr.get() == '#' && nextch(rdr) == '!' { + } else if rdr.curr_is('#') && nextch_is(rdr, '!') { read_shebang_comment(rdr, code_to_the_left, comments); } else { fail!(); } debug!("<<< consume comment"); @@ -363,7 +363,7 @@ pub fn gather_comments_and_literals(span_diagnostic: loop { let mut code_to_the_left = !first_read; consume_non_eol_whitespace(&rdr); - if rdr.curr.get() == '\n' { + if rdr.curr_is('\n') { code_to_the_left = false; consume_whitespace_counting_blank_lines(&rdr, &mut comments); } |
