Skip to content

Commit a1ecdb1

Browse files
committed
Fix some naughtiness of handling newlines in bracequotes and multi-line comments. Closes rust-lang#142.
1 parent 1fc4e9f commit a1ecdb1

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

src/boot/fe/lexer.mll

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@
2222
Lexing.pos_bol = p.Lexing.pos_cnum }
2323
;;
2424

25+
let newline lexbuf =
26+
lexbuf.Lexing.lex_curr_p
27+
<- (bump_line lexbuf.Lexing.lex_curr_p)
28+
;;
29+
2530
let mach_suf_table = Hashtbl.create 0
2631
;;
2732
let _ =
@@ -155,8 +160,7 @@ let id = ['a'-'z' 'A'-'Z' '_']['a'-'z' 'A'-'Z' '0'-'9' '_']*
155160

156161
rule token = parse
157162
ws+ { token lexbuf }
158-
| '\n' { lexbuf.Lexing.lex_curr_p
159-
<- (bump_line lexbuf.Lexing.lex_curr_p);
163+
| '\n' { newline lexbuf;
160164
token lexbuf }
161165
| "//" [^'\n']* { token lexbuf }
162166
| "/*" { comment 1 lexbuf }
@@ -389,8 +393,9 @@ and bracequote buf depth = parse
389393
bracequote buf depth lexbuf }
390394

391395

392-
| [^'\\' '{' '}']+ { let s = Lexing.lexeme lexbuf in
393-
Buffer.add_string buf s;
396+
| [^'\\' '{' '}'] as c { Buffer.add_char buf c;
397+
if c = '\n'
398+
then newline lexbuf;
394399
bracequote buf depth lexbuf }
395400

396401

@@ -402,6 +407,7 @@ and comment depth = parse
402407
then token lexbuf
403408
else comment (depth-1) lexbuf }
404409

405-
| '*' [^'{'] { comment depth lexbuf }
406-
| '/' [^'*'] { comment depth lexbuf }
407-
| [^'/' '*']+ { comment depth lexbuf }
410+
| '\n' { newline lexbuf;
411+
comment depth lexbuf }
412+
413+
| _ { comment depth lexbuf }
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// -*- rust -*-
2+
// error-pattern:9:2:E
3+
4+
/* 1
5+
* 2
6+
* 3
7+
*/
8+
fn main() {
9+
%; // parse error on line 9, but is reported on line 6 instead.
10+
}

0 commit comments

Comments
 (0)