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

Function parseAttribute

hclwrite/parser.go:241–290  ·  view source on GitHub ↗
(nativeAttr *hclsyntax.Attribute, from, leadComments, lineComments, newline inputTokens)

Source from the content-addressed store, hash-verified

239}
240
241func parseAttribute(nativeAttr *hclsyntax.Attribute, from, leadComments, lineComments, newline inputTokens) *node {
242 attr := &Attribute{
243 inTree: newInTree(),
244 }
245 children := attr.children
246
247 {
248 cn := newNode(newComments(leadComments.Tokens()))
249 attr.leadComments = cn
250 children.AppendNode(cn)
251 }
252
253 before, nameTokens, from := from.Partition(nativeAttr.NameRange)
254 {
255 children.AppendUnstructuredTokens(before.Tokens())
256 if nameTokens.Len() != 1 {
257 // Should never happen with valid input
258 panic("attribute name is not exactly one token")
259 }
260 token := nameTokens.Tokens()[0]
261 in := newNode(newIdentifier(token))
262 attr.name = in
263 children.AppendNode(in)
264 }
265
266 before, equalsTokens, from := from.Partition(nativeAttr.EqualsRange)
267 children.AppendUnstructuredTokens(before.Tokens())
268 children.AppendUnstructuredTokens(equalsTokens.Tokens())
269
270 before, exprTokens, from := from.Partition(nativeAttr.Expr.Range())
271 {
272 children.AppendUnstructuredTokens(before.Tokens())
273 exprNode := parseExpression(nativeAttr.Expr, exprTokens)
274 attr.expr = exprNode
275 children.AppendNode(exprNode)
276 }
277
278 {
279 cn := newNode(newComments(lineComments.Tokens()))
280 attr.lineComments = cn
281 children.AppendNode(cn)
282 }
283
284 children.AppendUnstructuredTokens(newline.Tokens())
285
286 // Collect any stragglers, though there shouldn't be any
287 children.AppendUnstructuredTokens(from.Tokens())
288
289 return newNode(attr)
290}
291
292func parseBlock(nativeBlock *hclsyntax.Block, from, leadComments, lineComments, newline inputTokens) *node {
293 block := &Block{

Callers 1

parseBodyItemFunction · 0.85

Calls 11

newInTreeFunction · 0.85
newNodeFunction · 0.85
newCommentsFunction · 0.85
newIdentifierFunction · 0.85
TokensMethod · 0.80
AppendNodeMethod · 0.80
PartitionMethod · 0.80
parseExpressionFunction · 0.70
RangeMethod · 0.65
LenMethod · 0.45

Tested by

no test coverage detected