Simplified tokenizer

This commit is contained in:
Eduard Urbach 2025-02-02 11:11:59 +01:00
parent dd6ebd9cd4
commit 25f6928f40
Signed by: eduard
GPG key ID: 49226B848C78F6C8
9 changed files with 300 additions and 261 deletions

28
src/token/quote.go Normal file
View file

@ -0,0 +1,28 @@
package token
// quote handles all tokens starting with a single or double quote.
func quote(tokens List, buffer []byte, i Position) (List, Position) {
limiter := buffer[i]
start := i
end := Position(len(buffer))
i++
for i < Position(len(buffer)) {
if buffer[i] == limiter && (buffer[i-1] != '\\' || buffer[i-2] == '\\') {
end = i + 1
i++
break
}
i++
}
kind := String
if limiter == '\'' {
kind = Rune
}
tokens = append(tokens, Token{Kind: kind, Position: start, Length: Length(end - start)})
return tokens, i
}