diff options
| author | Marijn Haverbeke <[email protected]> | 2011-03-29 14:07:41 +0200 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2011-03-31 14:41:40 +0000 |
| commit | 6a75740e96334407e8fcfcf5728eff2e7b8c3482 (patch) | |
| tree | 5709719d166444afea08ff15067d69fe1213e322 /src | |
| parent | Improve line comment positioning (diff) | |
| download | rust-6a75740e96334407e8fcfcf5728eff2e7b8c3482.tar.xz rust-6a75740e96334407e8fcfcf5728eff2e7b8c3482.zip | |
handle unterminated block comments and line comment at eof
Diffstat (limited to 'src')
| -rw-r--r-- | src/comp/front/lexer.rs | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/comp/front/lexer.rs b/src/comp/front/lexer.rs index 2229a4e6..6cead0bc 100644 --- a/src/comp/front/lexer.rs +++ b/src/comp/front/lexer.rs @@ -282,7 +282,7 @@ impure fn consume_any_line_comment(reader rdr) { if (rdr.curr() == '/') { alt (rdr.next()) { case ('/') { - while (rdr.curr() != '\n') { + while (rdr.curr() != '\n' && !rdr.is_eof()) { rdr.bump(); } // Restart whitespace munch. @@ -317,6 +317,10 @@ impure fn consume_block_comment(reader rdr) { rdr.bump(); } } + if (rdr.is_eof()) { + log "unterminated block comment"; + fail; + } } // restart whitespace munch. be consume_any_whitespace(rdr); @@ -800,9 +804,9 @@ impure fn consume_whitespace(reader rdr) -> uint { impure fn read_line_comment(reader rdr) -> cmnt { auto p = rdr.get_curr_pos(); rdr.bump(); rdr.bump(); - consume_whitespace(rdr); + while (rdr.curr() == ' ') {rdr.bump();} auto val = ""; - while (rdr.curr() != '\n') { + while (rdr.curr() != '\n' && !rdr.is_eof()) { _str.push_char(val, rdr.curr()); rdr.bump(); } @@ -814,7 +818,7 @@ impure fn read_line_comment(reader rdr) -> cmnt { impure fn read_block_comment(reader rdr) -> cmnt { auto p = rdr.get_curr_pos(); rdr.bump(); rdr.bump(); - consume_whitespace(rdr); + while (rdr.curr() == ' ') {rdr.bump();} let vec[str] lines = vec(); auto val = ""; auto level = 1; @@ -837,6 +841,7 @@ impure fn read_block_comment(reader rdr) -> cmnt { _str.push_char(val, rdr.curr()); rdr.bump(); } + if (rdr.is_eof()) {fail;} } ret rec(val=cmnt_block(lines), pos=p, |