hcl: start to implement our own lexer and parser

This commit is contained in:
Fatih Arslan 2015-10-03 14:32:19 +03:00
parent e5a8a1fa62
commit 7e929f0990
2 changed files with 46 additions and 0 deletions

1
parser/parser.go Normal file
View File

@ -0,0 +1 @@
package parser

45
parser/token.go Normal file
View File

@ -0,0 +1,45 @@
package parser
// Token is the set of lexical tokens of the HCL (HashiCorp Configuration Language)
type Token int
const (
// Special tokens
ILLEGAL Token = iota
EOF
COMMENT
NEWLINE
literal_beg
IDENT // literals
NUMBER // 12345
FLOAT // 123.45
BOOL // true,false
STRING // "abc"
literal_end
operator_beg
LBRACK // [
LBRACE // {
COMMA // ,
PERIOD // .
RBRACK // ]
RBRACE // }
ASSIGN // =
ADD // +
SUB // -
EPLUS // e
EMINUS // e-
operator_end
)
// IsLiteral returns true for tokens corresponding to identifiers and basic
// type literals; it returns false otherwise.
func (t Token) IsLiteral() bool { return literal_beg < t && t < literal_end }
// IsOperator returns true for tokens corresponding to operators and
// delimiters; it returns false otherwise.
func (t Token) IsOperator() bool { return operator_beg < t && t < operator_end }