From 1f93d72710cd0d97c302ebb094b5aed01c786384 Mon Sep 17 00:00:00 2001 From: SiegeLord Date: Sat, 11 Jan 2014 16:27:48 -0500 Subject: Rust: Make lexing of float literals more correct. --- lexers/LexRust.cxx | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/lexers/LexRust.cxx b/lexers/LexRust.cxx index 8917b9182..bf59933af 100644 --- a/lexers/LexRust.cxx +++ b/lexers/LexRust.cxx @@ -240,22 +240,6 @@ static void ScanDigits(Accessor& styler, int& pos, int base) { } } -static bool ScanExponent(Accessor& styler, int& pos) { - int c = styler.SafeGetCharAt(pos, '\0'); - if (c == 'e' || c == 'E') { - pos++; - c = styler.SafeGetCharAt(pos, '\0'); - if (c == '-' || c == '+') - pos++; - int old_pos = pos; - ScanDigits(styler, pos, 10); - if (old_pos == pos) { - return false; - } - } - return true; -} - static void ScanNumber(Accessor& styler, int& pos) { int base = 10; int c = styler.SafeGetCharAt(pos, '\0'); @@ -287,13 +271,31 @@ static void ScanNumber(Accessor& styler, int& pos) { } else if (c == '6' && n == '4') { pos += 2; } - } else if (c == '.') { - error = base != 10; - pos++; - ScanDigits(styler, pos, 10); - error |= !ScanExponent(styler, pos); + } else { + n = styler.SafeGetCharAt(pos + 1, '\0'); + if (c == '.' && !(IsIdentifierStart(n) || n == '.')) { + error |= base != 10; + pos++; + ScanDigits(styler, pos, 10); + } + + c = styler.SafeGetCharAt(pos, '\0'); + if (c == 'e' || c == 'E') { + error |= base != 10; + pos++; + c = styler.SafeGetCharAt(pos, '\0'); + if (c == '-' || c == '+') + pos++; + int old_pos = pos; + ScanDigits(styler, pos, 10); + if (old_pos == pos) { + error = true; + } + } + c = styler.SafeGetCharAt(pos, '\0'); if (c == 'f') { + error |= base != 10; pos++; c = styler.SafeGetCharAt(pos, '\0'); n = styler.SafeGetCharAt(pos + 1, '\0'); -- cgit v1.2.3