protected override ATNState GetReachableTarget(ATNConfig source, Transition trans, int ttype) { if (ttype == AntlrV4.CaretToken.CaretTokenType) { ATNState target = null; AtomTransition atomTransition = trans as AtomTransition; if (atomTransition != null) { if (GetWordlikeTokenTypes().Contains(atomTransition.label)) { target = atomTransition.target; } } else { SetTransition setTransition = trans as SetTransition; if (setTransition != null) { bool not = trans is NotSetTransition; foreach (int t in GetWordlikeTokenTypes().ToArray()) { if (!not && setTransition.set.Contains(t) || not && !setTransition.set.Contains(t)) { target = setTransition.target; break; } } } else { RangeTransition rangeTransition = trans as RangeTransition; if (rangeTransition != null) { // TODO: there must be a better algorithm here int[] wordlikeTokenTypes = GetWordlikeTokenTypes().ToArray(); int lowerBound = Array.BinarySearch(wordlikeTokenTypes, rangeTransition.from); int upperBound = Array.BinarySearch(wordlikeTokenTypes, rangeTransition.to); if (lowerBound >= 0 || upperBound >= 0 || lowerBound != upperBound) { target = rangeTransition.target; } } else { WildcardTransition wildcardTransition = trans as WildcardTransition; if (wildcardTransition != null) { target = trans.target; } } } } if (_caretTransitions == null) { _caretTransitions = new Dictionary <ATNConfig, IList <Transition> >(); } IList <Transition> configTransitions; if (!_caretTransitions.TryGetValue(source, out configTransitions)) { configTransitions = new List <Transition>(); _caretTransitions[source] = configTransitions; } configTransitions.Add(trans); return(target); } return(base.GetReachableTarget(source, trans, ttype)); }
public ATNState GetReachableTargetHelper(ATNConfig source, Transition trans, int ttype) { return(GetReachableTarget(source, trans, ttype)); }