This commit is contained in:
Chuck Smith
2024-01-20 13:20:13 -05:00
parent 10821fc88a
commit 13c9062fed
9 changed files with 140 additions and 23 deletions

View File

@@ -91,6 +91,9 @@ func (l *Lexer) NextToken() token.Token {
case 0:
tok.Literal = ""
tok.Type = token.EOF
case '"':
tok.Type = token.STRING
tok.Literal = l.readString()
default:
if isLetter(l.ch) {
tok.Literal = l.readIdentifier()
@@ -145,3 +148,14 @@ func (l *Lexer) skipWhitespace() {
l.readChar()
}
}
func (l *Lexer) readString() string {
position := l.position + 1
for {
l.readChar()
if l.ch == '"' || l.ch == 0 {
break
}
}
return l.input[position:l.position]
}