Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/Ramstack.ExpressionParser/ExpressionBuilder.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,8 @@ private static BinaryExpression ApplyNullCoalescing(Identifier op, Expression lh
/// <returns>
/// <see langword="true" /> if the expression is the null literal; otherwise, <see langword="false" />.
/// </returns>
private static bool IsNullLiteral(Expr expr)
{
while (expr is Expr.Parenthesized parenthesized)
expr = parenthesized.Expression;

return expr is Expr.Literal { Value: null };
}
private static bool IsNullLiteral(Expr expr) =>
SkipParentheses(expr) is Expr.Literal { Value: null };

/// <summary>
/// Determines whether the specified expression is the integer literal 0, possibly in parentheses.
Expand All @@ -248,12 +243,22 @@ private static bool IsNullLiteral(Expr expr)
/// <returns>
/// <see langword="true" /> if the expression is the integer literal 0; otherwise, <see langword="false" />.
/// </returns>
private static bool IsZeroLiteral(Expr expr)
private static bool IsZeroLiteral(Expr expr) =>
SkipParentheses(expr) is Expr.Literal { Value: 0 or 0u or 0L or 0UL };

/// <summary>
/// Removes any number of enclosing parentheses from the specified expression.
/// </summary>
/// <param name="expr">The expression to unwrap.</param>
/// <returns>
/// The expression without enclosing parentheses, or <paramref name="expr" /> if it is not in parentheses.
/// </returns>
private static Expr SkipParentheses(Expr expr)
{
while (expr is Expr.Parenthesized parenthesized)
expr = parenthesized.Expression;

return expr is Expr.Literal { Value: 0 or 0u or 0L or 0UL };
return expr;
}

/// <summary>
Expand Down