diff options
-rw-r--r-- | src/lexer/comments.rs | 29 | ||||
-rw-r--r-- | tests/data/lexer/0010_comments.rs | 3 | ||||
-rw-r--r-- | tests/data/lexer/0010_comments.txt | 6 | ||||
-rw-r--r-- | validation.md | 1 |
4 files changed, 37 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 |
diff --git a/tests/data/lexer/0010_comments.rs b/tests/data/lexer/0010_comments.rs new file mode 100644 index 000000000..71bdd1f9c --- /dev/null +++ b/tests/data/lexer/0010_comments.rs | |||
@@ -0,0 +1,3 @@ | |||
1 | #!/usr/bin/env bash | ||
2 | // hello | ||
3 | //! World | ||
diff --git a/tests/data/lexer/0010_comments.txt b/tests/data/lexer/0010_comments.txt new file mode 100644 index 000000000..3c997de3f --- /dev/null +++ b/tests/data/lexer/0010_comments.txt | |||
@@ -0,0 +1,6 @@ | |||
1 | SHEBANG 19 "#!/usr/bin/env bash" | ||
2 | WHITESPACE 1 "\n" | ||
3 | COMMENT 8 "// hello" | ||
4 | WHITESPACE 1 "\n" | ||
5 | COMMENT 9 "//! World" | ||
6 | WHITESPACE 1 "\n" | ||
diff --git a/validation.md b/validation.md index 39b5f85fa..e72de1ea2 100644 --- a/validation.md +++ b/validation.md | |||
@@ -6,3 +6,4 @@ Fixmes: | |||
6 | base, and are in range | 6 | base, and are in range |
7 | * Validation for unclosed char literal | 7 | * Validation for unclosed char literal |
8 | * Strings are completely wrong: more tests and comparison with libsyntax. | 8 | * Strings are completely wrong: more tests and comparison with libsyntax. |
9 | * Comment lexing is completely wrong | ||