33import com .annimon .ownlang .exceptions .OperationIsNotSupportedException ;
44import com .annimon .ownlang .exceptions .TypeException ;
55import com .annimon .ownlang .lib .ArrayValue ;
6+ import com .annimon .ownlang .lib .Functions ;
67import com .annimon .ownlang .lib .NumberValue ;
78import com .annimon .ownlang .lib .StringValue ;
89import com .annimon .ownlang .lib .Types ;
@@ -54,6 +55,17 @@ public BinaryExpression(Operator operation, Expression expr1, Expression expr2)
5455 public Value eval () {
5556 final Value value1 = expr1 .eval ();
5657 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 {
5769 switch (operation ) {
5870 case ADD : return add (value1 , value2 );
5971 case SUBTRACT : return subtract (value1 , value2 );
@@ -75,10 +87,10 @@ public Value eval() {
7587 private Value add (Value value1 , Value value2 ) {
7688 switch (value1 .type ()) {
7789 case Types .NUMBER : return add ((NumberValue ) value1 , value2 );
90+ case Types .STRING : return new StringValue (value1 .asString () + value2 .asString ());
7891 case Types .ARRAY : return ArrayValue .add ((ArrayValue ) value1 , value2 );
7992 case Types .MAP : /* TODO: merge maps */
8093 case Types .FUNCTION : /* TODO: combining functions */
81- case Types .STRING :
8294 default :
8395 // Concatenation strings
8496 return new StringValue (value1 .asString () + value2 .asString ());
0 commit comments