aboutsummaryrefslogtreecommitdiff
path: root/src/lexer/comments.rs
blob: 79782cc5b85c7bbe896a0488859fc915bd049219 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use lexer::ptr::Ptr;

use {SyntaxKind};
use syntax_kinds::*;

pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool {
    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<SyntaxKind> {
    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;
        }
    }
}