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
6 changes: 2 additions & 4 deletions src/Ramstack.ExpressionParser/Binder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ public abstract class Binder
/// <param name="isStatic">A <see cref="bool"/> indicating whether to match only static methods
/// (<see langword="true"/>) or instance methods (<see langword="false"/>).</param>
/// <returns>
/// A <see cref="MethodInfo"/> representing the matching method if found; otherwise,
/// <see langword="null"/> if no suitable method is identified.
/// A <see cref="MethodInfo"/> representing the matching method if found; otherwise, <see langword="null"/>.
/// </returns>
public abstract MethodInfo? BindToMethod(Type? type, Identifier methodName, Type[] parameterTypes, bool isStatic);

Expand All @@ -46,8 +45,7 @@ public abstract class Binder
/// <param name="isStatic">A <see cref="bool"/> indicating whether to match only static members
/// (<see langword="true"/>) or instance members (<see langword="false"/>).</param>
/// <returns>
/// A <see cref="MemberInfo"/> representing the matching member if found; otherwise,
/// <see langword="null"/> if no suitable member is identified.
/// A <see cref="MemberInfo"/> representing the matching member if found; otherwise, <see langword="null"/>.
/// </returns>
public abstract MemberInfo? BindToMember(Type? type, Identifier memberName, bool isStatic);
}
4 changes: 3 additions & 1 deletion src/Ramstack.ExpressionParser/ExpressionBuilder.Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,9 @@ private static bool IsZeroLiteral(Expr expr)

