From e0c5f51bd50b46fafd726166cb6d9e4e21d6517f Mon Sep 17 00:00:00 2001 From: Martin Atkins Date: Tue, 13 Jun 2017 08:43:03 -0700 Subject: [PATCH] zclsyntax: "Keyword" type This is a helper for recognizing identifiers that are actually keywords. --- zcl/zclsyntax/keywords.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 zcl/zclsyntax/keywords.go diff --git a/zcl/zclsyntax/keywords.go b/zcl/zclsyntax/keywords.go new file mode 100644 index 0000000..83e1109 --- /dev/null +++ b/zcl/zclsyntax/keywords.go @@ -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) +}