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