std.zig.tokenizer: 3 slashes is doc comment, 4 is line comment

This commit is contained in:
Andrew Kelley 2018-04-30 00:56:59 -04:00
parent 0bf7ebcfea
commit 54987c3d8f

View File

@ -260,6 +260,7 @@ pub const Tokenizer = struct {
Slash,
LineCommentStart,
LineComment,
DocCommentStart,
DocComment,
Zero,
IntegerLiteral,
@ -840,8 +841,7 @@ pub const Tokenizer = struct {
},
State.LineCommentStart => switch (c) {
'/' => {
result.id = Token.Id.DocComment;
state = State.DocComment;
state = State.DocCommentStart;
},
'\n' => break,
else => {
@ -849,6 +849,20 @@ pub const Tokenizer = struct {
self.checkLiteralCharacter();
},
},
State.DocCommentStart => switch (c) {
'/' => {
state = State.LineComment;
},
'\n' => {
result.id = Token.Id.DocComment;
break;
},
else => {
state = State.DocComment;
result.id = Token.Id.DocComment;
self.checkLiteralCharacter();
},
},
State.LineComment, State.DocComment => switch (c) {
'\n' => break,
else => self.checkLiteralCharacter(),
@ -938,7 +952,7 @@ pub const Tokenizer = struct {
State.LineComment => {
result.id = Token.Id.LineComment;
},
State.DocComment => {
State.DocComment, State.DocCommentStart => {
result.id = Token.Id.DocComment;
},
@ -1213,6 +1227,7 @@ test "tokenizer - line comment and doc comment" {
testTokenize("// /", []Token.Id{Token.Id.LineComment});
testTokenize("/// a", []Token.Id{Token.Id.DocComment});
testTokenize("///", []Token.Id{Token.Id.DocComment});
testTokenize("////", []Token.Id{Token.Id.LineComment});
}
test "tokenizer - line comment followed by identifier" {