Don't allow float to end with a dot

This commit is contained in:
Thomas Pelletier
2013-12-10 17:24:53 +01:00
parent 278c4d97ec
commit 5ffe2e5565
2 changed files with 22 additions and 0 deletions
+6
View File
@@ -413,6 +413,12 @@ func lexNumber(l *lexer) stateFn {
for {
next := l.next()
if next == '.' {
if point_seen {
return l.errorf("cannot have two dots in one float")
}
if !isDigit(l.peek()) {
return l.errorf("float cannot end with a dot")
}
point_seen = true
} else if isDigit(next) {
digit_seen = true
+16
View File
@@ -268,6 +268,22 @@ func TestKeyEqualDate(t *testing.T) {
})
}
func TestFloatEndingWithDot(t *testing.T) {
testFlow(t, "foo = 42.", []token{
token{tokenKey, "foo"},
token{tokenEqual, "="},
token{tokenError, "float cannot end with a dot"},
})
}
func TestFloatWithTwoDots(t *testing.T) {
testFlow(t, "foo = 4.2.", []token{
token{tokenKey, "foo"},
token{tokenEqual, "="},
token{tokenError, "cannot have two dots in one float"},
})
}
func TestKeyEqualNumber(t *testing.T) {
testFlow(t, "foo = 42", []token{
token{tokenKey, "foo"},