From f4f79038d103c77e36b9b4eb74f532a7f9598234 Mon Sep 17 00:00:00 2001 From: Christopher Durham Date: Sun, 28 Jan 2018 05:08:25 -0500 Subject: Block Comments closes #7 --- src/lexer/comments.rs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/lexer/comments.rs b/src/lexer/comments.rs index b70f2c6c6..d388561bf 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) } } -- cgit v1.2.3