Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ replace `x:int` with `x :> int`.
### Limits

An expression tree can be at most 256 levels deep. Each operator, member access, call, indexer,
and pair of parentheses adds a level, so `a + b + c` counts as deeply as `((a + b) + c)`.
and pair of parentheses adds a level, so a chain such as `a + b + c` gets one level deeper with each operator.
Parsing fails with an error rather than crashing the process when an expression is deeper than that,
or when it is nested too deeply to fit on the stack of the current thread.

Expand Down
2 changes: 1 addition & 1 deletion src/Ramstack.ExpressionParser/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public abstract class Binder
public abstract MethodInfo? BindToMethod(Type? type, Identifier methodName, Type[] parameterTypes, bool isStatic);

/// <summary>
/// Attempts to bind to a member (field, property, or method) based on the specified type and member name.
/// Attempts to bind to a member (field or property) based on the specified type and member name.
/// </summary>
/// <param name="type">The <see cref="Type"/> from which to select the member.</param>
/// <param name="memberName">The <see cref="Identifier"/> representing the name of the member to bind.</param>
Expand Down
2 changes: 1 addition & 1 deletion src/Ramstack.ExpressionParser/ExpressionParser.Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ partial class ExpressionParser
/// <remarks>
/// Parsing stops with a fatal error if the expression tree is deeper than 256 levels.
/// Each operator, member access, call, indexer, and pair of parentheses adds a level,
/// so a chain such as <c>a + b + c</c> counts as deeply as the nested expression <c>((a + b) + c)</c>.
/// so a chain such as <c>a + b + c</c> gets one level deeper with each operator.
/// Parsing also stops with a fatal error if the thread's stack runs short. On a small stack, this can happen
/// before the limit is reached for deeply nested parentheses, arguments, indexers, and conditional expressions.
/// </remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Ramstack.Parsing.Expressions;
partial class Expr
{
/// <summary>
/// Represents a reference to a variable, parameter, or member in an expression tree.
/// Represents a reference to a type or member by its name in an expression tree.
/// </summary>
public sealed class Reference(Identifier value) : Expr(ExprKind.Reference)
{
Expand Down
18 changes: 9 additions & 9 deletions src/Ramstack.ExpressionParser/Expressions/Expr.Unary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ partial class Expr
/// Represents a unary operation expression in an expression tree, consisting of an operator and a single operand.
/// </summary>
/// <param name="operator">The <see cref="Identifier"/> representing the unary operator, e.g., <c>"-"</c> or <c>"int"</c>.</param>
/// <param name="unaryType">The <see cref="UnaryType"/> specifying the kind of unary operation (e.g., arithmetic or conversion).</param>
/// <param name="unaryType">The <see cref="UnaryType"/> specifying the kind of unary operation, such as negation or conversion.</param>
/// <param name="operand">The <see cref="Expr"/> on which the unary operation is applied.</param>
public sealed class Unary(Identifier @operator, UnaryType unaryType, Expr operand)
: Expr(ExprKind.Unary, operand.Depth + 1)
Expand All @@ -23,7 +23,7 @@ public sealed class Unary(Identifier @operator, UnaryType unaryType, Expr operan
/// Gets the type of the unary operation.
/// </summary>
/// <value>
/// A <see cref="UnaryType"/> value indicating the nature of the operation, e.g., arithmetic or conversion.
/// A <see cref="UnaryType"/> value indicating the kind of operation, such as negation or conversion.
/// </value>
public UnaryType UnaryType { get; } = unaryType;

Expand All @@ -42,9 +42,9 @@ public sealed class Unary(Identifier @operator, UnaryType unaryType, Expr operan
/// <param name="operand">The <see cref="Expr"/> on which the operation is applied.</param>
/// <example>
/// <code>
/// var unary = new Unary(new Identifier("-"), UnaryType.Arithmetic, new Identifier("x"));
/// unary.Deconstruct(out UnaryType type, out Expr op);
/// // type is UnaryType.Arithmetic, op is Identifier("x")
/// var unary = new Expr.Unary(new Identifier("-"), UnaryType.Negate, new Expr.Reference(new Identifier("x")));
/// var (type, operand) = unary;
/// // type is UnaryType.Negate, operand is the reference to x
/// </code>
/// </example>
public void Deconstruct(out UnaryType unaryType, out Expr operand) =>
Expand All @@ -58,9 +58,9 @@ public void Deconstruct(out UnaryType unaryType, out Expr operand) =>
/// <param name="operand">The <see cref="Expr"/> on which the operation is applied.</param>
/// <example>
/// <code>
/// var unary = new Unary(new Identifier("-"), UnaryType.Arithmetic, new Identifier("x"));
/// unary.Deconstruct(out Identifier op, out UnaryType type, out Expr operand);
/// // op.Name is "-", type is UnaryType.Arithmetic, operand is Identifier("x")
/// var unary = new Expr.Unary(new Identifier("-"), UnaryType.Negate, new Expr.Reference(new Identifier("x")));
/// var (op, type, operand) = unary;
/// // op.Name is "-", type is UnaryType.Negate, operand is the reference to x
/// </code>
/// </example>
public void Deconstruct(out Identifier @operator, out UnaryType unaryType, out Expr operand) =>
Expand All @@ -75,7 +75,7 @@ public override T Accept<T>(ExprVisitor<T> visitor) =>

/// <inheritdoc />
/// <returns>
/// A string representation of the unary expression, e.g., <c>-x</c> for operators or <c>x :> int</c> for conversions.
/// A string representation of the unary expression, e.g., <c>-(x)</c> for operators or <c>x :> int</c> for conversions.
/// </returns>
public override string ToString() => UnaryType switch
{
Expand Down
4 changes: 2 additions & 2 deletions src/Ramstack.ExpressionParser/Expressions/ExprKind.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace Ramstack.Parsing.Expressions;
public enum ExprKind
{
/// <summary>
/// Represents a reference to a variable, parameter, or member in the expression.
/// Represents a reference to a type or member by its name.
/// </summary>
/// <example>
/// In the expression <c>x</c>, this would indicate a reference to the variable "x".
/// In the expression <c>Math.PI</c>, <c>Math</c> is a reference to a type, and <c>PI</c> is a reference to its member.
/// </example>
Reference,

Expand Down
2 changes: 1 addition & 1 deletion src/Ramstack.ExpressionParser/Expressions/ExprVisitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Ramstack.Parsing.Expressions;
public abstract class ExprVisitor<T>
{
/// <summary>
/// Dispatches an expression to the appropriate specialized visit method based on its <see cref="Expr.Kind"/>.
/// Dispatches the expression to the visit method for its node type by calling <see cref="Expr.Accept{T}"/>.
/// </summary>
/// <param name="expr">The <see cref="Expr"/> to visit.</param>
/// <returns>
Expand Down
8 changes: 4 additions & 4 deletions src/Ramstack.ExpressionParser/Internal/MethodResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ namespace Ramstack.Parsing.Internal;
internal static class MethodResolver
{
/// <summary>
/// Resolves the most appropriate method from the provided array of methods
/// that matches the specified parameter types.
/// Resolves the method from the specified candidates that best matches the specified argument types.
/// </summary>
/// <param name="match">An array of methods representing the candidates for matching.</param>
/// <param name="match">The candidate methods.</param>
/// <param name="argumentTypes">The argument types used to locate a matching method.</param>
/// <returns>
/// The resolved <see cref="MethodInfo"/> if a matching method is found; otherwise, <see langword="null" />.
/// The method that best matches the argument types, or <see langword="null" /> if no candidate
/// accepts the argument types or several candidates match them equally well.
/// </returns>
public static MethodBase? ResolveMethod(IReadOnlyList<MethodBase> match, Type[] argumentTypes)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ public static bool IsStatic(this Type type) =>
/// <item><description>For types (including nested types), checks whether the type is static using <see cref="IsStatic(Type)"/>.</description></item>
/// </list>
/// </returns>
/// <exception cref="ArgumentException">
/// Thrown when the member type is unsupported or cannot be evaluated for static declaration.
/// </exception>
public static bool IsStatic(this MemberInfo memberInfo)
{
bool result;
Expand Down Expand Up @@ -109,7 +106,7 @@ public static bool IsStatic(this MemberInfo memberInfo)
}

/// <summary>
/// Determines the runtime type associated with the specified member.
/// Determines the type associated with the specified member.
/// </summary>
/// <param name="memberInfo">The <see cref="MemberInfo"/> instance representing the member to evaluate.</param>
/// <returns>
Expand All @@ -123,9 +120,6 @@ public static bool IsStatic(this MemberInfo memberInfo)
/// <item><description>If the member is a type, returns the <see cref="Type"/> itself.</description></item>
/// </list>
/// </returns>
/// <exception cref="ArgumentException">
/// Thrown when the member type is unsupported or the runtime type cannot be determined.
/// </exception>
public static Type GetMemberType(this MemberInfo memberInfo)
{
return memberInfo.MemberType switch
Expand Down
5 changes: 3 additions & 2 deletions src/Ramstack.ExpressionParser/Internal/TypeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,13 @@ public static bool CanConvertPrimitive(Type source, Type target)
}

/// <summary>
/// Attempts to find an implicit conversion operator.
/// Attempts to find an implicit conversion operator declared in the source type.
/// </summary>
/// <param name="source">The type to convert from.</param>
/// <param name="target">The type to convert to.</param>
/// <returns>
/// The conversion operator.
/// The conversion operator, or <see langword="null" /> if <paramref name="source"/> does not declare
/// an implicit conversion to <paramref name="target"/>.
/// </returns>
public static MethodInfo? FindConversionOperator(Type source, Type target)
{
Expand Down