public AddPathDepsTraverser(int maxPathLength, bool backwards, AbstractPathMatch <TDependency, TItem> countMatch, [NotNull] Action checkAbort) : base(checkAbort) { _maxPathLength = maxPathLength; _backwards = backwards; _countMatch = countMatch; }
protected override UpInfo <TItem> BeforePopDependency(Stack <TDependency> currentPath, int expectedPathMatchIndex, AbstractPathMatch <TDependency, TItem> pathMatchOrNull, bool isEnd, Ignore here, UpInfo <TItem> upSum, UpInfo <TItem> childUp) { upSum.UnionWith(childUp); TDependency top = currentPath.Peek(); var key = new ItemAndInt(top.UsedItem, expectedPathMatchIndex); bool isEndOfCycle = _onPath.Contains(key); if (isEnd || isEndOfCycle) { upSum.Add(top.UsedItem); } return(upSum); }
protected override DownAndHere AfterPushDependency(Stack <TDependency> currentPath, int expectedPathMatchIndex, AbstractPathMatch <TDependency, TItem> pathMatchOrNull, bool isEnd, DownInfo down) { TDependency tailDependency = currentPath.Peek(); TItem usedItem = tailDependency.UsedItem; if (down.BehindCountMatch != null) { if (!Counts.ContainsKey(usedItem)) { Counts[usedItem] = new HashSet <IMatchableObject>(); } Counts[usedItem].Add(down.BehindCountMatch); } _seenInnerPathStarts.Add(usedItem); IMatchableObject pushDownMatch = null; bool dependencyMatchedByCountMatch = false; bool usedItemMatchedByCountMatch = false; if (down.BehindCountMatch != null) { pushDownMatch = down.BehindCountMatch; } else if (_countMatch == null) { // default values are ok } else if (_countMatch == pathMatchOrNull) { if (_countMatch is DependencyPathMatch <TDependency, TItem> ) { pushDownMatch = tailDependency; dependencyMatchedByCountMatch = true; } else { pushDownMatch = usedItem; usedItemMatchedByCountMatch = true; } } else { // default values are ok } return(new DownAndHere(new DownInfo(pushDownMatch), new HereInfo(dependencyMatchedByCountMatch, usedItemMatchedByCountMatch))); }
protected override Ignore BeforePopDependency(Stack <TDependency> currentPath, int expectedPathMatchIndex, AbstractPathMatch <TDependency, TItem> pathMatchOrNull, bool isEnd, Ignore here, Ignore upSum, Ignore childUp) { return(childUp); }
protected override DownAndHere AfterPushDependency(Stack <TDependency> currentPath, int expectedPathMatchIndex, AbstractPathMatch <TDependency, TItem> pathMatchOrNull, bool isEnd, Ignore down) { return(new DownAndHere()); }
public void Parse([NotNull] GlobalContext globalContext, [CanBeNull] string argsAsString, out bool backwardsX, out ItemMatch pathAnchorX, out bool pathAnchorIsCountMatchX, List <AbstractPathMatch <Dependency, Item> > expectedPathMatches, out AbstractPathMatch <Dependency, Item> countMatchX, out int?maxPathLengthX, [NotNull][ItemNotNull] params OptionAction[] moreOptions) { bool backwards = false; ItemMatch pathAnchor = null; bool pathAnchorIsCountMatch = false; ////var expectedPathMatches = new List<AbstractPathMatch<Dependency, Item>>(); var dontMatchesBeforeNextPathMatch = new List <AbstractPathMatch <Dependency, Item> >(); AbstractPathMatch <Dependency, Item> countMatch = null; int?maxPathLength = null; Option.Parse(globalContext, argsAsString, new[] { BackwardsOption.Action((args, j) => { backwards = true; return(j); }), PathItemAnchorOption.Action((args, j) => { if (pathAnchor == null) { pathAnchor = new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Missing item pattern"), globalContext.IgnoreCase, anyWhereMatcherOk: true); } else { expectedPathMatches.Add(CreateItemPathMatch(globalContext, args, ref j, multipleOccurrencesAllowed: false, mayContinue: true, dontMatches: dontMatchesBeforeNextPathMatch)); } return(j); }), PathDependencyAnchorOption.Action((args, j) => { CheckPathAnchorSet(pathAnchor); expectedPathMatches.Add(CreateDependencyPathMatch(globalContext, args, ref j, multipleOccurrencesAllowed: false, mayContinue: true, dontMatchesBeforeThis: dontMatchesBeforeNextPathMatch)); return(j); }), CountItemAnchorOption.Action((args, j) => { if (pathAnchor == null) { pathAnchor = new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Missing item pattern"), globalContext.IgnoreCase, anyWhereMatcherOk: true); pathAnchorIsCountMatch = true; } else { expectedPathMatches.Add( countMatch = CreateItemPathMatch(globalContext, args, ref j, multipleOccurrencesAllowed: false, mayContinue: true, dontMatches: dontMatchesBeforeNextPathMatch)); } return(j); }), CountDependencyAnchorOption.Action((args, j) => { CheckPathAnchorSet(pathAnchor); expectedPathMatches.Add( countMatch = CreateDependencyPathMatch(globalContext, args, ref j, multipleOccurrencesAllowed: false, mayContinue: true, dontMatchesBeforeThis: dontMatchesBeforeNextPathMatch)); return(j); }), MultipleItemAnchorOption.Action((args, j) => { CheckPathAnchorSet(pathAnchor); expectedPathMatches.Add(CreateItemPathMatch(globalContext, args, ref j, multipleOccurrencesAllowed: true, mayContinue: true, dontMatches: dontMatchesBeforeNextPathMatch)); return(j); }), MultipleDependencyAnchorOption.Action((args, j) => { CheckPathAnchorSet(pathAnchor); expectedPathMatches.Add(CreateDependencyPathMatch(globalContext, args, ref j, multipleOccurrencesAllowed: true, mayContinue: true, dontMatchesBeforeThis: dontMatchesBeforeNextPathMatch)); return(j); }), NoSuchItemAnchorOption.Action((args, j) => { CheckPathAnchorSet(pathAnchor); dontMatchesBeforeNextPathMatch.Add(CreateItemPathMatch(globalContext, args, ref j, multipleOccurrencesAllowed: false, mayContinue: false, dontMatches: new AbstractPathMatch <Dependency, Item> [0])); return(j); }), NoSuchDependencyAnchorOption.Action((args, j) => { CheckPathAnchorSet(pathAnchor); dontMatchesBeforeNextPathMatch.Add(CreateDependencyPathMatch(globalContext, args, ref j, multipleOccurrencesAllowed: false, mayContinue: false, dontMatchesBeforeThis: new AbstractPathMatch <Dependency, Item> [0])); return(j); }), MaxPathLengthOption.Action((args, j) => { maxPathLength = Option.ExtractIntOptionValue(args, ref j, "Invalid maximum path length"); return(j); }) }.Concat(moreOptions).ToArray()); backwardsX = backwards; pathAnchorX = pathAnchor; pathAnchorIsCountMatchX = pathAnchorIsCountMatch; countMatchX = countMatch; maxPathLengthX = maxPathLength; }
protected override List <PathNode <TItem, TDependency> > BeforePopDependency(Stack <TDependency> currentPath, int expectedPathMatchIndex, AbstractPathMatch <TDependency, TItem> pathMatchOrNull, bool isEnd, HereInfo here, List <PathNode <TItem, TDependency> > upSum, List <PathNode <TItem, TDependency> > childUp) { TDependency top = currentPath.Peek(); var key = new ItemAndInt(top.UsedItem, expectedPathMatchIndex); bool isEndOfCycle = _onPath.Contains(key); if (isEnd || isEndOfCycle || childUp.Any(p => p.LeadsToEndNodes)) { PathNode <TItem, TDependency> n = new PathNode <TItem, TDependency>(top, isEnd, isEndOfCycle, here.DependencyMatchedByCountMatch, here.UsedItemMatchedByCountMatch, childUp); if (isEnd || isEndOfCycle) { _nodesWithEndFlag++; } upSum.Add(n); } return(upSum); }