splitAccordingToSemanticValidity method

Pair<ATNConfigSet, ATNConfigSet> splitAccordingToSemanticValidity(
  1. ATNConfigSet configs,
  2. ParserRuleContext outerContext
)

Walk the list of configurations and split them according to those that have preds evaluating to true/false. If no pred, assume true pred and include in succeeded set. Returns Pair of sets.

Create a new set so as not to alter the incoming parameter.

Assumption: the input stream has been restored to the starting point prediction, which is where predicates need to evaluate.

Implementation

Pair<ATNConfigSet, ATNConfigSet> splitAccordingToSemanticValidity(
  ATNConfigSet configs,
  ParserRuleContext outerContext,
) {
  final succeeded = ATNConfigSet(configs.fullCtx);
  final failed = ATNConfigSet(configs.fullCtx);
  for (var c in configs) {
    if (c.semanticContext != EmptySemanticContext.Instance) {
      final predicateEvaluationResult = evalSemanticContextOne(
        c.semanticContext,
        outerContext,
        c.alt,
        configs.fullCtx,
      );
      if (predicateEvaluationResult) {
        succeeded.add(c);
      } else {
        failed.add(c);
      }
    } else {
      succeeded.add(c);
    }
  }
  return Pair<ATNConfigSet, ATNConfigSet>(succeeded, failed);
}