From b5021411a84822cb3f1e3aeffad9550dd15bdeb6 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 16 Sep 2018 12:54:24 +0300 Subject: rename all things --- crates/ra_syntax/src/lexer/comments.rs | 57 ++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 crates/ra_syntax/src/lexer/comments.rs (limited to 'crates/ra_syntax/src/lexer/comments.rs') diff --git a/crates/ra_syntax/src/lexer/comments.rs b/crates/ra_syntax/src/lexer/comments.rs new file mode 100644 index 000000000..eb417c2dc --- /dev/null +++ b/crates/ra_syntax/src/lexer/comments.rs @@ -0,0 +1,57 @@ +use lexer::ptr::Ptr; + +use SyntaxKind::{self, *}; + +pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool { + if ptr.at_str("!/") { + ptr.bump(); + ptr.bump(); + bump_until_eol(ptr); + true + } else { + false + } +} + +fn scan_block_comment(ptr: &mut Ptr) -> Option { + if ptr.at('*') { + ptr.bump(); + let mut depth: u32 = 1; + while depth > 0 { + if ptr.at_str("*/") { + depth -= 1; + ptr.bump(); + ptr.bump(); + } else if ptr.at_str("/*") { + 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.at('/') { + bump_until_eol(ptr); + Some(COMMENT) + } else { + scan_block_comment(ptr) + } +} + +fn bump_until_eol(ptr: &mut Ptr) { + loop { + if ptr.at('\n') || ptr.at_str("\r\n") { + return; + } + if ptr.bump().is_none() { + break; + } + } +} -- cgit v1.2.3