zclsyntax: "Keyword" type
This is a helper for recognizing identifiers that are actually keywords.
This commit is contained in:
parent
54fcc09ed4
commit
e0c5f51bd5
18
zcl/zclsyntax/keywords.go
Normal file
18
zcl/zclsyntax/keywords.go
Normal 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user