3
3
import com .annimon .ownlang .exceptions .OperationIsNotSupportedException ;
4
4
import com .annimon .ownlang .exceptions .TypeException ;
5
5
import com .annimon .ownlang .lib .ArrayValue ;
6
+ import com .annimon .ownlang .lib .Functions ;
6
7
import com .annimon .ownlang .lib .NumberValue ;
7
8
import com .annimon .ownlang .lib .StringValue ;
8
9
import com .annimon .ownlang .lib .Types ;
@@ -54,6 +55,17 @@ public BinaryExpression(Operator operation, Expression expr1, Expression expr2)
54
55
public Value eval () {
55
56
final Value value1 = expr1 .eval ();
56
57
final Value value2 = expr2 .eval ();
58
+ try {
59
+ return eval (value1 , value2 );
60
+ } catch (OperationIsNotSupportedException ex ) {
61
+ if (Functions .isExists (operation .toString ())) {
62
+ return Functions .get (operation .toString ()).execute (value1 , value2 );
63
+ }
64
+ throw ex ;
65
+ }
66
+ }
67
+
68
+ private Value eval (Value value1 , Value value2 ) throws OperationIsNotSupportedException {
57
69
switch (operation ) {
58
70
case ADD : return add (value1 , value2 );
59
71
case SUBTRACT : return subtract (value1 , value2 );
@@ -75,10 +87,10 @@ public Value eval() {
75
87
private Value add (Value value1 , Value value2 ) {
76
88
switch (value1 .type ()) {
77
89
case Types .NUMBER : return add ((NumberValue ) value1 , value2 );
90
+ case Types .STRING : return new StringValue (value1 .asString () + value2 .asString ());
78
91
case Types .ARRAY : return ArrayValue .add ((ArrayValue ) value1 , value2 );
79
92
case Types .MAP : /* TODO: merge maps */
80
93
case Types .FUNCTION : /* TODO: combining functions */
81
- case Types .STRING :
82
94
default :
83
95
// Concatenation strings
84
96
return new StringValue (value1 .asString () + value2 .asString ());
0 commit comments