zclsyntax: "Keyword" type

This is a helper for recognizing identifiers that are actually keywords.
This commit is contained in:
Martin Atkins 2017-06-13 08:43:03 -07:00
parent 54fcc09ed4
commit e0c5f51bd5

18
zcl/zclsyntax/keywords.go Normal file
View File

@ -0,0 +1,18 @@
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)
}