diff options
Diffstat (limited to 'hclwrite/tokens.go')
| -rw-r--r-- | hclwrite/tokens.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/hclwrite/tokens.go b/hclwrite/tokens.go index d37b1c6..d87f818 100644 --- a/hclwrite/tokens.go +++ b/hclwrite/tokens.go @@ -5,6 +5,7 @@ import ( "io" "github.com/apparentlymart/go-textseg/textseg" + "github.com/hashicorp/hcl2/hcl" "github.com/hashicorp/hcl2/hcl/hclsyntax" ) @@ -22,6 +23,23 @@ type Token struct { SpacesBefore int } +// asHCLSyntax returns the receiver expressed as an incomplete hclsyntax.Token. +// A complete token is not possible since we don't have source location +// information here, and so this method is unexported so we can be sure it will +// only be used for internal purposes where we know the range isn't important. +// +// This is primarily intended to allow us to re-use certain functionality from +// hclsyntax rather than re-implementing it against our own token type here. +func (t *Token) asHCLSyntax() hclsyntax.Token { + return hclsyntax.Token{ + Type: t.Type, + Bytes: t.Bytes, + Range: hcl.Range{ + Filename: "<invalid>", + }, + } +} + // Tokens is a flat list of tokens. type Tokens []*Token |
