MCPcopy
hub / github.com/hashicorp/hcl / TokensForTuple

Function TokensForTuple

hclwrite/generate.go:71–94  ·  view source on GitHub ↗

TokensForTuple returns a sequence of tokens that represents a tuple constructor, with element expressions populated from the given list of tokens. TokensForTuple includes the given elements verbatim into the element positions in the resulting tuple expression, without any validation to ensure that

(elems []Tokens)

Source from the content-addressed store, hash-verified

69// TokensForTuple, TokensForObject, and TokensForFunctionCall to
70// generate other nested compound expressions.
71func TokensForTuple(elems []Tokens) Tokens {
72 var toks Tokens
73 toks = append(toks, &Token{
74 Type: hclsyntax.TokenOBrack,
75 Bytes: []byte{'['},
76 })
77 for index, elem := range elems {
78 if index > 0 {
79 toks = append(toks, &Token{
80 Type: hclsyntax.TokenComma,
81 Bytes: []byte{','},
82 })
83 }
84 toks = append(toks, elem...)
85 }
86
87 toks = append(toks, &Token{
88 Type: hclsyntax.TokenCBrack,
89 Bytes: []byte{']'},
90 })
91
92 format(toks) // fiddle with the SpacesBefore field to get canonical spacing
93 return toks
94}
95
96// TokensForObject returns a sequence of tokens that represents an object
97// constructor, with attribute name/value pairs populated from the given

Callers 2

TestTokensForTupleFunction · 0.85

Calls 1

formatFunction · 0.85

Tested by 2

TestTokensForTupleFunction · 0.68