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

Method startComment

expfmt/text_parse.go:167–224  ·  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

165// startComment represents the state where the next byte read from p.buf is the
166// start of a comment (or whitespace leading up to it).
167func (p *TextParser) startComment() stateFn {
168 if p.skipBlankTab(); p.err != nil {
169 return nil // Unexpected end of input.
170 }
171 if p.currentByte == '\n' {
172 return p.startOfLine
173 }
174 if p.readTokenUntilWhitespace(); p.err != nil {
175 return nil // Unexpected end of input.
176 }
177 // If we have hit the end of line already, there is nothing left
178 // to do. This is not considered a syntax error.
179 if p.currentByte == '\n' {
180 return p.startOfLine
181 }
182 keyword := p.currentToken.String()
183 if keyword != "HELP" && keyword != "TYPE" {
184 // Generic comment, ignore by fast forwarding to end of line.
185 for p.currentByte != '\n' {
186 if p.currentByte, p.err = p.buf.ReadByte(); p.err != nil {
187 return nil // Unexpected end of input.
188 }
189 }
190 return p.startOfLine
191 }
192 // There is something. Next has to be a metric name.
193 if p.skipBlankTab(); p.err != nil {
194 return nil // Unexpected end of input.
195 }
196 if p.readTokenAsMetricName(); p.err != nil {
197 return nil // Unexpected end of input.
198 }
199 if p.currentByte == '\n' {
200 // At the end of the line already.
201 // Again, this is not considered a syntax error.
202 return p.startOfLine
203 }
204 if !isBlankOrTab(p.currentByte) {
205 p.parseError("invalid metric name in comment")
206 return nil
207 }
208 p.setOrCreateCurrentMF()
209 if p.skipBlankTab(); p.err != nil {
210 return nil // Unexpected end of input.
211 }
212 if p.currentByte == '\n' {
213 // At the end of the line already.
214 // Again, this is not considered a syntax error.
215 return p.startOfLine
216 }
217 switch keyword {
218 case "HELP":
219 return p.readingHelp
220 case "TYPE":
221 return p.readingType
222 }
223 panic(fmt.Sprintf("code error: unexpected keyword %q", keyword))
224}

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