@@ -22,7 +22,7 @@ public class ExpressionEvaluator
2222 private static readonly Regex internalCharRegex = new Regex ( @"^['](\\[']|[^'])*[']" ) ;
2323 private static readonly Regex castRegex = new Regex ( @"^\(\s*(?<typeName>[a-zA-Z_][a-zA-Z0-9_\.\[\]<>]*[?]?)\s*\)" ) ;
2424 private static readonly Regex indexingBeginningRegex = new Regex ( @"^[?]?\[" ) ;
25- private static readonly Regex assignationOperatorRegex = new Regex ( @"^\s*(?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>])" ) ;
25+ private static readonly Regex assignationOrPostFixOperatorRegex = new Regex ( @"^\s*(( ?<assignmentPrefix>[+\-*/%&|^]|<<|>>)?=(?![=>])|(?<postfixOperator>([+][+]|--)(?![a-zA-Z0-9_])) )" ) ;
2626 private static readonly Regex endOfStringWithDollar = new Regex ( "^[^\" {]*[\" {]" ) ;
2727 private static readonly Regex endOfStringWithoutDollar = new Regex ( "^[^\" ]*[\" ]" ) ;
2828 private static readonly Regex endOfStringInterpolationRegex = new Regex ( "^[^}\" ]*[}\" ]" ) ;
@@ -1642,42 +1642,50 @@ private bool EvaluateIndexing(string expr, string s, Stack<object> stack, ref in
16421642 ExpressionOperator op = indexingBeginningMatch . Length == 2 ? ExpressionOperator . IndexingWithNullConditional : ExpressionOperator . Indexing ;
16431643 dynamic left = stack . Pop ( ) ;
16441644
1645- Match assignationOperatorMatch ;
1645+ Match assignationOrPostFixOperatorMatch = assignationOrPostFixOperatorRegex . Match ( expr . Substring ( i + 1 ) ) ;
16461646
16471647 object valueToPush = null ;
16481648
1649- if ( ( assignationOperatorMatch = assignationOperatorRegex . Match ( expr . Substring ( i + 1 ) ) ) . Success )
1649+ if ( assignationOrPostFixOperatorMatch . Success )
16501650 {
1651- i += assignationOperatorMatch . Length + 1 ;
1651+ i += assignationOrPostFixOperatorMatch . Length + 1 ;
16521652
1653- if ( stack . Count > 1 )
1654- throw new ExpressionEvaluatorSyntaxErrorException ( "The left part of an assignation must be a variable, a property or an indexer." ) ;
1653+ bool postFixoperator = assignationOrPostFixOperatorMatch . Groups [ "postfixOperator" ] . Success ;
1654+ string exceptionContext = postFixoperator ? "++ or -- operator" : " an assignation" ;
16551655
1656- string rightExpression = expr . Substring ( i ) ;
1657- i = expr . Length ;
1656+ if ( stack . Count > 1 )
1657+ throw new ExpressionEvaluatorSyntaxErrorException ( $ "The left part of { exceptionContext } must be a variable, a property or an indexer." ) ;
16581658
16591659 if ( op == ExpressionOperator . IndexingWithNullConditional )
1660- throw new ExpressionEvaluatorSyntaxErrorException ( "Null coalescing is not usable left to an assignation" ) ;
1661-
1662- if ( rightExpression . Trim ( ) . Equals ( string . Empty ) )
1663- throw new ExpressionEvaluatorSyntaxErrorException ( "Right part is missing in assignation" ) ;
1660+ throw new ExpressionEvaluatorSyntaxErrorException ( $ "Null coalescing is not usable left to { exceptionContext } ") ;
16641661
1665- if ( assignationOperatorMatch . Groups [ "assignmentPrefix" ] . Success )
1662+ if ( postFixoperator )
1663+ valueToPush = assignationOrPostFixOperatorMatch . Groups [ "postfixOperator" ] . Value . Equals ( "++" ) ? left [ right ] ++ : left [ right ] -- ;
1664+ else
16661665 {
1667- ExpressionOperator prefixOp = operatorsDictionary [ assignationOperatorMatch . Groups [ "assignmentPrefix" ] . Value ] ;
1666+ string rightExpression = expr . Substring ( i ) ;
1667+ i = expr . Length ;
16681668
1669- valueToPush = operatorsEvaluations [ 0 ] [ op ] ( left , right ) ;
1669+ if ( rightExpression . Trim ( ) . Equals ( string . Empty ) )
1670+ throw new ExpressionEvaluatorSyntaxErrorException ( "Right part is missing in assignation" ) ;
16701671
1671- valueToPush = operatorsEvaluations . Find ( dict => dict . ContainsKey ( prefixOp ) ) [ prefixOp ] ( valueToPush , Evaluate ( rightExpression ) ) ;
1672- }
1673- else
1674- {
1675- valueToPush = Evaluate ( rightExpression ) ;
1676- }
1672+ if ( assignationOrPostFixOperatorMatch . Groups [ "assignmentPrefix" ] . Success )
1673+ {
1674+ ExpressionOperator prefixOp = operatorsDictionary [ assignationOrPostFixOperatorMatch . Groups [ "assignmentPrefix" ] . Value ] ;
16771675
1678- left [ right ] = valueToPush ;
1676+ valueToPush = operatorsEvaluations [ 0 ] [ op ] ( left , right ) ;
16791677
1680- stack . Clear ( ) ;
1678+ valueToPush = operatorsEvaluations . Find ( dict => dict . ContainsKey ( prefixOp ) ) [ prefixOp ] ( valueToPush , Evaluate ( rightExpression ) ) ;
1679+ }
1680+ else
1681+ {
1682+ valueToPush = Evaluate ( rightExpression ) ;
1683+ }
1684+
1685+ left [ right ] = valueToPush ;
1686+
1687+ stack . Clear ( ) ;
1688+ }
16811689 }
16821690 else
16831691 {
@@ -2324,36 +2332,6 @@ private void GetCodeUntilEndOfString(string subExpr, Match stringBeginningMatch,
23242332 }
23252333 }
23262334
2327- //private string GetCodeUntilEndOfStringInterpolation(string subExpr)
2328- //{
2329- // Match endOfStringInterpolationMatch = endOfStringInterpolationRegex.Match(subExpr);
2330- // StringBuilder result = new StringBuilder();
2331-
2332- // if (endOfStringInterpolationMatch.Success)
2333- // {
2334- // if (endOfStringInterpolationMatch.Value.EndsWith("}"))
2335- // {
2336- // result.Append(endOfStringInterpolationMatch.Value);
2337- // }
2338- // else
2339- // {
2340- // Match stringBeginningForEndBlockMatch = stringBeginningForEndBlockRegex.Match(endOfStringInterpolationMatch.Value);
2341-
2342- // string subString = GetCodeUntilEndOfString(subExpr.Substring(endOfStringInterpolationMatch.Length), stringBeginningForEndBlockMatch);
2343-
2344- // result.Append(endOfStringInterpolationMatch.Value);
2345- // result.Append(subString);
2346- // result.Append(GetCodeUntilEndOfStringInterpolation(subExpr.Substring(endOfStringInterpolationMatch.Length + subString.Length)));
2347- // }
2348- // }
2349- // else
2350- // {
2351- // result.Append(subExpr);
2352- // }
2353-
2354- // return result.ToString();
2355- //}
2356-
23572335 private string GetCodeUntilEndOfStringInterpolation ( string subExpr )
23582336 {
23592337 Match endOfStringInterpolationMatch = endOfStringInterpolationRegex . Match ( subExpr ) ;
0 commit comments