33
44namespace SqlServerSimulator . Parser ;
55
6+ /// <summary>
7+ /// Contains the logic described by a SQL command and computes its results.
8+ /// </summary>
69internal abstract class Expression
710{
811 private protected Expression ( )
912 {
1013 }
1114
15+ /// <summary>
16+ /// A name or alias associated with an expression.
17+ /// Anonymous expressions return <see cref="string.Empty"/>.
18+ /// </summary>
1219 public virtual string Name => string . Empty ;
1320
21+ /// <summary>
22+ /// Converts the tokens from a command into a single expression.
23+ /// </summary>
24+ /// <param name="simulation">Simulation shared context.</param>
25+ /// <param name="tokens">The sequence of command tokens. This will be advanced to the end of the expression.</param>
26+ /// <param name="token">Retains the most recently provided token from <paramref name="tokens"/>.</param>
27+ /// <param name="getVariableValue">Provides the value to any variable included alongside the command.</param>
28+ /// <returns>The parsed expression.</returns>
29+ /// <exception cref="SimulatedSqlException">A variety of messages are possible for various problems with the command.</exception>
30+ /// <exception cref="NotSupportedException">A condition was encountered that may be valid but can't currently be parsed.</exception>
1431 public static Expression Parse ( Simulation simulation , IEnumerator < Token > tokens , ref Token ? token , Func < string , object ? > getVariableValue )
1532 {
1633 Expression ? expression = null ;
@@ -131,6 +148,11 @@ public static Expression Parse(Simulation simulation, IEnumerator<Token> tokens,
131148 return expression ;
132149 }
133150
151+ /// <summary>
152+ /// Runs the expression, returning its result.
153+ /// </summary>
154+ /// <param name="getColumnValue">Provides the value for a column.</param>
155+ /// <returns>The result of the expression.</returns>
134156 public abstract object ? Run ( Func < List < string > , object ? > getColumnValue ) ;
135157
136158#if DEBUG
@@ -144,6 +166,11 @@ public static Expression Parse(Simulation simulation, IEnumerator<Token> tokens,
144166 new ( "abs" , ( simulation , tokens , ref token , getVariableValue ) => new AbsoluteValue( Expression . Parse ( simulation , tokens , ref token , getVariableValue ) ) ) ,
145167 ] ) ;
146168
169+ /// <summary>
170+ /// An expression that has been given a name, such as with `as`.
171+ /// </summary>
172+ /// <param name="expression">The expression to be named.</param>
173+ /// <param name="name">The name of the expression, exposed via the <see cref="Name"/> property.</param>
147174 private sealed class NamedExpression ( Expression expression , string name ) : Expression
148175 {
149176 private readonly Expression expression = expression ;
@@ -156,13 +183,11 @@ private sealed class NamedExpression(Expression expression, string name) : Expre
156183
157184 public override object ? Run ( Func < List < string > , object ? > getColumnValue ) => this . expression . Run ( getColumnValue ) ;
158185
159- #if DEBUG
160186 /// <summary>
161187 /// Transfers the name to an outer expression.
162188 /// </summary>
163189 /// <param name="destination">The expression wrapping this<see cref="NamedExpression"/>.</param>
164190 /// <returns>A new <see cref="NamedExpression"/> wrapping <paramref name="destination"/> using <see cref="Name"/>.</returns>
165- #endif
166191 public NamedExpression TransferName ( Expression destination )
167192 {
168193#if DEBUG
@@ -268,6 +293,10 @@ public sealed class Reference(Name name) : Expression
268293#endif
269294 }
270295
296+ /// <summary>
297+ /// Encapsulates the SQL DATALENGTH command: https://learn.microsoft.com/en-us/sql/t-sql/functions/datalength-transact-sql
298+ /// </summary>
299+ /// <param name="source">Provides the value to be processed.</param>
271300 public sealed class DataLength ( Expression source ) : Expression
272301 {
273302 private readonly Expression source = source ;
@@ -284,6 +313,10 @@ public sealed class DataLength(Expression source) : Expression
284313#endif
285314 }
286315
316+ /// <summary>
317+ /// Encapsulates the SQL ABS command: https://learn.microsoft.com/en-us/sql/t-sql/functions/abs-transact-sql
318+ /// </summary>
319+ /// <param name="source">Provides the value to be processed.</param>
287320 public sealed class AbsoluteValue ( Expression source ) : Expression
288321 {
289322 private readonly Expression source = source ;
0 commit comments