diff options
| author | Matt Brubeck <[email protected]> | 2010-07-08 17:01:25 +0800 |
|---|---|---|
| committer | Graydon Hoare <[email protected]> | 2010-07-08 22:43:15 +0800 |
| commit | 244ea680820c205461ad5af979c0a722372e6dc6 (patch) | |
| tree | 45d4da70ea8f68b84105bfdac48f8556519fb14e | |
| parent | Some more typestate tests. (diff) | |
| download | rust-244ea680820c205461ad5af979c0a722372e6dc6.tar.xz rust-244ea680820c205461ad5af979c0a722372e6dc6.zip | |
Issue 66: Multi-line comments
| -rw-r--r-- | doc/rust.texi | 10 | ||||
| -rw-r--r-- | src/boot/fe/lexer.mll | 15 | ||||
| -rw-r--r-- | src/test/compile-fail/unbalanced-comment.rs | 9 | ||||
| -rw-r--r-- | src/test/run-pass/multiline-comment.rs | 8 |
4 files changed, 39 insertions, 3 deletions
diff --git a/doc/rust.texi b/doc/rust.texi index b8a59a2b..3e6a93b2 100644 --- a/doc/rust.texi +++ b/doc/rust.texi @@ -616,11 +616,17 @@ otherwise a free-form language. @dfn{Whitespace} is any of the following Unicode characters: U+0020 (space), U+0009 (tab, @code{'\t'}), U+000A (LF, @code{'\n'}), U+000D (CR, @code{'\r'}). -@dfn{Comments} are any sequence of Unicode characters beginning with U+002F -U+002F (@code{"//"}) and extending to the next U+000A character, +@dfn{Comments} are @emph{single-line comments} or @emph{multi-line comments}. + +A @dfn{single-line comment} is any sequence of Unicode characters beginning +with U+002F U+002F (@code{"//"}) and extending to the next U+000A character, @emph{excluding} cases in which such a sequence occurs within a string literal token or a syntactic extension token. +A @dfn{multi-line comments} is any sequence of Unicode characters beginning +with U+002F U+002A (@code{"/*"}) and ending with U+002A U+002F (@code{"*/"}), +@emph{excluding} cases in which such a sequence occurs within a string literal +token or a syntactic extension token. Multi-line comments may be nested. @node Ref.Lex.Ident @subsection Ref.Lex.Ident diff --git a/src/boot/fe/lexer.mll b/src/boot/fe/lexer.mll index 6430821d..090da25f 100644 --- a/src/boot/fe/lexer.mll +++ b/src/boot/fe/lexer.mll @@ -139,7 +139,7 @@ rule token = parse <- (bump_line lexbuf.Lexing.lex_curr_p); token lexbuf } | "//" [^'\n']* { token lexbuf } - +| "/*" { comment 1 lexbuf } | '+' { PLUS } | '-' { MINUS } | '*' { STAR } @@ -362,3 +362,16 @@ and bracequote buf depth = parse | [^'\\' '{' '}']+ { let s = Lexing.lexeme lexbuf in Buffer.add_string buf s; bracequote buf depth lexbuf } + + +and comment depth = parse + + '/' '*' { comment (depth+1) lexbuf } + +| '*' '/' { if depth = 1 + then token lexbuf + else comment (depth-1) lexbuf } + +| '*' [^'{'] { comment depth lexbuf } +| '/' [^'*'] { comment depth lexbuf } +| [^'/' '*']+ { comment depth lexbuf } diff --git a/src/test/compile-fail/unbalanced-comment.rs b/src/test/compile-fail/unbalanced-comment.rs new file mode 100644 index 00000000..c22df4ec --- /dev/null +++ b/src/test/compile-fail/unbalanced-comment.rs @@ -0,0 +1,9 @@ +// -*- rust -*- + +/* + * This is an un-balanced /* multi-line comment. + */ + +fn main() { + log "hello, world."; +} diff --git a/src/test/run-pass/multiline-comment.rs b/src/test/run-pass/multiline-comment.rs new file mode 100644 index 00000000..3b846433 --- /dev/null +++ b/src/test/run-pass/multiline-comment.rs @@ -0,0 +1,8 @@ +// -*- rust -*- + +/* + * This is a /* depth-balanced */ multi-line comment. + */ + +fn main() { +} |