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

Method AssertEmptyIncludeNewlinesStack

hclsyntax/peeker.go:171–185  ·  view source on GitHub ↗

AssertEmptyNewlinesStack checks if the IncludeNewlinesStack is empty, doing panicking if it is not. This can be used to catch stack mismanagement that might otherwise just cause confusing downstream errors. This function is a no-op if the stack is empty when called. If newlines stack tracing is en

()

Source from the content-addressed store, hash-verified

169// calls will be produced to help identify which caller in the parser is
170// misbehaving.
171func (p *peeker) AssertEmptyIncludeNewlinesStack() {
172 if len(p.IncludeNewlinesStack) != 1 {
173 // Should never happen; indicates mismanagement of the stack inside
174 // the parser.
175 if p.newlineStackChanges != nil { // only if traceNewlinesStack is enabled above
176 panic(fmt.Errorf(
177 "non-empty IncludeNewlinesStack after parse with %d calls unaccounted for:\n%s",
178 len(p.IncludeNewlinesStack)-1,
179 formatPeekerNewlineStackChanges(p.newlineStackChanges),
180 ))
181 } else {
182 panic(fmt.Errorf("non-empty IncludeNewlinesStack after parse: %#v", p.IncludeNewlinesStack))
183 }
184 }
185}
186
187func formatPeekerNewlineStackChanges(changes []peekerNewlineStackChange) string {
188 indent := 0

Callers 5

ParseConfigFunction · 0.80
ParseExpressionFunction · 0.80
ParseTemplateFunction · 0.80
ParseTraversalAbsFunction · 0.80
ParseTraversalPartialFunction · 0.80

Calls 1

Tested by

no test coverage detected