Fix some naughtiness of handling newlines in bracequotes and multi-line comments. Closes #142.
This commit is contained in:
@@ -22,6 +22,11 @@
|
|||||||
Lexing.pos_bol = p.Lexing.pos_cnum }
|
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 mach_suf_table = Hashtbl.create 0
|
||||||
;;
|
;;
|
||||||
let _ =
|
let _ =
|
||||||
@@ -155,8 +160,7 @@ let id = ['a'-'z' 'A'-'Z' '_']['a'-'z' 'A'-'Z' '0'-'9' '_']*
|
|||||||
|
|
||||||
rule token = parse
|
rule token = parse
|
||||||
ws+ { token lexbuf }
|
ws+ { token lexbuf }
|
||||||
| '\n' { lexbuf.Lexing.lex_curr_p
|
| '\n' { newline lexbuf;
|
||||||
<- (bump_line lexbuf.Lexing.lex_curr_p);
|
|
||||||
token lexbuf }
|
token lexbuf }
|
||||||
| "//" [^'\n']* { token lexbuf }
|
| "//" [^'\n']* { token lexbuf }
|
||||||
| "/*" { comment 1 lexbuf }
|
| "/*" { comment 1 lexbuf }
|
||||||
@@ -389,8 +393,9 @@ and bracequote buf depth = parse
|
|||||||
bracequote buf depth lexbuf }
|
bracequote buf depth lexbuf }
|
||||||
|
|
||||||
|
|
||||||
| [^'\\' '{' '}']+ { let s = Lexing.lexeme lexbuf in
|
| [^'\\' '{' '}'] as c { Buffer.add_char buf c;
|
||||||
Buffer.add_string buf s;
|
if c = '\n'
|
||||||
|
then newline lexbuf;
|
||||||
bracequote buf depth lexbuf }
|
bracequote buf depth lexbuf }
|
||||||
|
|
||||||
|
|
||||||
@@ -402,6 +407,7 @@ and comment depth = parse
|
|||||||
then token lexbuf
|
then token lexbuf
|
||||||
else comment (depth-1) lexbuf }
|
else comment (depth-1) lexbuf }
|
||||||
|
|
||||||
| '*' [^'{'] { comment depth lexbuf }
|
| '\n' { newline lexbuf;
|
||||||
| '/' [^'*'] { comment depth lexbuf }
|
comment depth lexbuf }
|
||||||
| [^'/' '*']+ { comment depth lexbuf }
|
|
||||||
|
| _ { comment depth lexbuf }
|
||||||
|
|||||||
10
src/test/compile-fail/multiline-comment-line-tracking.rs
Normal file
10
src/test/compile-fail/multiline-comment-line-tracking.rs
Normal 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.
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user