MCPcopy
hub / github.com/google/go-jsonnet / parseObjectRemainderComp

Method parseObjectRemainderComp

internal/parser/parser.go:356–395  ·  view source on GitHub ↗
(fields ast.ObjectFields, gotComma bool, tok *token, next *token)

Source from the content-addressed store, hash-verified

354}
355
356func (p *parser) parseObjectRemainderComp(fields ast.ObjectFields, gotComma bool, tok *token, next *token) (ast.Node, *token, errors.StaticError) {
357 numFields := 0
358 numAsserts := 0
359 var field ast.ObjectField
360 for _, f := range fields {
361 if f.Kind == ast.ObjectLocal {
362 continue
363 }
364 if f.Kind == ast.ObjectAssert {
365 numAsserts++
366 continue
367 }
368 numFields++
369 field = f
370 }
371
372 if numAsserts > 0 {
373 return nil, nil, errors.MakeStaticError("Object comprehension cannot have asserts", next.loc)
374 }
375 if numFields != 1 {
376 return nil, nil, errors.MakeStaticError("Object comprehension can only have one field", next.loc)
377 }
378 if field.Hide != ast.ObjectFieldInherit {
379 return nil, nil, errors.MakeStaticError("Object comprehensions cannot have hidden fields", next.loc)
380 }
381 if field.Kind != ast.ObjectFieldExpr {
382 return nil, nil, errors.MakeStaticError("Object comprehensions can only have [e] fields", next.loc)
383 }
384 spec, last, err := p.parseComprehensionSpecs(next, tokenBraceR)
385 if err != nil {
386 return nil, nil, err
387 }
388 return &ast.ObjectComp{
389 NodeBase: ast.NewNodeBaseLoc(locFromTokens(tok, last), tok.fodder),
390 Fields: fields,
391 TrailingComma: gotComma,
392 Spec: *spec,
393 CloseFodder: last.fodder,
394 }, last, nil
395}
396
397func (p *parser) parseObjectRemainderField(literalFields *literalFieldSet, tok *token, next *token) (*ast.ObjectField, errors.StaticError) {
398 var kind ast.ObjectFieldKind

Callers 1

parseObjectRemainderMethod · 0.95

Calls 3

MakeStaticErrorFunction · 0.92
locFromTokensFunction · 0.85

Tested by

no test coverage detected