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

35
src/token/zero.go Normal file
View file

@ -0,0 +1,35 @@
package token
// zero handles all tokens starting with a '0'.
func zero(tokens List, buffer []byte, i Position) (List, Position) {
position := i
i++
if i >= Position(len(buffer)) {
tokens = append(tokens, Token{Kind: Number, Position: position, Length: 1})
return tokens, i
}
filter := isDigit
switch buffer[i] {
case 'x':
i++
filter = isHexDigit
case 'b':
i++
filter = isBinaryDigit
case 'o':
i++
filter = isOctalDigit
}
for i < Position(len(buffer)) && filter(buffer[i]) {
i++
}
tokens = append(tokens, Token{Kind: Number, Position: position, Length: Length(i - position)})
return tokens, i
}