Table of Contents

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

IReadOnlyList<string>

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 int

The starting character index where the error is present

endChar int

The ending character index where the error is present

message string

The 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

bool

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

bool

ExpectOperator(OperatorToken, string)

Assert/validate that the correct operator was used

public bool ExpectOperator(OperatorToken op, string expectedOp)

Parameters

op OperatorToken

The operator to

expectedOp string

The expected operator

Returns

bool

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 T

The expected type

Returns

bool