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

Method parseTupleCons

hclsyntax/parser.go:1326–1404  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1324}
1325
1326func (p *parser) parseTupleCons() (Expression, hcl.Diagnostics) {
1327 open := p.Read()
1328 if open.Type != TokenOBrack {
1329 // Should never happen if callers are behaving
1330 panic("parseTupleCons called without peeker pointing to open bracket")
1331 }
1332
1333 p.PushIncludeNewlines(false)
1334 defer p.PopIncludeNewlines()
1335
1336 if forKeyword.TokenMatches(p.Peek()) {
1337 return p.finishParsingForExpr(open)
1338 }
1339
1340 var close Token
1341
1342 var diags hcl.Diagnostics
1343 var exprs []Expression
1344
1345 for {
1346 next := p.Peek()
1347 if next.Type == TokenCBrack {
1348 close = p.Read() // eat closer
1349 break
1350 }
1351
1352 expr, exprDiags := p.ParseExpression()
1353 exprs = append(exprs, expr)
1354 diags = append(diags, exprDiags...)
1355
1356 if p.recovery && exprDiags.HasErrors() {
1357 // If expression parsing failed then we are probably in a strange
1358 // place in the token stream, so we'll bail out and try to reset
1359 // to after our closing bracket to allow parsing to continue.
1360 close = p.recover(TokenCBrack)
1361 break
1362 }
1363
1364 next = p.Peek()
1365 if next.Type == TokenCBrack {
1366 close = p.Read() // eat closer
1367 break
1368 }
1369
1370 if next.Type != TokenComma {
1371 if !p.recovery {
1372 switch next.Type {
1373 case TokenEOF:
1374 diags = append(diags, &hcl.Diagnostic{
1375 Severity: hcl.DiagError,
1376 Summary: "Unterminated tuple constructor expression",
1377 Detail: "There is no corresponding closing bracket before the end of the file. This may be caused by incorrect bracket nesting elsewhere in this file.",
1378 Subject: open.Range.Ptr(),
1379 })
1380 default:
1381 diags = append(diags, &hcl.Diagnostic{
1382 Severity: hcl.DiagError,
1383 Summary: "Missing item separator",

Callers 1

parseExpressionTermMethod · 0.95

Calls 10

finishParsingForExprMethod · 0.95
ParseExpressionMethod · 0.95
recoverMethod · 0.95
PushIncludeNewlinesMethod · 0.80
PopIncludeNewlinesMethod · 0.80
TokenMatchesMethod · 0.80
HasErrorsMethod · 0.80
PtrMethod · 0.80
ReadMethod · 0.45
PeekMethod · 0.45

Tested by

no test coverage detected