From 98a58bf806ffda1b4d3352ed0f3e494fa25c8c74 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Sun, 31 Dec 2017 16:56:33 +0300 Subject: Lexer: basic comments --- src/lexer/comments.rs | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/lexer/comments.rs b/src/lexer/comments.rs index c61c85824..79782cc5b 100644 --- a/src/lexer/comments.rs +++ b/src/lexer/comments.rs @@ -1,11 +1,36 @@ use lexer::ptr::Ptr; use {SyntaxKind}; +use syntax_kinds::*; pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool { - false + if ptr.next_is('!') && ptr.nnext_is('/') { + ptr.bump(); + ptr.bump(); + bump_until_eol(ptr); + true + } else { + false + } } pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option { - None + if ptr.next_is('/') { + bump_until_eol(ptr); + Some(COMMENT) + } else { + None + } +} + + +fn bump_until_eol(ptr: &mut Ptr) { + loop { + if ptr.next_is('\n') || ptr.next_is('\r') && ptr.nnext_is('\n') { + return; + } + if ptr.bump().is_none() { + break; + } + } } \ No newline at end of file -- cgit v1.2.3