diff options
| author | Robert Griesemer <gri@golang.org> | 2009-12-18 10:52:11 -0800 |
|---|---|---|
| committer | Robert Griesemer <gri@golang.org> | 2009-12-18 10:52:11 -0800 |
| commit | 4be54c62eddc84eb1604ef04995f822609a77547 (patch) | |
| tree | bb84cb407f84a34a9259a71cb6f86150cb75068d /src/pkg/go/scanner/scanner.go | |
| parent | 5d9c9df375f694aa193c2db933a5e846fbe739cc (diff) | |
| download | golang-4be54c62eddc84eb1604ef04995f822609a77547.tar.gz | |
report an error for illegal octal numbers instead of treating them as floats
added more test cases
some capitalization cleanups
R=rsc
CC=golang-dev
http://codereview.appspot.com/180085
Diffstat (limited to 'src/pkg/go/scanner/scanner.go')
| -rw-r--r-- | src/pkg/go/scanner/scanner.go | 28 |
1 files changed, 17 insertions, 11 deletions
diff --git a/src/pkg/go/scanner/scanner.go b/src/pkg/go/scanner/scanner.go index 4735cbd3b..7a21205a9 100644 --- a/src/pkg/go/scanner/scanner.go +++ b/src/pkg/go/scanner/scanner.go @@ -271,10 +271,11 @@ func (S *Scanner) scanMantissa(base int) { } -func (S *Scanner) scanNumber(seen_decimal_point bool) token.Token { +func (S *Scanner) scanNumber(pos token.Position, seenDecimalPoint bool) token.Token { + // digitVal(S.ch) < 10 tok := token.INT - if seen_decimal_point { + if seenDecimalPoint { tok = token.FLOAT S.scanMantissa(10) goto exponent @@ -289,23 +290,29 @@ func (S *Scanner) scanNumber(seen_decimal_point bool) token.Token { S.scanMantissa(16) } else { // octal int or float + seenDecimalDigit := false S.scanMantissa(8) - if digitVal(S.ch) < 10 || S.ch == '.' || S.ch == 'e' || S.ch == 'E' { - // float - tok = token.FLOAT - goto mantissa + if S.ch == '8' || S.ch == '9' { + // illegal octal int or float + seenDecimalDigit = true + S.scanMantissa(10) + } + if S.ch == '.' || S.ch == 'e' || S.ch == 'E' { + goto fraction } // octal int + if seenDecimalDigit { + S.error(pos, "illegal octal number") + } } goto exit } -mantissa: // decimal int or float S.scanMantissa(10) +fraction: if S.ch == '.' { - // float tok = token.FLOAT S.next() S.scanMantissa(10) @@ -313,7 +320,6 @@ mantissa: exponent: if S.ch == 'e' || S.ch == 'E' { - // float tok = token.FLOAT S.next() if S.ch == '-' || S.ch == '+' { @@ -503,7 +509,7 @@ scanAgain: } case digitVal(ch) < 10: insertSemi = true - tok = S.scanNumber(false) + tok = S.scanNumber(pos, false) default: S.next() // always make progress switch ch { @@ -532,7 +538,7 @@ scanAgain: case '.': if digitVal(S.ch) < 10 { insertSemi = true - tok = S.scanNumber(true) + tok = S.scanNumber(pos, true) } else if S.ch == '.' { S.next() if S.ch == '.' { |
