mirror of
https://github.com/letic/terraform-provider-google.git
synced 2024-09-07 09:36:44 +00:00
![Paddy](/assets/img/avatar_default.png)
Switch to using Go modules. This migrates our vendor.json to use Go 1.11's modules system, and replaces the vendor folder with the output of go mod vendor. The vendored code should remain basically the same; I believe some tree shaking of packages and support scripts/licenses/READMEs/etc. happened. This also fixes Travis and our Makefile to no longer use govendor.
122 lines
2.1 KiB
Go
122 lines
2.1 KiB
Go
package hclwrite
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
)
|
|
|
|
type File struct {
|
|
inTree
|
|
|
|
srcBytes []byte
|
|
body *node
|
|
}
|
|
|
|
// NewEmptyFile constructs a new file with no content, ready to be mutated
|
|
// by other calls that append to its body.
|
|
func NewEmptyFile() *File {
|
|
f := &File{
|
|
inTree: newInTree(),
|
|
}
|
|
body := newBody()
|
|
f.body = f.children.Append(body)
|
|
return f
|
|
}
|
|
|
|
// Body returns the root body of the file, which contains the top-level
|
|
// attributes and blocks.
|
|
func (f *File) Body() *Body {
|
|
return f.body.content.(*Body)
|
|
}
|
|
|
|
// WriteTo writes the tokens underlying the receiving file to the given writer.
|
|
//
|
|
// The tokens first have a simple formatting pass applied that adjusts only
|
|
// the spaces between them.
|
|
func (f *File) WriteTo(wr io.Writer) (int64, error) {
|
|
tokens := f.inTree.children.BuildTokens(nil)
|
|
format(tokens)
|
|
return tokens.WriteTo(wr)
|
|
}
|
|
|
|
// Bytes returns a buffer containing the source code resulting from the
|
|
// tokens underlying the receiving file. If any updates have been made via
|
|
// the AST API, these will be reflected in the result.
|
|
func (f *File) Bytes() []byte {
|
|
buf := &bytes.Buffer{}
|
|
f.WriteTo(buf)
|
|
return buf.Bytes()
|
|
}
|
|
|
|
type comments struct {
|
|
leafNode
|
|
|
|
parent *node
|
|
tokens Tokens
|
|
}
|
|
|
|
func newComments(tokens Tokens) *comments {
|
|
return &comments{
|
|
tokens: tokens,
|
|
}
|
|
}
|
|
|
|
func (c *comments) BuildTokens(to Tokens) Tokens {
|
|
return c.tokens.BuildTokens(to)
|
|
}
|
|
|
|
type identifier struct {
|
|
leafNode
|
|
|
|
parent *node
|
|
token *Token
|
|
}
|
|
|
|
func newIdentifier(token *Token) *identifier {
|
|
return &identifier{
|
|
token: token,
|
|
}
|
|
}
|
|
|
|
func (i *identifier) BuildTokens(to Tokens) Tokens {
|
|
return append(to, i.token)
|
|
}
|
|
|
|
func (i *identifier) hasName(name string) bool {
|
|
return name == string(i.token.Bytes)
|
|
}
|
|
|
|
type number struct {
|
|
leafNode
|
|
|
|
parent *node
|
|
token *Token
|
|
}
|
|
|
|
func newNumber(token *Token) *number {
|
|
return &number{
|
|
token: token,
|
|
}
|
|
}
|
|
|
|
func (n *number) BuildTokens(to Tokens) Tokens {
|
|
return append(to, n.token)
|
|
}
|
|
|
|
type quoted struct {
|
|
leafNode
|
|
|
|
parent *node
|
|
tokens Tokens
|
|
}
|
|
|
|
func newQuoted(tokens Tokens) *quoted {
|
|
return "ed{
|
|
tokens: tokens,
|
|
}
|
|
}
|
|
|
|
func (q *quoted) BuildTokens(to Tokens) Tokens {
|
|
return q.tokens.BuildTokens(to)
|
|
}
|