From 244ea680820c205461ad5af979c0a722372e6dc6 Mon Sep 17 00:00:00 2001 From: Matt Brubeck Date: Thu, 8 Jul 2010 17:01:25 +0800 Subject: Issue 66: Multi-line comments --- src/boot/fe/lexer.mll | 15 ++++++++++++++- src/test/compile-fail/unbalanced-comment.rs | 9 +++++++++ src/test/run-pass/multiline-comment.rs | 8 ++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/test/compile-fail/unbalanced-comment.rs create mode 100644 src/test/run-pass/multiline-comment.rs (limited to 'src') 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() { +} -- cgit v1.2.3