7 hcltoken "github.com/hashicorp/hcl/hcl/token"
10 // Token defines a single HCL token which can be obtained via the Scanner
17 // Type is the set of lexical tokens of the HCL (HashiCorp Configuration Language)
48 var tokens = [...]string{
69 // String returns the string corresponding to the token tok.
70 func (t Type) String() string {
72 if 0 <= t && t < Type(len(tokens)) {
76 s = "token(" + strconv.Itoa(int(t)) + ")"
81 // IsIdentifier returns true for tokens corresponding to identifiers and basic
82 // type literals; it returns false otherwise.
83 func (t Type) IsIdentifier() bool { return identifier_beg < t && t < identifier_end }
85 // IsLiteral returns true for tokens corresponding to basic type literals; it
86 // returns false otherwise.
87 func (t Type) IsLiteral() bool { return literal_beg < t && t < literal_end }
89 // IsOperator returns true for tokens corresponding to operators and
90 // delimiters; it returns false otherwise.
91 func (t Type) IsOperator() bool { return operator_beg < t && t < operator_end }
93 // String returns the token's literal text. Note that this is only
94 // applicable for certain token types, such as token.IDENT,
95 // token.STRING, etc..
96 func (t Token) String() string {
97 return fmt.Sprintf("%s %s %s", t.Pos.String(), t.Type.String(), t.Text)
100 // HCLToken converts this token to an HCL token.
102 // The token type must be a literal type or this will panic.
103 func (t Token) HCLToken() hcltoken.Token {
106 return hcltoken.Token{Type: hcltoken.BOOL, Text: t.Text}
108 return hcltoken.Token{Type: hcltoken.FLOAT, Text: t.Text}
110 return hcltoken.Token{Type: hcltoken.STRING, Text: ""}
112 return hcltoken.Token{Type: hcltoken.NUMBER, Text: t.Text}
114 return hcltoken.Token{Type: hcltoken.STRING, Text: t.Text, JSON: true}
116 panic(fmt.Sprintf("unimplemented HCLToken for type: %s", t.Type))