From 5ffe2e5565cde1ece44217a00227d0e8393041c3 Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Tue, 10 Dec 2013 17:24:53 +0100 Subject: [PATCH] Don't allow float to end with a dot --- lexer.go | 6 ++++++ lexer_test.go | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/lexer.go b/lexer.go index c4a2bd6..0ad27a2 100644 --- a/lexer.go +++ b/lexer.go @@ -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 diff --git a/lexer_test.go b/lexer_test.go index e5846bd..c2bb2f2 100644 --- a/lexer_test.go +++ b/lexer_test.go @@ -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"},