From 96516fe6d9e4d4d84f10fb3ffaf329f82a024aa2 Mon Sep 17 00:00:00 2001 From: "Jonathan A. Sternberg" Date: Sun, 2 Jul 2017 23:33:19 -0500 Subject: [PATCH] Remove seldom used parseTokenMaybe method --- influxql/parser.go | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/influxql/parser.go b/influxql/parser.go index 6ba77bad56..6f48eb4a98 100644 --- a/influxql/parser.go +++ b/influxql/parser.go @@ -1384,11 +1384,13 @@ func (p *Parser) parseCreateContinuousQueryStatement() (*CreateContinuousQuerySt } stmt.Database = ident - if p.parseTokenMaybe(RESAMPLE) { + if tok, _, _ := p.scanIgnoreWhitespace(); tok == RESAMPLE { stmt.ResampleEvery, stmt.ResampleFor, err = p.parseResample() if err != nil { return nil, err } + } else { + p.unscan() } // Expect a "BEGIN SELECT" tokens. @@ -2525,7 +2527,7 @@ func (p *Parser) parseCall(name string) (*Call, error) { // EVERY and FOR are optional, but at least one of the two has to be used. func (p *Parser) parseResample() (time.Duration, time.Duration, error) { var interval time.Duration - if p.parseTokenMaybe(EVERY) { + if tok, _, _ := p.scanIgnoreWhitespace(); tok == EVERY { tok, pos, lit := p.scanIgnoreWhitespace() if tok != DURATIONVAL { return 0, 0, newParseError(tokstr(tok, lit), []string{"duration"}, pos) @@ -2536,10 +2538,12 @@ func (p *Parser) parseResample() (time.Duration, time.Duration, error) { return 0, 0, &ParseError{Message: err.Error(), Pos: pos} } interval = d + } else { + p.unscan() } var maxDuration time.Duration - if p.parseTokenMaybe(FOR) { + if tok, _, _ := p.scanIgnoreWhitespace(); tok == FOR { tok, pos, lit := p.scanIgnoreWhitespace() if tok != DURATIONVAL { return 0, 0, newParseError(tokstr(tok, lit), []string{"duration"}, pos) @@ -2550,6 +2554,8 @@ func (p *Parser) parseResample() (time.Duration, time.Duration, error) { return 0, 0, &ParseError{Message: err.Error(), Pos: pos} } maxDuration = d + } else { + p.unscan() } // Neither EVERY or FOR were read, so read the next token again @@ -2713,17 +2719,6 @@ func (p *Parser) parseTokens(toks []Token) error { return nil } -// parseTokenMaybe consumes the next token if it matches the expected one and -// does nothing if the next token is not the next one. -func (p *Parser) parseTokenMaybe(expected Token) bool { - tok, _, _ := p.scanIgnoreWhitespace() - if tok != expected { - p.unscan() - return false - } - return true -} - var ( // Quote String replacer. qsReplacer = strings.NewReplacer("\n", `\n`, `\`, `\\`, `'`, `\'`)