/// <summary>
/// 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 <c>-</c> is left unchanged, so <c>x - 0</c> returns
/// the enum type rather than the underlying type.
/// </summary>
/// <param name="expr">The binary expression.</param>
/// <param name="lhs">The expression of the left operand.</param>
Expand Down
15 changes: 8 additions & 7 deletions src/Ramstack.ExpressionParser/Expressions/Expr.Call.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,35 @@ namespace Ramstack.Parsing.Expressions;
partial class Expr
{
/// <summary>
/// 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.
/// </summary>
[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.")]
public sealed class Call(Expr expression, IReadOnlyList<Expr> parameters)
: Expr(ExprKind.Call, ComputeDepth(expression, parameters))
{
/// <summary>
/// Gets the expression being called, such as a method or function reference.
/// Gets the expression that specifies the method or delegate to call.
/// </summary>
/// <value>
/// An <see cref="Expr"/> representing the target of the call, e.g., <c>Math.Abs</c>.
/// An <see cref="Expr"/> representing the target of the call, such as <c>Math.Abs</c> in <c>Math.Abs(-5)</c>.
/// </value>
public Expr Expression { get; } = expression;

/// <summary>
/// Gets the list of parameters passed to the call.
/// Gets the arguments passed to the call.
/// </summary>
/// <value>
/// An <see cref="IReadOnlyList{T}"/> of <see cref="Expr"/> instances representing the arguments, e.g., <c>-5</c>.
/// An <see cref="IReadOnlyList{T}"/> of <see cref="Expr"/> instances representing the arguments,
/// such as <c>-5</c> in <c>Math.Abs(-5)</c>.
/// </value>
public IReadOnlyList<Expr> Parameters { get; } = parameters;

/// <summary>
/// Deconstructs the call expression into its target expression and parameters.
/// Deconstructs the call expression into its target expression and arguments.
/// </summary>
/// <param name="expression">The <see cref="Expr"/> representing the target of the call.</param>
/// <param name="parameters">The <see cref="IReadOnlyList{T}"/> of <see cref="Expr"/> instances representing the call’s arguments.</param>
/// <param name="parameters">The <see cref="IReadOnlyList{T}"/> of <see cref="Expr"/> instances representing the call's arguments.</param>
public void Deconstruct(out Expr expression, out IReadOnlyList<Expr> parameters) =>
(expression, parameters) = (Expression, Parameters);

Expand Down
8 changes: 4 additions & 4 deletions src/Ramstack.ExpressionParser/Expressions/Expr.Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@ public sealed class Indexer(Expr expression, IReadOnlyList<Expr> parameters)
: Expr(ExprKind.Index, ComputeDepth(expression, parameters))
{
/// <summary>
/// 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.
/// </summary>
public Expr Expression { get; } = expression;

/// <summary>
/// Gets the list of parameters used as indices or arguments for the indexing operation.
/// Gets the index arguments of the indexing operation.
/// </summary>
public IReadOnlyList<Expr> Parameters { get; } = parameters;

/// <summary>
/// Deconstructs the indexer expression into its target expression and index parameters.
/// Deconstructs the indexer expression into its target expression and index arguments.
/// </summary>
/// <param name="expression">The <see cref="Expr"/> representing the target being indexed.</param>
/// <param name="parameters">The <see cref="IReadOnlyList{T}"/> of <see cref="Expr"/> instances representing the indices.</param>
/// <param name="parameters">The <see cref="IReadOnlyList{T}"/> of <see cref="Expr"/> instances representing the index arguments.</param>
public void Deconstruct(out Expr expression, out IReadOnlyList<Expr> parameters) =>
(expression, parameters) = (Expression, Parameters);

Expand Down
14 changes: 7 additions & 7 deletions src/Ramstack.ExpressionParser/Expressions/Expr.Unary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public sealed class Unary(Identifier @operator, UnaryType unaryType, Expr operan
public Identifier Operator { get; } = @operator;

/// <summary>
/// Gets the type of the unary operation.
/// Gets the kind of the unary operation.
/// </summary>
/// <value>
/// A <see cref="UnaryType"/> value indicating the kind of operation, such as negation or conversion.
Expand All @@ -36,31 +36,31 @@ public sealed class Unary(Identifier @operator, UnaryType unaryType, Expr operan
public Expr Operand { get; } = operand;

/// <summary>
/// Deconstructs the unary expression into its type and operand.
/// Deconstructs the unary expression into its kind and operand.
/// </summary>
/// <param name="unaryType">The <see cref="UnaryType"/> of the unary operation.</param>
/// <param name="operand">The <see cref="Expr"/> on which the operation is applied.</param>
/// <example>
/// <code>
/// 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
/// </code>
/// </example>
public void Deconstruct(out UnaryType unaryType, out Expr operand) =>
(unaryType, operand) = (UnaryType, Operand);

/// <summary>
/// Deconstructs the unary expression into its operator, type, and operand.
/// Deconstructs the unary expression into its operator, kind, and operand.
/// </summary>
/// <param name="operator">The <see cref="Identifier"/> representing the unary operator.</param>
/// <param name="unaryType">The <see cref="UnaryType"/> of the unary operation.</param>
/// <param name="operand">The <see cref="Expr"/> on which the operation is applied.</param>
/// <example>
/// <code>
/// 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
/// </code>
/// </example>
public void Deconstruct(out Identifier @operator, out UnaryType unaryType, out Expr operand) =>
Expand Down
2 changes: 1 addition & 1 deletion src/Ramstack.ExpressionParser/Expressions/Expr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private static int ComputeDepth(Expr expression, IReadOnlyList<Expr> list)
/// <summary>
/// Deconstructs the expression into its kind.
/// </summary>
/// <param name="kind">The <see cref="ExprKind"/> of this expression node, output as an enumeration value.</param>
/// <param name="kind">The <see cref="ExprKind"/> of this expression node.</param>
public void Deconstruct(out ExprKind kind) =>
kind = Kind;

Expand Down
11 changes: 4 additions & 7 deletions src/Ramstack.ExpressionParser/Expressions/ExprVisitor.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
namespace Ramstack.Parsing.Expressions;

/// <summary>
/// Represents a visitor or rewriter for expression trees that produces a result of type <typeparamref name="T"/>.
/// Represents a visitor for <see cref="Expr"/> trees that produces a result of type <typeparamref name="T"/>.
/// </summary>
/// <typeparam name="T">The type of the result produced by visiting the expression tree nodes.</typeparam>
public abstract class ExprVisitor<T>
Expand All @@ -17,15 +17,12 @@ public virtual T Visit(Expr expr) =>
expr.Accept(this);

/// <summary>
/// Visits a list of expressions and returns a collection of results.
/// Visits each expression in the list in order and returns the results.
/// </summary>
/// <param name="nodes">The <see cref="IReadOnlyList{T}"/> of <see cref="Expr"/> instances to visit.</param>
/// <param name="nodes">The expressions to visit.</param>
/// <returns>
/// An <see cref="IReadOnlyList{T}"/> containing the results of type <typeparamref name="T"/> for each visited expression.
/// The results of visiting the expressions, in the same order as <paramref name="nodes"/>.
/// </returns>
/// <remarks>
/// Returns an empty list if <paramref name="nodes"/> is empty; otherwise, visits each expression in sequence.
/// </remarks>
public virtual IReadOnlyList<T> Visit(IReadOnlyList<Expr> nodes)
{
if (nodes.Count == 0)
Expand Down
4 changes: 2 additions & 2 deletions src/Ramstack.ExpressionParser/Expressions/Identifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ public sealed class Identifier(string name)
public string Name { get; } = name;

/// <summary>
/// Deconstructs the identifier into its constituent name.
/// Deconstructs the identifier into its name.
/// </summary>
/// <param name="name">The name of the identifier, output as a string.</param>
/// <param name="name">The name of the identifier.</param>
public void Deconstruct(out string name) =>
name = Name;

Expand Down
4 changes: 2 additions & 2 deletions src/Ramstack.ExpressionParser/Expressions/UnaryType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace Ramstack.Parsing.Expressions;
public enum UnaryType
{
/// <summary>
/// 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.
/// </summary>
/// <example>
/// In the expression <c>x :> int</c>, this indicates a conversion of <c>x</c> to an integer.
/// In the expression <c>x :> int</c>, this indicates a conversion of <c>x</c> to <c>int</c>.
/// </example>
Convert,

Expand Down
2 changes: 1 addition & 1 deletion src/Ramstack.ExpressionParser/Internal/Error.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Ramstack.Parsing.Internal;

/// <summary>
/// Provides helper methods for throwing exceptions during expression parsing to simplify error handling.
/// Provides helper methods for throwing exceptions during expression parsing.
/// </summary>
internal static class Error
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace Ramstack.Parsing.Internal;

/// <summary>
/// Provides reflection based extension methods.
/// Provides extension methods for the <see cref="Type"/> and <see cref="MemberInfo"/> classes.
/// </summary>
internal static class ReflectionExtensions
{
Expand Down
16 changes: 13 additions & 3 deletions src/Ramstack.ExpressionParser/Internal/TypeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,13 @@ public static class TypeUtils
/// </summary>
/// <param name="type">The <see cref="Type"/> to test.</param>
/// <returns>
/// A value indicating whether the <paramref name="type"/> is a numeric type.
/// <see langword="true" /> if <paramref name="type"/> is a numeric type; otherwise, <see langword="false" />.
/// </returns>
/// <remarks>
/// Besides the integer types checked by <see cref="IsInteger"/>, the numeric types are
/// <see cref="char"/>, <see cref="float"/>, <see cref="double"/>, and <see cref="decimal"/>.
/// Enum types are not numeric.
/// </remarks>
public static bool IsNumeric(Type type)
{
if (!type.IsEnum)
Expand Down Expand Up @@ -105,13 +110,18 @@ public static bool IsInteger(Type type)


/// <summary>
/// Determines whether the <paramref name="source"/> can convert to the <paramref name="target"/>.
/// Determines whether an implicit identity or numeric conversion exists
/// from <paramref name="source"/> to <paramref name="target"/>.
/// </summary>
/// <param name="source">The type to convert from.</param>
/// <param name="target">The type to convert to.</param>
/// <returns>
/// A value indicating whether the conversion is possible.
/// <see langword="true" /> if the conversion exists; otherwise, <see langword="false" />.
/// </returns>
/// <remarks>
/// Only primitive types, <see cref="decimal"/>, <see cref="string"/>, and <see cref="DateTime"/> are considered;
/// for other types, including enum types, the method returns <see langword="false" />.
/// </remarks>
public static bool CanConvertPrimitive(Type source, Type target)
{
//
Expand Down
12 changes: 4 additions & 8 deletions src/Ramstack.ExpressionParser/Parsers/ConstantNumberParser.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
namespace Ramstack.Parsing.Parsers;

/// <summary>
/// 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 <c>.5</c>.
/// </summary>
/// <remarks>
/// 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.
/// </remarks>
internal sealed class ConstantNumberParser : Parser<object>
{
/// <summary>
/// Gets an instance of the numeric literal parser.
/// Gets the numeric literal parser.
/// </summary>
/// <remarks>
/// This parser only matches the number itself, since the unary sign
/// is intercepted by the parser responsible for unary operations.
/// </remarks>
public static Parser<object> NumericLiteral { get; } = new ConstantNumberParser();

/// <summary>
Expand Down