Skip to content

Commit

Permalink
update lexer to allow numbers without leading zeros (#589)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathaniel Cook committed May 31, 2016
1 parent 1696081 commit dc2c9f4
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 32 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ kapacitor replay-live query -task cpu_alert -query 'SELECT usage_idle FROM teleg
- [#561](https://github.com/influxdata/kapacitor/issues/561): Fixes bug when lambda expressions would return error about types with nested binary expressions.
- [#555](https://github.com/influxdata/kapacitor/issues/555): Fixes bug where "time" functions didn't work in lambda expressions.
- [#570](https://github.com/influxdata/kapacitor/issues/570): Removes panic in SMTP service on failed close connection.
- [#587](https://github.com/influxdata/kapacitor/issues/587): Allow number literals without leading zeros.

## v0.13.1 [2016-05-13]

Expand Down
1 change: 0 additions & 1 deletion services/task_store/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,6 @@ func (ts *Service) handleCreateTask(w http.ResponseWriter, r *http.Request) {
}
w.Write(httpd.MarshalJSON(t, true))
}

func (ts *Service) handleUpdateTask(w http.ResponseWriter, r *http.Request) {
id, err := ts.taskIDFromPath(r.URL.Path)
if err != nil {
Expand Down
17 changes: 10 additions & 7 deletions tick/ast/lex.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,9 @@ func lexToken(l *lexer) stateFn {
case isOperatorChar(r):
l.backup()
return lexOperator
case unicode.IsDigit(r), r == '-':
case unicode.IsDigit(r), r == '-', r == '.':
l.backup()
return lexNumberOrDuration
return lexNumberOrDurationOrDot
case unicode.IsLetter(r):
return lexIdentOrKeyword
case r == '"':
Expand All @@ -348,9 +348,6 @@ func lexToken(l *lexer) stateFn {
case r == ']':
l.emit(TokenRSBracket)
return lexToken
case r == '.':
l.emit(TokenDot)
return lexToken
case r == '|':
l.emit(TokenPipe)
return lexToken
Expand Down Expand Up @@ -473,18 +470,23 @@ func isDurUnit(r rune) bool {
return strings.IndexRune(durationUnits, r) != -1
}

func lexNumberOrDuration(l *lexer) stateFn {
func lexNumberOrDurationOrDot(l *lexer) stateFn {
foundDecimal := false
first := true
for {
switch r := l.next(); {
case r == '.':
if first && !unicode.IsDigit(l.peek()) {
l.emit(TokenDot)
return lexToken
}
if foundDecimal {
return l.errorf("multiple decimals in number")
}
foundDecimal = true
case unicode.IsDigit(r):
//absorb
case isDurUnit(r):
case !foundDecimal && isDurUnit(r):
if r == 'm' && l.peek() == 's' {
l.next()
}
Expand All @@ -495,6 +497,7 @@ func lexNumberOrDuration(l *lexer) stateFn {
l.emit(TokenNumber)
return lexToken
}
first = false
}
}

Expand Down
25 changes: 1 addition & 24 deletions tick/ast/lex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,8 +249,7 @@ func TestLexer(t *testing.T) {
{
in: ".421",
tokens: []token{
token{TokenDot, 0, "."},
token{TokenNumber, 1, "421"},
token{TokenNumber, 0, ".421"},
token{TokenEOF, 4, ""},
},
},
Expand All @@ -269,28 +268,6 @@ func TestLexer(t *testing.T) {
token{TokenEOF, 3, ""},
},
},
{
in: "42.21m",
tokens: []token{
token{TokenDuration, 0, "42.21m"},
token{TokenEOF, 6, ""},
},
},
{
in: ".421h",
tokens: []token{
token{TokenDot, 0, "."},
token{TokenDuration, 1, "421h"},
token{TokenEOF, 5, ""},
},
},
{
in: "0.421s",
tokens: []token{
token{TokenDuration, 0, "0.421s"},
token{TokenEOF, 6, ""},
},
},
{
in: "1u",
tokens: []token{
Expand Down

0 comments on commit dc2c9f4

Please sign in to comment.