Fixup unary '-'

.. so date-9 is not treated as "date" "-9" but
   instead as "date" "-" "9"
This commit is contained in:
Mark Liversedge
2015-08-17 15:21:24 +01:00
parent 6088c21a32
commit e1f2c1b48b
4 changed files with 41 additions and 5 deletions

View File

@@ -143,6 +143,9 @@ Leaf::isDynamic(Leaf *leaf)
case Leaf::Logical :
if (leaf->op == 0) return leaf->isDynamic(leaf->lvalue.l);
case Leaf::UnaryOperation :
return leaf->isDynamic(leaf->lvalue.l);
break;
case Leaf::Operation :
case Leaf::BinaryOperation :
return leaf->isDynamic(leaf->lvalue.l) || leaf->isDynamic(leaf->rvalue.l);
@@ -262,6 +265,10 @@ void Leaf::color(Leaf *leaf, QTextDocument *document)
return;
break;
case Leaf::UnaryOperation :
leaf->color(leaf->lvalue.l, document);
return;
break;
case Leaf::BinaryOperation :
leaf->color(leaf->lvalue.l, document);
leaf->color(leaf->rvalue.l, document);
@@ -338,6 +345,9 @@ void Leaf::print(Leaf *leaf, int level)
leaf->print(leaf->lvalue.l, level+1);
leaf->print(leaf->rvalue.l, level+1);
break;
case Leaf::UnaryOperation : qDebug()<<"uop"<<leaf->op;
leaf->print(leaf->lvalue.l, level+1);
break;
case Leaf::BinaryOperation : qDebug()<<"bop"<<leaf->op;
leaf->print(leaf->lvalue.l, level+1);
leaf->print(leaf->rvalue.l, level+1);
@@ -414,6 +424,7 @@ bool Leaf::isNumber(DataFilter *df, Leaf *leaf)
break;
case Leaf::Logical : return true; // not possible!
case Leaf::Operation : return true;
case Leaf::UnaryOperation : return true;
case Leaf::BinaryOperation : return true;
case Leaf::Function : return true;
case Leaf::Vector :
@@ -594,6 +605,14 @@ void Leaf::validateFilter(DataFilter *df, Leaf *leaf)
}
break;
case Leaf::UnaryOperation :
{ // only 1 at present, unary minus return the value * -1
if (!Leaf::isNumber(df, leaf->lvalue.l)) {
DataFiltererrors << QString(QObject::tr("unary negation on a string!"));
leaf->inerror = true;
}
}
break;
case Leaf::BinaryOperation :
case Leaf::Operation :
{
@@ -1266,6 +1285,18 @@ Result Leaf::eval(Context *context, DataFilter *df, Leaf *leaf, RideItem *m)
}
break;
//
// UNARY EXPRESSION
//
case Leaf::UnaryOperation :
{
// get result
Result lhs = eval(context, df, leaf->lvalue.l, m);
return Result(lhs.number * -1);
}
break;
//
// BINARY EXPRESSION
//