diff options
author | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-01-28 10:52:49 +0000 |
---|---|---|
committer | bors[bot] <bors[bot]@users.noreply.github.com> | 2018-01-28 10:52:49 +0000 |
commit | 7a6fa6504c5458dcc32e24327ba0ec597222fc63 (patch) | |
tree | 429094453c94f79adf9ed6ad0f69771684d0c7a8 | |
parent | 37ee4c4c2afc1df536f50a776ac16dab69a67058 (diff) | |
parent | 5982e6d73b600e00d4eb72800e30c3c0700eb75b (diff) |
Merge #24
24: Block Comments r=matklad a=CAD97
closes #7
-rw-r--r-- | src/lexer/comments.rs | 25 | ||||
-rw-r--r-- | tests/data/lexer/00012_block_comment.rs | 4 | ||||
-rw-r--r-- | tests/data/lexer/00012_block_comment.txt | 7 |
3 files changed, 35 insertions, 1 deletions
diff --git a/src/lexer/comments.rs b/src/lexer/comments.rs index b70f2c6c6..d1e958817 100644 --- a/src/lexer/comments.rs +++ b/src/lexer/comments.rs | |||
@@ -14,12 +14,35 @@ pub(crate) fn scan_shebang(ptr: &mut Ptr) -> bool { | |||
14 | } | 14 | } |
15 | } | 15 | } |
16 | 16 | ||
17 | fn scan_block_comment(ptr: &mut Ptr) -> Option<SyntaxKind> { | ||
18 | if ptr.next_is('*') { | ||
19 | ptr.bump(); | ||
20 | let mut depth: u32 = 1; | ||
21 | while depth > 0 { | ||
22 | if ptr.next_is('*') && ptr.nnext_is('/') { | ||
23 | depth -= 1; | ||
24 | ptr.bump(); | ||
25 | ptr.bump(); | ||
26 | } else if ptr.next_is('/') && ptr.nnext_is('*') { | ||
27 | depth += 1; | ||
28 | ptr.bump(); | ||
29 | ptr.bump(); | ||
30 | } else if ptr.bump().is_none() { | ||
31 | break; | ||
32 | } | ||
33 | } | ||
34 | Some(COMMENT) | ||
35 | } else { | ||
36 | None | ||
37 | } | ||
38 | } | ||
39 | |||
17 | pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option<SyntaxKind> { | 40 | pub(crate) fn scan_comment(ptr: &mut Ptr) -> Option<SyntaxKind> { |
18 | if ptr.next_is('/') { | 41 | if ptr.next_is('/') { |
19 | bump_until_eol(ptr); | 42 | bump_until_eol(ptr); |
20 | Some(COMMENT) | 43 | Some(COMMENT) |
21 | } else { | 44 | } else { |
22 | None | 45 | scan_block_comment(ptr) |
23 | } | 46 | } |
24 | } | 47 | } |
25 | 48 | ||
diff --git a/tests/data/lexer/00012_block_comment.rs b/tests/data/lexer/00012_block_comment.rs new file mode 100644 index 000000000..708aac197 --- /dev/null +++ b/tests/data/lexer/00012_block_comment.rs | |||
@@ -0,0 +1,4 @@ | |||
1 | /* */ | ||
2 | /**/ | ||
3 | /* /* */ */ | ||
4 | /* | ||
diff --git a/tests/data/lexer/00012_block_comment.txt b/tests/data/lexer/00012_block_comment.txt new file mode 100644 index 000000000..9958b2518 --- /dev/null +++ b/tests/data/lexer/00012_block_comment.txt | |||
@@ -0,0 +1,7 @@ | |||
1 | COMMENT 5 "/* */" | ||
2 | WHITESPACE 1 "\n" | ||
3 | COMMENT 4 "/**/" | ||
4 | WHITESPACE 1 "\n" | ||
5 | COMMENT 11 "/* /* */ */" | ||
6 | WHITESPACE 1 "\n" | ||
7 | COMMENT 3 "/*\n" | ||