diff options
| author | Graydon Hoare <[email protected]> | 2010-08-03 16:28:50 -0700 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-08-03 16:28:50 -0700 |
| commit | a1ecdb103d32551ffb5bf552f95c88292b7eac1c (patch) | |
| tree | b9de43929b763d6acf5e4348aabc4843b06a062b /src/boot/fe | |
| parent | Add tests and fix pexp bug. Closes #141. (diff) | |
| download | rust-a1ecdb103d32551ffb5bf552f95c88292b7eac1c.tar.xz rust-a1ecdb103d32551ffb5bf552f95c88292b7eac1c.zip | |
Fix some naughtiness of handling newlines in bracequotes and multi-line comments. Closes #142.
Diffstat (limited to 'src/boot/fe')
| -rw-r--r-- | src/boot/fe/lexer.mll | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/boot/fe/lexer.mll b/src/boot/fe/lexer.mll index bb1d881e..ed548b1e 100644 --- a/src/boot/fe/lexer.mll +++ b/src/boot/fe/lexer.mll @@ -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 } |