Simplified tokenizer
This commit is contained in:
parent
dd6ebd9cd4
commit
25f6928f40
9 changed files with 300 additions and 261 deletions
28
src/token/quote.go
Normal file
28
src/token/quote.go
Normal 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
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue