diff --git a/README.md b/README.md index 5bc2566..45c558a 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/src/Ramstack.ExpressionParser/Binder.cs b/src/Ramstack.ExpressionParser/Binder.cs index 48b95ed..6ca6bfa 100644 --- a/src/Ramstack.ExpressionParser/Binder.cs +++ b/src/Ramstack.ExpressionParser/Binder.cs @@ -39,7 +39,7 @@ public abstract class Binder public abstract MethodInfo? BindToMethod(Type? type, Identifier methodName, Type[] parameterTypes, bool isStatic); /// - /// 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. /// /// The from which to select the member. /// The representing the name of the member to bind. diff --git a/src/Ramstack.ExpressionParser/ExpressionParser.Parser.cs b/src/Ramstack.ExpressionParser/ExpressionParser.Parser.cs index b2698f3..9d62834 100644 --- a/src/Ramstack.ExpressionParser/ExpressionParser.Parser.cs +++ b/src/Ramstack.ExpressionParser/ExpressionParser.Parser.cs @@ -23,7 +23,7 @@ partial class ExpressionParser /// /// 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 a + b + c counts as deeply as the nested expression ((a + b) + c). + /// so a chain such as a + b + 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. /// diff --git a/src/Ramstack.ExpressionParser/Expressions/Expr.Reference.cs b/src/Ramstack.ExpressionParser/Expressions/Expr.Reference.cs index 675145b..1650191 100644 --- a/src/Ramstack.ExpressionParser/Expressions/Expr.Reference.cs +++ b/src/Ramstack.ExpressionParser/Expressions/Expr.Reference.cs @@ -3,7 +3,7 @@ namespace Ramstack.Parsing.Expressions; partial class Expr { /// - /// 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. /// public sealed class Reference(Identifier value) : Expr(ExprKind.Reference) { diff --git a/src/Ramstack.ExpressionParser/Expressions/Expr.Unary.cs b/src/Ramstack.ExpressionParser/Expressions/Expr.Unary.cs index 7403406..6780a0b 100644 --- a/src/Ramstack.ExpressionParser/Expressions/Expr.Unary.cs +++ b/src/Ramstack.ExpressionParser/Expressions/Expr.Unary.cs @@ -6,7 +6,7 @@ partial class Expr /// Represents a unary operation expression in an expression tree, consisting of an operator and a single operand. /// /// The representing the unary operator, e.g., "-" or "int". - /// The specifying the kind of unary operation (e.g., arithmetic or conversion). + /// The specifying the kind of unary operation, such as negation or conversion. /// The on which the unary operation is applied. public sealed class Unary(Identifier @operator, UnaryType unaryType, Expr operand) : Expr(ExprKind.Unary, operand.Depth + 1) @@ -23,7 +23,7 @@ public sealed class Unary(Identifier @operator, UnaryType unaryType, Expr operan /// Gets the type of the unary operation. /// /// - /// A value indicating the nature of the operation, e.g., arithmetic or conversion. + /// A value indicating the kind of operation, such as negation or conversion. /// public UnaryType UnaryType { get; } = unaryType; @@ -42,9 +42,9 @@ public sealed class Unary(Identifier @operator, UnaryType unaryType, Expr operan /// The on which the operation is applied. /// /// - /// 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 /// /// public void Deconstruct(out UnaryType unaryType, out Expr operand) => @@ -58,9 +58,9 @@ public void Deconstruct(out UnaryType unaryType, out Expr operand) => /// The on which the operation is applied. /// /// - /// 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 /// /// public void Deconstruct(out Identifier @operator, out UnaryType unaryType, out Expr operand) => @@ -75,7 +75,7 @@ public override T Accept(ExprVisitor visitor) => /// /// - /// A string representation of the unary expression, e.g., -x for operators or x :> int for conversions. + /// A string representation of the unary expression, e.g., -(x) for operators or x :> int for conversions. /// public override string ToString() => UnaryType switch { diff --git a/src/Ramstack.ExpressionParser/Expressions/ExprKind.cs b/src/Ramstack.ExpressionParser/Expressions/ExprKind.cs index 04791ca..33a8560 100644 --- a/src/Ramstack.ExpressionParser/Expressions/ExprKind.cs +++ b/src/Ramstack.ExpressionParser/Expressions/ExprKind.cs @@ -6,10 +6,10 @@ namespace Ramstack.Parsing.Expressions; public enum ExprKind { /// - /// Represents a reference to a variable, parameter, or member in the expression. + /// Represents a reference to a type or member by its name. /// /// - /// In the expression x, this would indicate a reference to the variable "x". + /// In the expression Math.PI, Math is a reference to a type, and PI is a reference to its member. /// Reference, diff --git a/src/Ramstack.ExpressionParser/Expressions/ExprVisitor.cs b/src/Ramstack.ExpressionParser/Expressions/ExprVisitor.cs index e175271..d466a21 100644 --- a/src/Ramstack.ExpressionParser/Expressions/ExprVisitor.cs +++ b/src/Ramstack.ExpressionParser/Expressions/ExprVisitor.cs @@ -7,7 +7,7 @@ namespace Ramstack.Parsing.Expressions; public abstract class ExprVisitor { /// - /// Dispatches an expression to the appropriate specialized visit method based on its . + /// Dispatches the expression to the visit method for its node type by calling . /// /// The to visit. /// diff --git a/src/Ramstack.ExpressionParser/Internal/MethodResolver.cs b/src/Ramstack.ExpressionParser/Internal/MethodResolver.cs index 75d3a43..24db1b7 100644 --- a/src/Ramstack.ExpressionParser/Internal/MethodResolver.cs +++ b/src/Ramstack.ExpressionParser/Internal/MethodResolver.cs @@ -15,13 +15,13 @@ namespace Ramstack.Parsing.Internal; internal static class MethodResolver { /// - /// 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. /// - /// An array of methods representing the candidates for matching. + /// The candidate methods. /// The argument types used to locate a matching method. /// - /// The resolved if a matching method is found; otherwise, . + /// The method that best matches the argument types, or if no candidate + /// accepts the argument types or several candidates match them equally well. /// public static MethodBase? ResolveMethod(IReadOnlyList match, Type[] argumentTypes) { diff --git a/src/Ramstack.ExpressionParser/Internal/ReflectionExtensions.cs b/src/Ramstack.ExpressionParser/Internal/ReflectionExtensions.cs index 300f4bd..68637f6 100644 --- a/src/Ramstack.ExpressionParser/Internal/ReflectionExtensions.cs +++ b/src/Ramstack.ExpressionParser/Internal/ReflectionExtensions.cs @@ -64,9 +64,6 @@ public static bool IsStatic(this Type type) => /// For types (including nested types), checks whether the type is static using . /// /// - /// - /// Thrown when the member type is unsupported or cannot be evaluated for static declaration. - /// public static bool IsStatic(this MemberInfo memberInfo) { bool result; @@ -109,7 +106,7 @@ public static bool IsStatic(this MemberInfo memberInfo) } /// - /// Determines the runtime type associated with the specified member. + /// Determines the type associated with the specified member. /// /// The instance representing the member to evaluate. /// @@ -123,9 +120,6 @@ public static bool IsStatic(this MemberInfo memberInfo) /// If the member is a type, returns the itself. /// /// - /// - /// Thrown when the member type is unsupported or the runtime type cannot be determined. - /// public static Type GetMemberType(this MemberInfo memberInfo) { return memberInfo.MemberType switch diff --git a/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs b/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs index 1de8c64..a0a4ec8 100644 --- a/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs +++ b/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs @@ -132,12 +132,13 @@ public static bool CanConvertPrimitive(Type source, Type target) } /// - /// Attempts to find an implicit conversion operator. + /// Attempts to find an implicit conversion operator declared in the source type. /// /// The type to convert from. /// The type to convert to. /// - /// The conversion operator. + /// The conversion operator, or if does not declare + /// an implicit conversion to . /// public static MethodInfo? FindConversionOperator(Type source, Type target) {