(nativeBlock *hclsyntax.Block, from, leadComments, lineComments, newline inputTokens)
| 290 | } |
| 291 | |
| 292 | func parseBlock(nativeBlock *hclsyntax.Block, from, leadComments, lineComments, newline inputTokens) *node { |
| 293 | block := &Block{ |
| 294 | inTree: newInTree(), |
| 295 | } |
| 296 | children := block.children |
| 297 | |
| 298 | { |
| 299 | cn := newNode(newComments(leadComments.Tokens())) |
| 300 | block.leadComments = cn |
| 301 | children.AppendNode(cn) |
| 302 | } |
| 303 | |
| 304 | before, typeTokens, from := from.Partition(nativeBlock.TypeRange) |
| 305 | { |
| 306 | children.AppendUnstructuredTokens(before.Tokens()) |
| 307 | if typeTokens.Len() != 1 { |
| 308 | // Should never happen with valid input |
| 309 | panic("block type name is not exactly one token") |
| 310 | } |
| 311 | token := typeTokens.Tokens()[0] |
| 312 | in := newNode(newIdentifier(token)) |
| 313 | block.typeName = in |
| 314 | children.AppendNode(in) |
| 315 | } |
| 316 | |
| 317 | _, labelsNode, from := parseBlockLabels(nativeBlock, from) |
| 318 | block.labels = labelsNode |
| 319 | children.AppendNode(labelsNode) |
| 320 | |
| 321 | before, oBrace, from := from.Partition(nativeBlock.OpenBraceRange) |
| 322 | children.AppendUnstructuredTokens(before.Tokens()) |
| 323 | block.open = children.AppendUnstructuredTokens(oBrace.Tokens()) |
| 324 | |
| 325 | // We go a bit out of order here: we go hunting for the closing brace |
| 326 | // so that we have a delimited body, but then we'll deal with the body |
| 327 | // before we actually append the closing brace and any straggling tokens |
| 328 | // that appear after it. |
| 329 | bodyTokens, cBrace, from := from.Partition(nativeBlock.CloseBraceRange) |
| 330 | before, body, after := parseBody(nativeBlock.Body, bodyTokens) |
| 331 | children.AppendUnstructuredTokens(before.Tokens()) |
| 332 | block.body = body |
| 333 | children.AppendNode(body) |
| 334 | children.AppendUnstructuredTokens(after.Tokens()) |
| 335 | |
| 336 | block.close = children.AppendUnstructuredTokens(cBrace.Tokens()) |
| 337 | |
| 338 | // stragglers |
| 339 | children.AppendUnstructuredTokens(from.Tokens()) |
| 340 | if lineComments.Len() > 0 { |
| 341 | // blocks don't actually have line comments, so we'll just treat |
| 342 | // them as extra stragglers |
| 343 | children.AppendUnstructuredTokens(lineComments.Tokens()) |
| 344 | } |
| 345 | children.AppendUnstructuredTokens(newline.Tokens()) |
| 346 | |
| 347 | return newNode(block) |
| 348 | } |
| 349 |
no test coverage detected