()
| 1404 | } |
| 1405 | |
| 1406 | func (p *parser) parseObjectCons() (Expression, hcl.Diagnostics) { |
| 1407 | open := p.Read() |
| 1408 | if open.Type != TokenOBrace { |
| 1409 | // Should never happen if callers are behaving |
| 1410 | panic("parseObjectCons called without peeker pointing to open brace") |
| 1411 | } |
| 1412 | |
| 1413 | // We must temporarily stop looking at newlines here while we check for |
| 1414 | // a "for" keyword, since for expressions are _not_ newline-sensitive, |
| 1415 | // even though object constructors are. |
| 1416 | p.PushIncludeNewlines(false) |
| 1417 | isFor := forKeyword.TokenMatches(p.Peek()) |
| 1418 | p.PopIncludeNewlines() |
| 1419 | if isFor { |
| 1420 | return p.finishParsingForExpr(open) |
| 1421 | } |
| 1422 | |
| 1423 | p.PushIncludeNewlines(true) |
| 1424 | defer p.PopIncludeNewlines() |
| 1425 | |
| 1426 | var close Token |
| 1427 | |
| 1428 | var diags hcl.Diagnostics |
| 1429 | var items []ObjectConsItem |
| 1430 | |
| 1431 | for { |
| 1432 | next := p.Peek() |
| 1433 | if next.Type == TokenNewline { |
| 1434 | p.Read() // eat newline |
| 1435 | continue |
| 1436 | } |
| 1437 | |
| 1438 | if next.Type == TokenCBrace { |
| 1439 | close = p.Read() // eat closer |
| 1440 | break |
| 1441 | } |
| 1442 | |
| 1443 | // Wrapping parens are not explicitly represented in the AST, but |
| 1444 | // we want to use them here to disambiguate intepreting a mapping |
| 1445 | // key as a full expression rather than just a name, and so |
| 1446 | // we'll remember this was present and use it to force the |
| 1447 | // behavior of our final ObjectConsKeyExpr. |
| 1448 | forceNonLiteral := (p.Peek().Type == TokenOParen) |
| 1449 | |
| 1450 | var key Expression |
| 1451 | var keyDiags hcl.Diagnostics |
| 1452 | key, keyDiags = p.ParseExpression() |
| 1453 | diags = append(diags, keyDiags...) |
| 1454 | |
| 1455 | if p.recovery && keyDiags.HasErrors() { |
| 1456 | // If expression parsing failed then we are probably in a strange |
| 1457 | // place in the token stream, so we'll bail out and try to reset |
| 1458 | // to after our closing brace to allow parsing to continue. |
| 1459 | close = p.recover(TokenCBrace) |
| 1460 | break |
| 1461 | } |
| 1462 | |
| 1463 | // We wrap up the key expression in a special wrapper that deals |
no test coverage detected