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
()
| 169 | // calls will be produced to help identify which caller in the parser is |
| 170 | // misbehaving. |
| 171 | func (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 | |
| 187 | func formatPeekerNewlineStackChanges(changes []peekerNewlineStackChange) string { |
| 188 | indent := 0 |
no test coverage detected