#### <a id="operator-additive-assignment"></a> Operator +=
-Modifies a dictionary or array by adding new elements to it.
-
-Example:
+The += operator is a shortcut. The following expression:
{
a = [ "hello" ],
a += [ "world" ]
}
-In this example a contains both `"hello"` and `"world"`. This currently
-only works for dictionaries and arrays.
+is equivalent to:
-<!--
+ {
+ a = [ "hello" ],
+ a = a + [ "world" ]
+ }
#### <a id="operator-substractive-assignment"></a> Operator -=
-Removes elements from a dictionary.
-
-Example:
+The -= operator is a shortcut. The following expression:
{
- a = { "hello", "world" },
- a -= [ "world" ]
+ a = 10,
+ a -= 5
}
-In this example a contains `"hello"`. Trying to remove an item that does
-not exist is not an error. Not implemented yet.
+is equivalent to:
+
+ {
+ a = 10,
+ a = a - 5
+ }
#### <a id="operator-multiply-assignment"></a> Operator \*=
-Multiplies an existing dictionary element with the specified number. If
-the dictionary element does not already exist 0 is used as its value.
-
-Example:
+The *= operator is a shortcut. The following expression:
{
a = 60,
a *= 5
}
-In this example a is 300. This only works for numbers. Not implemented
-yet.
+is equivalent to:
+
+ {
+ a = 60,
+ a = a * 5
+ }
#### <a id="operator-dividing-assignment"></a> Operator /=
-Divides an existing dictionary element by the specified number. If the
-dictionary element does not already exist 0 is used as its value.
-
-Example:
+The /= operator is a shortcut. The following expression:
{
a = 300,
a /= 5
}
-In this example a is 60. This only works for numbers. Not implemented
-yet.
+is equivalent to:
--->
+ {
+ a = 300,
+ a = a / 5
+ }
### <a id="indexer"></a> Indexer
Value AExpression::OpIndexer(const AExpression *expr, const Dictionary::Ptr& locals)
{
Dictionary::Ptr dict = locals->Get(expr->m_Operand1);
+
+ if (!dict)
+ BOOST_THROW_EXCEPTION(ConfigError("Script variable '" + expr->m_Operand1 + "' not set in this scope."));
+
return dict->Get(expr->m_Operand2);
}
lterm: identifier lbinary_op rterm
{
AExpression::Ptr aexpr = static_cast<AExpression::Ptr>(*$3);
- if ($2 == &AExpression::OpSetPlus || $2 == &AExpression::OpSetMinus || $2 == &AExpression::OpSetMultiply || $2 == &AExpression::OpSetDivide)
- aexpr->MakeInline();
-
$$ = new Value(make_shared<AExpression>($2, $1, aexpr, DebugInfoRange(@1, @3)));
free($1);
delete $3;
subexprl->Add(subexpr);
AExpression::Ptr expr = make_shared<AExpression>(&AExpression::OpDict, subexprl, DebugInfoRange(@1, @6));
- if ($5 == &AExpression::OpSetPlus || $5 == &AExpression::OpSetMinus || $5 == &AExpression::OpSetMultiply || $5 == &AExpression::OpSetDivide)
- expr->MakeInline();
-
$$ = new Value(make_shared<AExpression>(&AExpression::OpSetPlus, $1, expr, DebugInfoRange(@1, @6)));
free($1);
}