summaryrefslogtreecommitdiff
path: root/src/expr.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-11-15 20:34:42 (GMT)
committerMarius Kintel <marius@kintel.net>2013-11-15 20:34:42 (GMT)
commit022f80e87b1df5af489414a01bf2b5bcef1c3acd (patch)
treed20c8d9df56f129880df6426c0f885479ebc014a /src/expr.cc
parentaf8359993a6dfffed8f57bc5605f2ca77a353ffa (diff)
parentf46bd3788f75e691b65aaf0e4ffb1db1029ef717 (diff)
Merge pull request #542 from t-paul/issue500
Allow for statement with negative step value.
Diffstat (limited to 'src/expr.cc')
-rw-r--r--src/expr.cc23
1 files changed, 17 insertions, 6 deletions
diff --git a/src/expr.cc b/src/expr.cc
index 594fccf..08615ba 100644
--- a/src/expr.cc
+++ b/src/expr.cc
@@ -117,11 +117,18 @@ Value Expression::evaluate(const Context *context) const
if (this->type == "R") {
Value v1 = this->children[0]->evaluate(context);
Value v2 = this->children[1]->evaluate(context);
- Value v3 = this->children[2]->evaluate(context);
- if (v1.type() == Value::NUMBER && v2.type() == Value::NUMBER && v3.type() == Value::NUMBER) {
- Value::RangeType range(v1.toDouble(), v2.toDouble(), v3.toDouble());
- return Value(range);
- }
+ if (this->children.size() == 2) {
+ if (v1.type() == Value::NUMBER && v2.type() == Value::NUMBER) {
+ Value::RangeType range(v1.toDouble(), v2.toDouble());
+ return Value(range);
+ }
+ } else {
+ Value v3 = this->children[2]->evaluate(context);
+ if (v1.type() == Value::NUMBER && v2.type() == Value::NUMBER && v3.type() == Value::NUMBER) {
+ Value::RangeType range(v1.toDouble(), v2.toDouble(), v3.toDouble());
+ return Value(range);
+ }
+ }
return Value();
}
if (this->type == "V") {
@@ -192,7 +199,11 @@ std::string Expression::toString() const
stream << this->const_value;
}
else if (this->type == "R") {
- stream << "[" << *this->children[0] << " : " << *this->children[1] << " : " << *this->children[2] << "]";
+ stream << "[" << *this->children[0] << " : " << *this->children[1];
+ if (this->children.size() > 2) {
+ stream << " : " << *this->children[2];
+ }
+ stream << "]";
}
else if (this->type == "V") {
stream << "[";
contact: Jan Huwald // Impressum