diff --git a/parser/parser.go b/parser/parser.go new file mode 100644 index 0000000..0bfe2c2 --- /dev/null +++ b/parser/parser.go @@ -0,0 +1 @@ +package parser diff --git a/parser/token.go b/parser/token.go new file mode 100644 index 0000000..5b969eb --- /dev/null +++ b/parser/token.go @@ -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 }