Skip to content

Commit

Permalink
add single line comments
Browse files Browse the repository at this point in the history
This fixes #7

Signed-off-by: Flipez <code@brauser.io>
  • Loading branch information
Flipez committed Sep 29, 2021
1 parent ef25787 commit f52fce8
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion lexer/lexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ func (l *Lexer) NextToken() token.Token {
tok = newToken(token.BANG, l.ch)
}
case '/':
tok = newToken(token.SLASH, l.ch)
if l.peekChar() == '/' {
l.skipComment()
tok = l.NextToken()
} else {
tok = newToken(token.SLASH, l.ch)
}
case '*':
tok = newToken(token.ASTERISK, l.ch)
case '<':
Expand Down Expand Up @@ -146,6 +151,13 @@ func (l *Lexer) skipWhitespace() {
}
}

func (l *Lexer) skipComment() {
for l.ch != '\n' && l.ch != 0 {
l.readChar()
}
l.skipWhitespace()
}

func isLetter(ch byte) bool {
return 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z' || ch == '_'
}
Expand Down

0 comments on commit f52fce8

Please sign in to comment.