e0c5f51bd5
This is a helper for recognizing identifiers that are actually keywords.
19 lines
341 B
Go
19 lines
341 B
Go
package zclsyntax
|
|
|
|
import (
|
|
"bytes"
|
|
)
|
|
|
|
type Keyword []byte
|
|
|
|
var forKeyword = Keyword([]byte{'f', 'o', 'r'})
|
|
var inKeyword = Keyword([]byte{'i', 'n'})
|
|
var ifKeyword = Keyword([]byte{'i', 'f'})
|
|
|
|
func (kw Keyword) TokenMatches(token Token) bool {
|
|
if token.Type != TokenIdent {
|
|
return false
|
|
}
|
|
return bytes.Equal([]byte(kw), token.Bytes)
|
|
}
|