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

Function parseKeyword

json/parser.go:455–498  ·  view source on GitHub ↗
(p *peeker)

Source from the content-addressed store, hash-verified

453}
454
455func parseKeyword(p *peeker) (node, hcl.Diagnostics) {
456 tok := p.Read()
457 s := string(tok.Bytes)
458
459 switch s {
460 case "true":
461 return &booleanVal{
462 Value: true,
463 SrcRange: tok.Range,
464 }, nil
465 case "false":
466 return &booleanVal{
467 Value: false,
468 SrcRange: tok.Range,
469 }, nil
470 case "null":
471 return &nullVal{
472 SrcRange: tok.Range,
473 }, nil
474 case "undefined", "NaN", "Infinity":
475 return nil, hcl.Diagnostics{
476 {
477 Severity: hcl.DiagError,
478 Summary: "Invalid JSON keyword",
479 Detail: fmt.Sprintf("The JavaScript identifier %q cannot be used in JSON.", s),
480 Subject: &tok.Range,
481 },
482 }
483 default:
484 var dym string
485 if suggest := keywordSuggestion(s); suggest != "" {
486 dym = fmt.Sprintf(" Did you mean %q?", suggest)
487 }
488
489 return nil, hcl.Diagnostics{
490 {
491 Severity: hcl.DiagError,
492 Summary: "Invalid JSON keyword",
493 Detail: fmt.Sprintf("%q is not a valid JSON keyword.%s", s, dym),
494 Subject: &tok.Range,
495 },
496 }
497 }
498}

Callers 1

parseValueFunction · 0.85

Calls 2

keywordSuggestionFunction · 0.85
ReadMethod · 0.45

Tested by

no test coverage detected