parseOptionalTokenAndInt parses the specified token followed by an int, if it exists.
(t Token)
| 196 | // parseOptionalTokenAndInt parses the specified token followed |
| 197 | // by an int, if it exists. |
| 198 | func (p *Parser) parseOptionalTokenAndInt(t Token) (int, error) { |
| 199 | // Check if the token exists. |
| 200 | if tok, _, _ := p.scanIgnoreWhitespace(); tok != t { |
| 201 | p.unscan() |
| 202 | return 0, nil |
| 203 | } |
| 204 | |
| 205 | // Scan the number. |
| 206 | tok, pos, lit := p.scanIgnoreWhitespace() |
| 207 | if tok != NUMBER { |
| 208 | return 0, newParseError(tokstr(tok, lit), []string{"number"}, pos) |
| 209 | } |
| 210 | |
| 211 | // Return an error if the number has a fractional part. |
| 212 | if strings.Contains(lit, ".") { |
| 213 | msg := fmt.Sprintf("fractional parts not allowed in %s", t.String()) |
| 214 | return 0, &ParseError{Message: msg, Pos: pos} |
| 215 | } |
| 216 | |
| 217 | // Parse number. |
| 218 | n, _ := strconv.ParseInt(lit, 10, 64) |
| 219 | |
| 220 | if n < 0 { |
| 221 | msg := fmt.Sprintf("%s must be >= 0", t.String()) |
| 222 | return 0, &ParseError{Message: msg, Pos: pos} |
| 223 | } |
| 224 | |
| 225 | return int(n), nil |
| 226 | } |
| 227 | |
| 228 | // parseVarRef parses a reference to a measurement or field. |
| 229 | func (p *Parser) parseVarRef() (*VarRef, error) { |
nothing calls this directly
no test coverage detected