From: Christopher Durham Date: Sun, 28 Jan 2018 10:08:25 +0000 (-0500) Subject: Block Comments X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=f4f79038d103c77e36b9b4eb74f532a7f9598234;p=rust.git Block Comments closes #7 --- diff --git a/src/lexer/comments.rs b/src/lexer/comments.rs index b70f2c6c677..d388561bff2 100644 --- a/src/lexer/comments.rs +++ b/src/lexer/comments.rs @@ -14,12 +14,35 @@ pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool { } } +pub(crate) fn scan_block_comment(ptr: &mut Ptr) -> Option { + if ptr.next_is('*') { + ptr.bump(); + let mut depth: u32 = 1; + while depth > 0 { + if ptr.next_is('*') && ptr.nnext_is('/') { + depth -= 1; + ptr.bump(); + ptr.bump(); + } else if ptr.next_is('/') && ptr.nnext_is('*') { + depth += 1; + ptr.bump(); + ptr.bump(); + } else if ptr.bump().is_none() { + break; + } + } + Some(COMMENT) + } else { + None + } +} + pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option { if ptr.next_is('/') { bump_until_eol(ptr); Some(COMMENT) } else { - None + scan_block_comment(ptr) } } diff --git a/tests/data/lexer/00012_block_comment.rs b/tests/data/lexer/00012_block_comment.rs new file mode 100644 index 00000000000..708aac197f2 --- /dev/null +++ b/tests/data/lexer/00012_block_comment.rs @@ -0,0 +1,4 @@ +/* */ +/**/ +/* /* */ */ +/* diff --git a/tests/data/lexer/00012_block_comment.txt b/tests/data/lexer/00012_block_comment.txt new file mode 100644 index 00000000000..9958b25187d --- /dev/null +++ b/tests/data/lexer/00012_block_comment.txt @@ -0,0 +1,7 @@ +COMMENT 5 "/* */" +WHITESPACE 1 "\n" +COMMENT 4 "/**/" +WHITESPACE 1 "\n" +COMMENT 11 "/* /* */ */" +WHITESPACE 1 "\n" +COMMENT 3 "/*\n"