MCPcopy
hub / github.com/uber/aresdb / parseOptionalTokenAndInt

Method parseOptionalTokenAndInt

query/expr/parser.go:198–226  ·  view source on GitHub ↗

parseOptionalTokenAndInt parses the specified token followed by an int, if it exists.

(t Token)

Source from the content-addressed store, hash-verified

196// parseOptionalTokenAndInt parses the specified token followed
197// by an int, if it exists.
198func (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.
229func (p *Parser) parseVarRef() (*VarRef, error) {

Callers

nothing calls this directly

Calls 5

scanIgnoreWhitespaceMethod · 0.95
unscanMethod · 0.95
newParseErrorFunction · 0.85
tokstrFunction · 0.85
StringMethod · 0.65

Tested by

no test coverage detected