TokensForFunctionCall returns a sequence of tokens that represents call to the function with the given name, using the argument tokens to populate the argument expressions. TokensForFunctionCall includes the given argument tokens verbatim into the positions in the resulting call expression, without
(funcName string, args ...Tokens)
| 158 | // manually appending a TokenEllipsis with the bytes "..." to the tokens for |
| 159 | // the final argument. |
| 160 | func TokensForFunctionCall(funcName string, args ...Tokens) Tokens { |
| 161 | var toks Tokens |
| 162 | toks = append(toks, TokensForIdentifier(funcName)...) |
| 163 | toks = append(toks, &Token{ |
| 164 | Type: hclsyntax.TokenOParen, |
| 165 | Bytes: []byte{'('}, |
| 166 | }) |
| 167 | for index, arg := range args { |
| 168 | if index > 0 { |
| 169 | toks = append(toks, &Token{ |
| 170 | Type: hclsyntax.TokenComma, |
| 171 | Bytes: []byte{','}, |
| 172 | }) |
| 173 | } |
| 174 | toks = append(toks, arg...) |
| 175 | } |
| 176 | toks = append(toks, &Token{ |
| 177 | Type: hclsyntax.TokenCParen, |
| 178 | Bytes: []byte{')'}, |
| 179 | }) |
| 180 | |
| 181 | format(toks) // fiddle with the SpacesBefore field to get canonical spacing |
| 182 | return toks |
| 183 | } |
| 184 | |
| 185 | func appendTokensForValue(val cty.Value, toks Tokens) Tokens { |
| 186 | switch { |