zig fmt: support line comments and doc comments

line comments can go anywhere a list of something is allowed
This commit is contained in:
Andrew Kelley
2018-04-30 00:19:55 -04:00
parent 39befc35a8
commit fd2cd38bdb
4 changed files with 168 additions and 56 deletions

View File

@@ -137,6 +137,7 @@ pub const Token = struct {
IntegerLiteral,
FloatLiteral,
LineComment,
DocComment,
Keyword_align,
Keyword_and,
Keyword_asm,
@@ -257,6 +258,7 @@ pub const Tokenizer = struct {
Asterisk,
AsteriskPercent,
Slash,
LineCommentStart,
LineComment,
Zero,
IntegerLiteral,
@@ -822,8 +824,7 @@ pub const Tokenizer = struct {
State.Slash => switch (c) {
'/' => {
result.id = Token.Id.LineComment;
state = State.LineComment;
state = State.LineCommentStart;
},
'=' => {
result.id = Token.Id.SlashEqual;
@@ -835,6 +836,17 @@ pub const Tokenizer = struct {
break;
},
},
State.LineCommentStart => switch (c) {
'/' => {
result.id = Token.Id.DocComment;
state = State.LineComment;
},
'\n' => {
result.id = Token.Id.LineComment;
break;
},
else => self.checkLiteralCharacter(),
},
State.LineComment => switch (c) {
'\n' => break,
else => self.checkLiteralCharacter(),
@@ -920,6 +932,7 @@ pub const Tokenizer = struct {
result.id = id;
}
},
State.LineCommentStart,
State.LineComment => {
result.id = Token.Id.Eof;
},