aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/parser/qdeclarativejslexer.cpp
diff options
context:
space:
mode:
authorRoberto Raggi <roberto.raggi@nokia.com>2011-07-20 15:08:05 +0200
committerQt by Nokia <qt-info@nokia.com>2011-08-30 13:18:28 +0200
commit6f7b0451411174103dcf6649c94ccbcdbd8d9616 (patch)
tree9cd82dcef613ef9bca803359203470b451cd5b3b /src/declarative/qml/parser/qdeclarativejslexer.cpp
parenta6da3b26f5959986010deb85703cd51a0edb48e0 (diff)
Improved parsing of numeric literals
Change-Id: Id02b5b0b0ab590b7ea5d20098472459e1fd986a6 Reviewed-on: http://codereview.qt.nokia.com/3755 Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com> Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Diffstat (limited to 'src/declarative/qml/parser/qdeclarativejslexer.cpp')
-rw-r--r--src/declarative/qml/parser/qdeclarativejslexer.cpp99
1 files changed, 83 insertions, 16 deletions
diff --git a/src/declarative/qml/parser/qdeclarativejslexer.cpp b/src/declarative/qml/parser/qdeclarativejslexer.cpp
index ac4be34765..980c15cf48 100644
--- a/src/declarative/qml/parser/qdeclarativejslexer.cpp
+++ b/src/declarative/qml/parser/qdeclarativejslexer.cpp
@@ -407,26 +407,40 @@ again:
if (_char.isDigit()) {
QByteArray chars;
chars.reserve(32);
- while (_char.isLetterOrNumber() || _char == QLatin1Char('.')) {
- if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) {
+
+ chars += ch.unicode(); // append the `.'
+
+ while (_char.isDigit()) {
+ chars += _char.unicode();
+ scanChar();
+ }
+
+ if (_char.toLower() == QLatin1Char('e')) {
+ if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) &&
+ _codePtr[1].isDigit())) {
+
chars += _char.unicode();
- scanChar(); // skip e
+ scanChar(); // consume `e'
if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) {
chars += _char.unicode();
- scanChar(); // skip +/-
+ scanChar(); // consume the sign
+ }
+
+ while (_char.isDigit()) {
+ chars += _char.unicode();
+ scanChar();
}
- } else {
- chars += _char.unicode();
- scanChar();
}
}
+
const char *begin = chars.constData();
const char *end = 0;
bool ok = false;
+
_tokenValue = qstrtod(begin, &end, &ok);
- if (! ok || end != chars.end()) {
+ if (end != chars.end()) {
_errorCode = IllegalExponentIndicator;
_errorMessage = QCoreApplication::translate("QDeclarativeParser", "Illegal syntax for exponential number");
return T_ERROR;
@@ -676,27 +690,80 @@ again:
chars.reserve(32);
chars += ch.unicode();
- while (_char.isLetterOrNumber() || _char == QLatin1Char('.')) {
- if (_char == QLatin1Char('e') || _char == QLatin1Char('E')) {
+ if (ch == QLatin1Char('0') && (_char == 'x' || _char == 'X')) {
+ // parse hex integer literal
+
+ chars += _char.unicode();
+ scanChar(); // consume `x'
+
+ while (isHexDigit(_char)) {
chars += _char.unicode();
- scanChar(); // skip e
+ scanChar();
+ }
+
+ _tokenValue = integerFromString(chars.constData(), chars.size(), 16);
+ return T_NUMERIC_LITERAL;
+ }
+
+ // decimal integer literal
+ while (_char.isDigit()) {
+ chars += _char.unicode();
+ scanChar(); // consume the digit
+ }
+
+ if (_char == QLatin1Char('.')) {
+ chars += _char.unicode();
+ scanChar(); // consume `.'
+
+ while (_char.isDigit()) {
+ chars += _char.unicode();
+ scanChar();
+ }
+
+ if (_char.toLower() == QLatin1Char('e')) {
+ if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) &&
+ _codePtr[1].isDigit())) {
- if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) {
chars += _char.unicode();
- scanChar(); // skip +/-
+ scanChar(); // consume `e'
+
+ if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) {
+ chars += _char.unicode();
+ scanChar(); // consume the sign
+ }
+
+ while (_char.isDigit()) {
+ chars += _char.unicode();
+ scanChar();
+ }
}
- } else {
+ }
+ } else if (_char.toLower() == QLatin1Char('e')) {
+ if (_codePtr[0].isDigit() || ((_codePtr[0] == QLatin1Char('+') || _codePtr[0] == QLatin1Char('-')) &&
+ _codePtr[1].isDigit())) {
+
chars += _char.unicode();
- scanChar();
+ scanChar(); // consume `e'
+
+ if (_char == QLatin1Char('+') || _char == QLatin1Char('-')) {
+ chars += _char.unicode();
+ scanChar(); // consume the sign
+ }
+
+ while (_char.isDigit()) {
+ chars += _char.unicode();
+ scanChar();
+ }
}
}
+
const char *begin = chars.constData();
const char *end = 0;
bool ok = false;
_tokenValue = qstrtod(begin, &end, &ok);
- if (! ok || end != chars.end()) {
+ if (end != chars.end()) {
_errorCode = IllegalExponentIndicator;
_errorMessage = QCoreApplication::translate("QDeclarativeParser", "Illegal syntax for exponential number");
return T_ERROR;