Class ExpressionValidator<T>
- Namespace
- RandomizerCore.StringParsing
- Assembly
- RandomizerCore.dll
Provides typing validation and error aggregation for IExpression<T>s
public class ExpressionValidator<T>
Type Parameters
T
- Inheritance
-
ExpressionValidator<T>
- Inherited Members
Properties
Errors
public IReadOnlyList<string> Errors { get; }
Property Value
Methods
Expect(Func<bool>, int, int, string)
Assert/validate a custom condition holds.
public bool Expect(Func<bool> predicate, int startChar, int endChar, string message)
Parameters
predicate
Func<bool>The condition to evaluate
startChar
intThe starting character index where the error is present
endChar
intThe ending character index where the error is present
message
stringThe error message
Returns
- bool
Whether the condition was met (i.e. the result of predicate)
ExpectAllParallel(params Func<bool>[])
Performs multiple expectations in parallel - if one expectation fails then this expectation will fail, but will not short-circuit. Useful for expectations not dependent on each other, ie given 2 rules A and B, both A and B can independently produce useful error messages.
public bool ExpectAllParallel(params Func<bool>[] predicates)
Parameters
predicates
Func<bool>[]A group of expectations to evaluate. Technically this can be any producer but it's generally expected for them to be wrappers for calls to Expect*.
Returns
ExpectAllSequential(params Func<bool>[])
Performs a series of expectations in series - if one expectation fails then this expectation will fail and short-circuit. Useful for expectations dependent on each other, ie given 2 rules A and B, B's error message is not useful if A fails.
public bool ExpectAllSequential(params Func<bool>[] predicates)
Parameters
predicates
Func<bool>[]A group of expectations to evaluate. Technically this can be any producer but it's generally expected for them to be wrappers for calls to Expect* or calls to Validate(ExpressionValidator<T>)
Returns
ExpectOperator(OperatorToken, string)
Assert/validate that the correct operator was used
public bool ExpectOperator(OperatorToken op, string expectedOp)
Parameters
op
OperatorTokenThe operator to
expectedOp
stringThe expected operator
Returns
ExpectType(IExpression<T>, T)
Assert/validate that an expression evaluates to the expected type
public bool ExpectType(IExpression<T> expression, T expectedType)
Parameters
expression
IExpression<T>The expression to check
expectedType
TThe expected type