MCPcopy Create free account
hub / github.com/prometheus/common / startComment

Method startComment

expfmt/text_parse.go:224–284  ·  view source on GitHub ↗

startComment represents the state where the next byte read from p.buf is the start of a comment (or whitespace leading up to it).

()

Source from the content-addressed store, hash-verified

222// startComment represents the state where the next byte read from p.buf is the
223// start of a comment (or whitespace leading up to it).
224func (p *TextParser) startComment() stateFn {
225 if p.skipBlankTab(); p.err != nil {
226 return nil // Unexpected end of input.
227 }
228 if p.currentByte == '\n' {
229 return p.startOfLine
230 }
231 if p.readTokenUntilWhitespace(); p.err != nil {
232 return nil // Unexpected end of input.
233 }
234 // If we have hit the end of line already, there is nothing left
235 // to do. This is not considered a syntax error.
236 if p.currentByte == '\n' {
237 return p.startOfLine
238 }
239 keyword := p.currentToken.String()
240 if keyword != "HELP" && keyword != "TYPE" {
241 // Generic comment, ignore by fast forwarding to end of line.
242 for p.currentByte != '\n' {
243 if p.currentByte, p.err = p.buf.ReadByte(); p.err != nil {
244 return nil // Unexpected end of input.
245 }
246 }
247 return p.startOfLine
248 }
249 // There is something. Next has to be a metric name.
250 if p.skipBlankTab(); p.err != nil {
251 return nil // Unexpected end of input.
252 }
253 if p.readTokenAsMetricName(); p.err != nil {
254 return nil // Unexpected end of input.
255 }
256 if p.currentByte == '\n' {
257 // At the end of the line already.
258 // Again, this is not considered a syntax error.
259 return p.startOfLine
260 }
261 if !isBlankOrTab(p.currentByte) {
262 p.parseError("invalid metric name in comment")
263 return nil
264 }
265 p.setOrCreateCurrentMF()
266 if p.err != nil {
267 return nil
268 }
269 if p.skipBlankTab(); p.err != nil {
270 return nil // Unexpected end of input.
271 }
272 if p.currentByte == '\n' {
273 // At the end of the line already.
274 // Again, this is not considered a syntax error.
275 return p.startOfLine
276 }
277 switch keyword {
278 case "HELP":
279 return p.readingHelp
280 case "TYPE":
281 return p.readingType

Callers

nothing calls this directly

Calls 7

skipBlankTabMethod · 0.95
readTokenAsMetricNameMethod · 0.95
parseErrorMethod · 0.95
setOrCreateCurrentMFMethod · 0.95
isBlankOrTabFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected