Fix some naughtiness of handling newlines in bracequotes and multi-line comments. Closes #142.

This commit is contained in:
Graydon Hoare 2010-08-03 16:28:50 -07:00
parent 1fc4e9fcc6
commit a1ecdb103d
2 changed files with 23 additions and 7 deletions

View file

@ -22,6 +22,11 @@
Lexing.pos_bol = p.Lexing.pos_cnum }
;;
let newline lexbuf =
lexbuf.Lexing.lex_curr_p
<- (bump_line lexbuf.Lexing.lex_curr_p)
;;
let mach_suf_table = Hashtbl.create 0
;;
let _ =
@ -155,8 +160,7 @@ let id = ['a'-'z' 'A'-'Z' '_']['a'-'z' 'A'-'Z' '0'-'9' '_']*
rule token = parse
ws+ { token lexbuf }
| '\n' { lexbuf.Lexing.lex_curr_p
<- (bump_line lexbuf.Lexing.lex_curr_p);
| '\n' { newline lexbuf;
token lexbuf }
| "//" [^'\n']* { token lexbuf }
| "/*" { comment 1 lexbuf }
@ -389,8 +393,9 @@ and bracequote buf depth = parse
bracequote buf depth lexbuf }
| [^'\\' '{' '}']+ { let s = Lexing.lexeme lexbuf in
Buffer.add_string buf s;
| [^'\\' '{' '}'] as c { Buffer.add_char buf c;
if c = '\n'
then newline lexbuf;
bracequote buf depth lexbuf }
@ -402,6 +407,7 @@ and comment depth = parse
then token lexbuf
else comment (depth-1) lexbuf }
| '*' [^'{'] { comment depth lexbuf }
| '/' [^'*'] { comment depth lexbuf }
| [^'/' '*']+ { comment depth lexbuf }
| '\n' { newline lexbuf;
comment depth lexbuf }
| _ { comment depth lexbuf }

View file

@ -0,0 +1,10 @@
// -*- rust -*-
// error-pattern:9:2:E
/* 1
* 2
* 3
*/
fn main() {
%; // parse error on line 9, but is reported on line 6 instead.
}