hcl/zcl/zclsyntax/keywords.go
Martin Atkins e0c5f51bd5 zclsyntax: "Keyword" type
This is a helper for recognizing identifiers that are actually keywords.
2017-06-13 08:43:03 -07:00

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)
}