From a1ff657483920fc2b5fe16772e9e362614b5e222 Mon Sep 17 00:00:00 2001 From: rameel Date: Thu, 19 Nov 2026 15:24:37 +0500 Subject: [PATCH] docs: clarify imprecise XML comments Several XML comments were vague or imprecise: - Expr.Call and Expr.Indexer called their arguments parameters, and Expr.Call described its target as a function reference. The examples now show the arguments in context, as in Math.Abs(-5). - Expr.Unary.UnaryType was described as the type of the operation, which is easy to confuse with the target type of a conversion. - ExprVisitor was described as a rewriter, and the comments of Visit(IReadOnlyList) referred to IReadOnlyList{T}, which inside ExprVisitor reads as a list of T. - UnaryType.Convert did not say that the conversion is explicit. - ConstantNumberParser claimed to follow the C# syntax, although it does not support digit separators or real literals that start with a decimal point, such as .5. - TypeUtils.IsNumeric and CanConvertPrimitive did not say which types they accept, and ApplyEnumZeroConversion did not mention that x - 0 keeps the enum type. It also removes filler words and repetitions, and starts the ReflectionExtensions summary with "Provides extension methods for". Co-Authored-By: Claude Opus 5.5 --- src/Ramstack.ExpressionParser/Binder.cs | 6 ++---- .../ExpressionBuilder.Helpers.cs | 4 +++- .../Expressions/Expr.Call.cs | 15 ++++++++------- .../Expressions/Expr.Index.cs | 8 ++++---- .../Expressions/Expr.Unary.cs | 14 +++++++------- .../Expressions/Expr.cs | 2 +- .../Expressions/ExprVisitor.cs | 11 ++++------- .../Expressions/Identifier.cs | 4 ++-- .../Expressions/UnaryType.cs | 4 ++-- src/Ramstack.ExpressionParser/Internal/Error.cs | 2 +- .../Internal/ReflectionExtensions.cs | 2 +- .../Internal/TypeUtils.cs | 16 +++++++++++++--- .../Parsers/ConstantNumberParser.cs | 12 ++++-------- 13 files changed, 52 insertions(+), 48 deletions(-) diff --git a/src/Ramstack.ExpressionParser/Binder.cs b/src/Ramstack.ExpressionParser/Binder.cs index 6ca6bfa..eb49e26 100644 --- a/src/Ramstack.ExpressionParser/Binder.cs +++ b/src/Ramstack.ExpressionParser/Binder.cs @@ -33,8 +33,7 @@ public abstract class Binder /// A indicating whether to match only static methods /// () or instance methods (). /// - /// A representing the matching method if found; otherwise, - /// if no suitable method is identified. + /// A representing the matching method if found; otherwise, . /// public abstract MethodInfo? BindToMethod(Type? type, Identifier methodName, Type[] parameterTypes, bool isStatic); @@ -46,8 +45,7 @@ public abstract class Binder /// A indicating whether to match only static members /// () or instance members (). /// - /// A representing the matching member if found; otherwise, - /// if no suitable member is identified. + /// A representing the matching member if found; otherwise, . /// public abstract MemberInfo? BindToMember(Type? type, Identifier memberName, bool isStatic); } diff --git a/src/Ramstack.ExpressionParser/ExpressionBuilder.Helpers.cs b/src/Ramstack.ExpressionParser/ExpressionBuilder.Helpers.cs index a53fb8c..2b7e270 100644 --- a/src/Ramstack.ExpressionParser/ExpressionBuilder.Helpers.cs +++ b/src/Ramstack.ExpressionParser/ExpressionBuilder.Helpers.cs @@ -251,7 +251,9 @@ private static bool IsZeroLiteral(Expr expr) /// /// Converts the integer literal 0 opposite an operand of an enum type to that enum type - /// if the operator is defined for two operands of the enum type. + /// if the operator is defined for two operands of the enum type. As in the C# compiler, a literal + /// of the underlying type on the right of - is left unchanged, so x - 0 returns + /// the enum type rather than the underlying type. /// /// The binary expression. /// The expression of the left operand. diff --git a/src/Ramstack.ExpressionParser/Expressions/Expr.Call.cs b/src/Ramstack.ExpressionParser/Expressions/Expr.Call.cs index 81282c7..7239e13 100644 --- a/src/Ramstack.ExpressionParser/Expressions/Expr.Call.cs +++ b/src/Ramstack.ExpressionParser/Expressions/Expr.Call.cs @@ -3,7 +3,7 @@ namespace Ramstack.Parsing.Expressions; partial class Expr { /// - /// Represents a method call expression in an expression tree, consisting of a target expression and its parameters. + /// Represents a method or delegate call in an expression tree, consisting of a target expression and its arguments. /// [SuppressMessage("Naming", "CA1716:Identifiers should not match keywords", Justification = "The type is named after the ExprKind.Call expression kind, and renaming it would break the public API.")] @@ -11,26 +11,27 @@ public sealed class Call(Expr expression, IReadOnlyList parameters) : Expr(ExprKind.Call, ComputeDepth(expression, parameters)) { /// - /// Gets the expression being called, such as a method or function reference. + /// Gets the expression that specifies the method or delegate to call. /// /// - /// An representing the target of the call, e.g., Math.Abs. + /// An representing the target of the call, such as Math.Abs in Math.Abs(-5). /// public Expr Expression { get; } = expression; /// - /// Gets the list of parameters passed to the call. + /// Gets the arguments passed to the call. /// /// - /// An of instances representing the arguments, e.g., -5. + /// An of instances representing the arguments, + /// such as -5 in Math.Abs(-5). /// public IReadOnlyList Parameters { get; } = parameters; /// - /// Deconstructs the call expression into its target expression and parameters. + /// Deconstructs the call expression into its target expression and arguments. /// /// The representing the target of the call. - /// The of instances representing the call’s arguments. + /// The of instances representing the call's arguments. public void Deconstruct(out Expr expression, out IReadOnlyList parameters) => (expression, parameters) = (Expression, Parameters); diff --git a/src/Ramstack.ExpressionParser/Expressions/Expr.Index.cs b/src/Ramstack.ExpressionParser/Expressions/Expr.Index.cs index 810b30a..e8f523c 100644 --- a/src/Ramstack.ExpressionParser/Expressions/Expr.Index.cs +++ b/src/Ramstack.ExpressionParser/Expressions/Expr.Index.cs @@ -9,20 +9,20 @@ public sealed class Indexer(Expr expression, IReadOnlyList parameters) : Expr(ExprKind.Index, ComputeDepth(expression, parameters)) { /// - /// Gets the expression being indexed, such as an array or object with an indexer. + /// Gets the expression being indexed, such as an array or an object with an indexer. /// public Expr Expression { get; } = expression; /// - /// Gets the list of parameters used as indices or arguments for the indexing operation. + /// Gets the index arguments of the indexing operation. /// public IReadOnlyList Parameters { get; } = parameters; /// - /// Deconstructs the indexer expression into its target expression and index parameters. + /// Deconstructs the indexer expression into its target expression and index arguments. /// /// The representing the target being indexed. - /// The of instances representing the indices. + /// The of instances representing the index arguments. public void Deconstruct(out Expr expression, out IReadOnlyList parameters) => (expression, parameters) = (Expression, Parameters); diff --git a/src/Ramstack.ExpressionParser/Expressions/Expr.Unary.cs b/src/Ramstack.ExpressionParser/Expressions/Expr.Unary.cs index 6780a0b..33180db 100644 --- a/src/Ramstack.ExpressionParser/Expressions/Expr.Unary.cs +++ b/src/Ramstack.ExpressionParser/Expressions/Expr.Unary.cs @@ -20,7 +20,7 @@ public sealed class Unary(Identifier @operator, UnaryType unaryType, Expr operan public Identifier Operator { get; } = @operator; /// - /// Gets the type of the unary operation. + /// Gets the kind of the unary operation. /// /// /// A value indicating the kind of operation, such as negation or conversion. @@ -36,22 +36,22 @@ public sealed class Unary(Identifier @operator, UnaryType unaryType, Expr operan public Expr Operand { get; } = operand; /// - /// Deconstructs the unary expression into its type and operand. + /// Deconstructs the unary expression into its kind and operand. /// /// The of the unary operation. /// The on which the operation is applied. /// /// /// 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 + /// var (kind, operand) = unary; + /// // kind is UnaryType.Negate, operand is the reference to x /// /// public void Deconstruct(out UnaryType unaryType, out Expr operand) => (unaryType, operand) = (UnaryType, Operand); /// - /// Deconstructs the unary expression into its operator, type, and operand. + /// Deconstructs the unary expression into its operator, kind, and operand. /// /// The representing the unary operator. /// The of the unary operation. @@ -59,8 +59,8 @@ public void Deconstruct(out UnaryType unaryType, out Expr operand) => /// /// /// 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 + /// var (op, kind, operand) = unary; + /// // op.Name is "-", kind is UnaryType.Negate, operand is the reference to x /// /// public void Deconstruct(out Identifier @operator, out UnaryType unaryType, out Expr operand) => diff --git a/src/Ramstack.ExpressionParser/Expressions/Expr.cs b/src/Ramstack.ExpressionParser/Expressions/Expr.cs index 50294f8..285fede 100644 --- a/src/Ramstack.ExpressionParser/Expressions/Expr.cs +++ b/src/Ramstack.ExpressionParser/Expressions/Expr.cs @@ -55,7 +55,7 @@ private static int ComputeDepth(Expr expression, IReadOnlyList list) /// /// Deconstructs the expression into its kind. /// - /// The of this expression node, output as an enumeration value. + /// The of this expression node. public void Deconstruct(out ExprKind kind) => kind = Kind; diff --git a/src/Ramstack.ExpressionParser/Expressions/ExprVisitor.cs b/src/Ramstack.ExpressionParser/Expressions/ExprVisitor.cs index d466a21..102f857 100644 --- a/src/Ramstack.ExpressionParser/Expressions/ExprVisitor.cs +++ b/src/Ramstack.ExpressionParser/Expressions/ExprVisitor.cs @@ -1,7 +1,7 @@ namespace Ramstack.Parsing.Expressions; /// -/// Represents a visitor or rewriter for expression trees that produces a result of type . +/// Represents a visitor for trees that produces a result of type . /// /// The type of the result produced by visiting the expression tree nodes. public abstract class ExprVisitor @@ -17,15 +17,12 @@ public virtual T Visit(Expr expr) => expr.Accept(this); /// - /// Visits a list of expressions and returns a collection of results. + /// Visits each expression in the list in order and returns the results. /// - /// The of instances to visit. + /// The expressions to visit. /// - /// An containing the results of type for each visited expression. + /// The results of visiting the expressions, in the same order as . /// - /// - /// Returns an empty list if is empty; otherwise, visits each expression in sequence. - /// public virtual IReadOnlyList Visit(IReadOnlyList nodes) { if (nodes.Count == 0) diff --git a/src/Ramstack.ExpressionParser/Expressions/Identifier.cs b/src/Ramstack.ExpressionParser/Expressions/Identifier.cs index d930c19..cc0736f 100644 --- a/src/Ramstack.ExpressionParser/Expressions/Identifier.cs +++ b/src/Ramstack.ExpressionParser/Expressions/Identifier.cs @@ -11,9 +11,9 @@ public sealed class Identifier(string name) public string Name { get; } = name; /// - /// Deconstructs the identifier into its constituent name. + /// Deconstructs the identifier into its name. /// - /// The name of the identifier, output as a string. + /// The name of the identifier. public void Deconstruct(out string name) => name = Name; diff --git a/src/Ramstack.ExpressionParser/Expressions/UnaryType.cs b/src/Ramstack.ExpressionParser/Expressions/UnaryType.cs index 08d3ca1..cf400cc 100644 --- a/src/Ramstack.ExpressionParser/Expressions/UnaryType.cs +++ b/src/Ramstack.ExpressionParser/Expressions/UnaryType.cs @@ -6,10 +6,10 @@ namespace Ramstack.Parsing.Expressions; public enum UnaryType { /// - /// Represents a type cast or conversion operation, such as converting a value to a specific type. + /// Represents an explicit conversion of the operand to a type. /// /// - /// In the expression x :> int, this indicates a conversion of x to an integer. + /// In the expression x :> int, this indicates a conversion of x to int. /// Convert, diff --git a/src/Ramstack.ExpressionParser/Internal/Error.cs b/src/Ramstack.ExpressionParser/Internal/Error.cs index 59d1722..08f15ae 100644 --- a/src/Ramstack.ExpressionParser/Internal/Error.cs +++ b/src/Ramstack.ExpressionParser/Internal/Error.cs @@ -3,7 +3,7 @@ namespace Ramstack.Parsing.Internal; /// -/// Provides helper methods for throwing exceptions during expression parsing to simplify error handling. +/// Provides helper methods for throwing exceptions during expression parsing. /// internal static class Error { diff --git a/src/Ramstack.ExpressionParser/Internal/ReflectionExtensions.cs b/src/Ramstack.ExpressionParser/Internal/ReflectionExtensions.cs index 5c93fd2..4d1f240 100644 --- a/src/Ramstack.ExpressionParser/Internal/ReflectionExtensions.cs +++ b/src/Ramstack.ExpressionParser/Internal/ReflectionExtensions.cs @@ -3,7 +3,7 @@ namespace Ramstack.Parsing.Internal; /// -/// Provides reflection based extension methods. +/// Provides extension methods for the and classes. /// internal static class ReflectionExtensions { diff --git a/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs b/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs index a0a4ec8..bb62f47 100644 --- a/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs +++ b/src/Ramstack.ExpressionParser/Internal/TypeUtils.cs @@ -35,8 +35,13 @@ public static class TypeUtils /// /// The to test. /// - /// A value indicating whether the is a numeric type. + /// if is a numeric type; otherwise, . /// + /// + /// Besides the integer types checked by , the numeric types are + /// , , , and . + /// Enum types are not numeric. + /// public static bool IsNumeric(Type type) { if (!type.IsEnum) @@ -105,13 +110,18 @@ public static bool IsInteger(Type type) /// - /// Determines whether the can convert to the . + /// Determines whether an implicit identity or numeric conversion exists + /// from to . /// /// The type to convert from. /// The type to convert to. /// - /// A value indicating whether the conversion is possible. + /// if the conversion exists; otherwise, . /// + /// + /// Only primitive types, , , and are considered; + /// for other types, including enum types, the method returns . + /// public static bool CanConvertPrimitive(Type source, Type target) { // diff --git a/src/Ramstack.ExpressionParser/Parsers/ConstantNumberParser.cs b/src/Ramstack.ExpressionParser/Parsers/ConstantNumberParser.cs index 402736d..b9d6e32 100644 --- a/src/Ramstack.ExpressionParser/Parsers/ConstantNumberParser.cs +++ b/src/Ramstack.ExpressionParser/Parsers/ConstantNumberParser.cs @@ -1,21 +1,17 @@ namespace Ramstack.Parsing.Parsers; /// -/// Represents a parser for numeric literals following C# syntax rules. +/// Represents a parser for numeric literals in C# syntax, except for digit separators +/// and real literals that start with a decimal point, such as .5. /// /// -/// This parser only matches the number itself, since the unary sign -/// is intercepted by the parser responsible for unary operations. +/// This parser matches only the number itself; a leading sign is parsed as a unary operator. /// internal sealed class ConstantNumberParser : Parser { /// - /// Gets an instance of the numeric literal parser. + /// Gets the numeric literal parser. /// - /// - /// This parser only matches the number itself, since the unary sign - /// is intercepted by the parser responsible for unary operations. - /// public static Parser NumericLiteral { get; } = new ConstantNumberParser(); ///