diff options
author | Aleksey Kladov <[email protected]> | 2017-12-31 13:56:33 +0000 |
---|---|---|
committer | Aleksey Kladov <[email protected]> | 2017-12-31 13:56:33 +0000 |
commit | 98a58bf806ffda1b4d3352ed0f3e494fa25c8c74 (patch) | |
tree | 7f309dee323e04dde12683bfa118d16c55249ea8 /src | |
parent | cb6f07618440859a26fd6adea63bd030da375952 (diff) |
Lexer: basic comments
Diffstat (limited to 'src')
-rw-r--r-- | src/lexer/comments.rs | 29 |
1 files changed, 27 insertions, 2 deletions
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 @@ | |||
1 | use lexer::ptr::Ptr; | 1 | use lexer::ptr::Ptr; |
2 | 2 | ||
3 | use {SyntaxKind}; | 3 | use {SyntaxKind}; |
4 | use syntax_kinds::*; | ||
4 | 5 | ||
5 | pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool { | 6 | pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool { |
6 | false | 7 | if ptr.next_is('!') && ptr.nnext_is('/') { |
8 | ptr.bump(); | ||
9 | ptr.bump(); | ||
10 | bump_until_eol(ptr); | ||
11 | true | ||
12 | } else { | ||
13 | false | ||
14 | } | ||
7 | } | 15 | } |
8 | 16 | ||
9 | pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option<SyntaxKind> { | 17 | pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option<SyntaxKind> { |
10 | None | 18 | if ptr.next_is('/') { |
19 | bump_until_eol(ptr); | ||
20 | Some(COMMENT) | ||
21 | } else { | ||
22 | None | ||
23 | } | ||
24 | } | ||
25 | |||
26 | |||
27 | fn bump_until_eol(ptr: &mut Ptr) { | ||
28 | loop { | ||
29 | if ptr.next_is('\n') || ptr.next_is('\r') && ptr.nnext_is('\n') { | ||
30 | return; | ||
31 | } | ||
32 | if ptr.bump().is_none() { | ||
33 | break; | ||
34 | } | ||
35 | } | ||
11 | } \ No newline at end of file | 36 | } \ No newline at end of file |