@@ -93,8 +93,8 @@ private AphidObject InterpretOrExpression(BinaryOperatorExpression expression)
93
93
94
94
private AphidObject InterpretEqualityExpression ( BinaryOperatorExpression expression )
95
95
{
96
- var left = InterpretExpression ( expression . LeftOperand ) as AphidObject ;
97
- var right = InterpretExpression ( expression . RightOperand ) as AphidObject ;
96
+ var left = ( AphidObject ) InterpretExpression ( expression . LeftOperand ) ;
97
+ var right = ( AphidObject ) InterpretExpression ( expression . RightOperand ) ;
98
98
99
99
bool val = left . Value != null ?
100
100
left . Value . Equals ( right . Value ) :
@@ -718,6 +718,34 @@ public AphidObject InterpretThisExpression()
718
718
return _currentScope . Variables ;
719
719
}
720
720
721
+ public AphidObject InterpretPatternMatchingExpression ( PatternMatchingExpression expression )
722
+ {
723
+ var left = ( AphidObject ) InterpretExpression ( expression . TestExpression ) ;
724
+
725
+ foreach ( var p in expression . Patterns )
726
+ {
727
+ if ( p . Item1 != null )
728
+ {
729
+ var right = ( AphidObject ) InterpretExpression ( p . Item1 ) ;
730
+
731
+ var b = left . Value != null ?
732
+ left . Value . Equals ( right . Value ) :
733
+ ( null == right . Value && left . Count == 0 && right . Count == 0 ) ;
734
+
735
+ if ( b )
736
+ {
737
+ return ValueHelper . Wrap ( InterpretExpression ( p . Item2 ) ) ;
738
+ }
739
+ }
740
+ else
741
+ {
742
+ return ValueHelper . Wrap ( InterpretExpression ( p . Item2 ) ) ;
743
+ }
744
+ }
745
+
746
+ return new AphidObject ( ) ;
747
+ }
748
+
721
749
private object InterpretExpression ( Expression expression )
722
750
{
723
751
if ( expression is BinaryOperatorExpression )
@@ -801,6 +829,10 @@ private object InterpretExpression(Expression expression)
801
829
{
802
830
return InterpretThisExpression ( ) ;
803
831
}
832
+ else if ( expression is PatternMatchingExpression )
833
+ {
834
+ return InterpretPatternMatchingExpression ( expression as PatternMatchingExpression ) ;
835
+ }
804
836
else
805
837
{
806
838
throw new AphidRuntimeException ( "Unexpected expression {0}" , expression ) ;
0 commit comments