aspclassic-core/AspClassic.Parser/ComparisonCaseClause.cs
Jelle Luteijn 484dbfc9d9 progress
2022-05-15 11:19:49 +02:00

69 lines
2 KiB
C#

using System;
using System.Collections.Generic;
namespace AspClassic.Parser;
/// <summary>
/// A parse tree for a case clause that compares values.
/// </summary>
public sealed class ComparisonCaseClause : CaseClause
{
private readonly Location _IsLocation;
private readonly OperatorType _ComparisonOperator;
private readonly Location _OperatorLocation;
private readonly Expression _Operand;
/// <summary>
/// The location of the 'Is', if any.
/// </summary>
public Location IsLocation => _IsLocation;
/// <summary>
/// The comparison operator used in the case clause.
/// </summary>
public OperatorType ComparisonOperator => _ComparisonOperator;
/// <summary>
/// The location of the comparison operator.
/// </summary>
public Location OperatorLocation => _OperatorLocation;
/// <summary>
/// The operand of the case clause.
/// </summary>
public Expression Operand => _Operand;
/// <summary>
/// Constructs a new parse tree for a comparison case clause.
/// </summary>
/// <param name="isLocation">The location of the 'Is', if any.</param>
/// <param name="comparisonOperator">The comparison operator used.</param>
/// <param name="operatorLocation">The location of the comparison operator.</param>
/// <param name="operand">The operand of the comparison.</param>
/// <param name="span">The location of the parse tree.</param>
public ComparisonCaseClause(Location isLocation, OperatorType comparisonOperator, Location operatorLocation, Expression operand, Span span)
: base(TreeType.ComparisonCaseClause, span)
{
if (operand == null)
{
throw new ArgumentNullException("operand");
}
if (comparisonOperator < OperatorType.Equals || comparisonOperator > OperatorType.GreaterThanEquals)
{
throw new ArgumentOutOfRangeException("comparisonOperator");
}
SetParent(operand);
_IsLocation = isLocation;
_ComparisonOperator = comparisonOperator;
_OperatorLocation = operatorLocation;
_Operand = operand;
}
protected override void GetChildTrees(IList<Tree> childList)
{
Tree.AddChild(childList, Operand);
}
}