Skip to content
Permalink
Browse files

Merge pull request #35996 from agiudiceandrea/patch-int64-qgsexpression

 Fix int64 literals parsing in QgsExpression
  • Loading branch information
elpaso committed May 1, 2020
2 parents 253c706 + aa5141c commit fddc6b46e1f542f05ce5fc2ffed41f7bd28290d0
Showing with 8 additions and 0 deletions.
  1. +4 −0 src/core/qgsexpressionlexer.ll
  2. +3 −0 src/core/qgsexpressionparser.yy
  3. +1 −0 tests/src/core/testqgsexpression.cpp
@@ -209,6 +209,10 @@ string "'"{str_char}*"'"
if( ok )
return NUMBER_INT;
yylval->numberInt64 = cLocale()->toLongLong( QString::fromLatin1(yytext), &ok );
if( ok )
return NUMBER_INT64;
yylval->numberFloat = cLocale()->toDouble( QString::fromLatin1(yytext), &ok );
if( ok )
return NUMBER_FLOAT;
@@ -97,6 +97,7 @@ void addParserLocation(YYLTYPE* yyloc, QgsExpressionNode *node)
QgsExpressionNode::NamedNode* namednode;
double numberFloat;
int numberInt;
qlonglong numberInt64;
bool boolVal;
QString* text;
QgsExpressionNodeBinaryOperator::BinaryOperator b_op;
@@ -120,6 +121,7 @@ void addParserLocation(YYLTYPE* yyloc, QgsExpressionNode *node)
// literals
%token <numberFloat> NUMBER_FLOAT
%token <numberInt> NUMBER_INT
%token <numberInt64> NUMBER_INT64
%token <boolVal> BOOLEAN
%token NULLVALUE

@@ -326,6 +328,7 @@ expression:
// literals
| NUMBER_FLOAT { $$ = new QgsExpressionNodeLiteral( QVariant($1) ); }
| NUMBER_INT { $$ = new QgsExpressionNodeLiteral( QVariant($1) ); }
| NUMBER_INT64 { $$ = new QgsExpressionNodeLiteral( QVariant($1) ); }
| BOOLEAN { $$ = new QgsExpressionNodeLiteral( QVariant($1) ); }
| STRING { $$ = new QgsExpressionNodeLiteral( QVariant(*$1) ); delete $1; }
| NULLVALUE { $$ = new QgsExpressionNodeLiteral( QVariant() ); }
@@ -558,6 +558,7 @@ class TestQgsExpression: public QObject
// literal evaluation
QTest::newRow( "literal null" ) << "NULL" << false << QVariant();
QTest::newRow( "literal int" ) << "123" << false << QVariant( 123 );
QTest::newRow( "literal int64" ) << "1234567890123456789" << false << QVariant( qlonglong( 1234567890123456789 ) );
QTest::newRow( "literal double" ) << "1.2" << false << QVariant( 1.2 );
QTest::newRow( "literal text" ) << "'hello'" << false << QVariant( "hello" );
QTest::newRow( "literal double" ) << ".000001" << false << QVariant( 0.000001 );

0 comments on commit fddc6b4

Please sign in to comment.
You can’t perform that action at this time.