protected internal override IEnumerable <Action <Dependency> > Parse([NotNull] GlobalContext globalContext,
                                                                             [CanBeNull] string argsAsString, string defaultReasonForSetBad, bool ignoreCase,
                                                                             [NotNull][ItemNotNull] IEnumerable <OptionAction> moreOptionActions)
        {
            var localResult = new List <Action <Dependency> >();
            IEnumerable <Action <Dependency> > baseResult = base.Parse(globalContext, argsAsString, defaultReasonForSetBad, ignoreCase, new[] {
                IncrementBadOption.Action((args, j) => {
                    localResult.Add(d => d.IncrementBad(IncrementBadOption.Name));
                    return(j);
                }),
                ResetBadOption.Action((args, j) => {
                    localResult.Add(d => d.ResetBad());
                    return(j);
                }),
                SetQuestionableOption.Action((args, j) => {
                    localResult.Add(d => d.MarkAsQuestionable(SetQuestionableOption.Name));
                    return(j);
                }),
                IncrementQuestionableOption.Action((args, j) => {
                    localResult.Add(d => d.IncrementQuestionable(IncrementQuestionableOption.Name));
                    return(j);
                }),
                ResetQuestionableOption.Action((args, j) => {
                    localResult.Add(d => d.ResetQuestionable());
                    return(j);
                })
            }.Concat(moreOptionActions).ToArray());

            return(baseResult.Concat(localResult));
        }
Esempio n. 2
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            transformOptions.Effects = EffectOptions.Parse(globalContext: globalContext,
                                                           argsAsString: transformOptionsString, defaultReasonForSetBad: typeof(MarkCycleDeps).Name,
                                                           ignoreCase: globalContext.IgnoreCase, moreOptionActions: new[] {
                ConsiderSelfCyclesOption.Action((args, j) => {
                    transformOptions.IgnoreSelfCycles = false;
                    return(j);
                }),
                KeepOnlyCyclesOption.Action((args, j) => {
                    transformOptions.KeepOnlyCycleDependencies = true;
                    return(j);
                }),
                CycleAnchorsOption.Action((args, j) => {
                    transformOptions.CycleAnchorsMatch = new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "missing anchor name"), globalContext.IgnoreCase, anyWhereMatcherOk: true);
                    return(j);
                }),
                MaxCycleLengthOption.Action((args, j) => {
                    transformOptions.MaxCycleLength = Option.ExtractIntOptionValue(args, ref j, "Invalid maximum cycle length");
                    return(j);
                }),
                AddIndexedMarkerOption.Action((args, j) => {
                    transformOptions.IndexedMarkerPrefix = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                    return(j);
                }),
            });

            return(transformOptions);
        }
Esempio n. 3
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            //bool removeOriginal = false;

            DependencyMatchOptions.Parse(globalContext, transformOptionsString, globalContext.IgnoreCase,
                                         transformOptions.Matches, transformOptions.Excludes,
                                         FromItemsOption.Action((args, j) => {
                transformOptions.FromItemMatches.Add(new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Missing 'from' match"), globalContext.IgnoreCase, anyWhereMatcherOk: true));
                return(j);
            }),
                                         ToItemsOption.Action((args, j) => {
                transformOptions.ToItemMatches.Add(new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Missing 'to' match"), globalContext.IgnoreCase, anyWhereMatcherOk: true));
                return(j);
            }),
                                         IdempotentOption.Action((args, j) => {
                transformOptions.Idempotent = true;
                return(j);
            }),
                                         //RemoveOriginalOption.Action((args, j) => {
                                         //    removeOriginal = true;
                                         //    return j;
                                         //}),
                                         AddMarkerOption.Action((args, j) => {
                transformOptions.MarkersToAdd.Add(Option.ExtractRequiredOptionValue(args, ref j, "missing marker name").Trim('\'').Trim());
                return(j);
            }));

            return(transformOptions);
        }
Esempio n. 4
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext, [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            //bool recursive = false;

            DependencyMatchOptions.Parse(globalContext, transformOptionsString, globalContext.IgnoreCase, transformOptions.Matches, transformOptions.Excludes,
                                         MarkSingleCyclesOption.Action((args, j) => {
                transformOptions.MarkSingleCycleNodes = true;
                return(j);
                //}), RecursiveMarkOption.Action((args, j) => {
                //    recursive = true;
                //    return j;
            }),
                                         MarkTransitiveDependenciesOption.Action((args, j) => {
                transformOptions.MarkTransitiveDependencies = true;
                return(j);
            }),
                                         AddMarkerOption.Action((args, j) => {
                transformOptions.MarkerToAdd = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name").Trim('\'').Trim();
                return(j);
            }));

            return(transformOptions);
        }
Esempio n. 5
0
        protected override TransformOptions CreateTransformOptions(GlobalContext globalContext, string transformOptionsString,
                                                                   Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var options = new TransformOptions();

            Option.Parse(globalContext, transformOptionsString,
                         MatchOption.Action((args, j) => {
                options.Matches.Add(new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "missing match definition"),
                                                  globalContext.IgnoreCase, anyWhereMatcherOk: true));
                return(j);
            }), MarkSingleCyclesOption.Action((args, j) => {
                options.MarkSingleCycleNodes = true;
                return(j);
            }), ConsiderSelfCyclesOption.Action((args, j) => {
                options.ConsiderSelfCyclesInSourcesAndSinks = true;
                return(j);
            }), RecursiveMarkOption.Action((args, j) => {
                options.Recursive = true;
                return(j);
            }), MarkSourcesOption.Action((args, j) => {
                options.MarkSources = true;
                return(j);
            }), MarkSinksOption.Action((args, j) => {
                options.MarkSinks = true;
                return(j);
            }), AddMarkerOption.Action((args, j) => {
                options.MarkerToAdd = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name").Trim('\'').Trim();
                return(j);
            }));
            return(options);
        }
Esempio n. 6
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            Option.Parse(globalContext, transformOptionsString,
                         OrderByBadCount.Action((args, j) => {
                transformOptions.OrderBy = d => d.BadCt;
                return(j);
            }),
                         OrderByQuestionableCount.Action((args, j) => {
                transformOptions.OrderBy = d => d.QuestionableCt;
                return(j);
            }),
                         OrderByIncomingValues.Action((args, j) => {
                transformOptions.GetSortValue = (incoming, outgoing) => incoming;
                return(j);
            }),
                         OrderByOutgoingValues.Action((args, j) => {
                transformOptions.GetSortValue = (incoming, outgoing) => outgoing;
                return(j);
            }), AddMarkerOption.Action((args, j) => {
                transformOptions.OrderMarkerPrefix = Option.ExtractRequiredOptionValue(args, ref j, "missing marker prefix").Trim('\'').Trim();
                return(j);
            }));

            return(transformOptions);
        }
Esempio n. 7
0
        protected override ConfigureOptions CreateConfigureOptions(GlobalContext globalContext,
                                                                   string configureOptionsString, bool forceReload)
        {
            var options = new ConfigureOptions();

            Option.Parse(globalContext, configureOptionsString,
                         RuleFileExtensionOption.Action((args, j) => {
                options.RuleFileExtension = '.' + Option.ExtractRequiredOptionValue(args, ref j, "missing extension").TrimStart('.');
                return(j);
            }),
                         RuleRootDirectoryOption.Action((args, j) => {
                options.SearchRootsForRuleFiles.Add(new DirectoryInfo(Option.ExtractRequiredOptionValue(args, ref j, "missing rule-search root directory")));
                return(j);
            }),
                         DefaultRuleFileOption.Action((args, j) => {
                string fullSourceName  = Path.GetFullPath(Option.ExtractRequiredOptionValue(args, ref j, "missing default rules filename"));
                options.DefaultRuleSet = GetOrReadChildConfiguration(globalContext,
                                                                     () => new StreamReader(fullSourceName), fullSourceName, globalContext.IgnoreCase, "????", forceReload, options.LocalVars);
                return(j);
            }),
                         DefaultRulesOption.Action((args, j) => {
                options.DefaultRuleSet = GetOrReadChildConfiguration(globalContext,
                                                                     () => new StringReader(string.Join(Environment.NewLine, args.Skip(j + 1))),
                                                                     DefaultRulesOption.ShortName, globalContext.IgnoreCase, "????", forceReload: true, localVars: options.LocalVars);
                // ... and all args are read in, so the next arg index is past every argument.
                return(int.MaxValue);
            })
                         );
            return(options);
        }
Esempio n. 8
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            Option.Parse(globalContext, transformOptionsString,
                         MatchSourceOption.Action((args, j) => {
                transformOptions.SourceMatches.Add(new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Match pattern missing"), globalContext.IgnoreCase, anyWhereMatcherOk: true));
                return(j);
            }),
                         MatchTargetOption.Action((args, j) => {
                transformOptions.TargetMatches.Add(new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Match pattern missing"), globalContext.IgnoreCase, anyWhereMatcherOk: true));
                return(j);
            }),
                         UseQuestionableCountOption.Action((args, j) => {
                transformOptions.WeightForCut = d => d.QuestionableCt;
                return(j);
            }),
                         UseCountOption.Action((args, j) => {
                transformOptions.WeightForCut = d => d.Ct;
                return(j);
            }),
                         DepsMarkerOption.Action((args, j) => {
                transformOptions.MarkerToAddToCut = Option.ExtractRequiredOptionValue(args, ref j, "Dependency marker missing").Trim('\'').Trim();
                return(j);
            }),
                         SourceMarkerOption.Action((args, j) => {
                transformOptions.MarkerToAddToSourceSide = Option.ExtractRequiredOptionValue(args, ref j, "Source marker missing").Trim('\'').Trim();
                return(j);
            }));
            return(transformOptions);
        }
Esempio n. 9
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            DependencyMatchOptions.Parse(globalContext, transformOptionsString, globalContext.IgnoreCase, transformOptions.Matches, transformOptions.Excludes,
                                         MarkLeftItemOption.Action((args, j) => {
                string marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                transformOptions.MarkersToAddOnLeft.Add(marker.TrimStart('\''));
                return(j);
            }),
                                         MarkDependencyItemOption.Action((args, j) => {
                string marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                transformOptions.MarkersToAddOnDep[marker.TrimStart('\'')] = 1;
                return(j);
            }),
                                         MarkRightItemOption.Action((args, j) => {
                string marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                transformOptions.MarkersToAddOnRight.Add(marker.TrimStart('\''));
                return(j);
            }),
                                         UnmarkLeftItemOption.Action((args, j) => {
                string marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                transformOptions.MarkerPatternsToRemoveOnLeft.Add(marker.TrimStart('\''));
                return(j);
            }),
                                         UnmarkDependencyItemOption.Action((args, j) => {
                string marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                transformOptions.MarkersToRemoveOnDep.Add(marker.TrimStart('\''));
                return(j);
            }),
                                         UnmarkRightItemOption.Action((args, j) => {
                string marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker");
                transformOptions.MarkerPatternsToRemoveOnRight.Add(marker.TrimStart('\''));
                return(j);
            }),
                                         ClearLeftItemOption.Action((args, j) => {
                transformOptions.ClearLeft = true;
                return(j);
            }),
                                         ClearDependencyItemOption.Action((args, j) => {
                transformOptions.ClearDependency = true;
                return(j);
            }),
                                         ClearRightItemOption.Action((args, j) => {
                transformOptions.ClearRight = true;
                return(j);
            }),
                                         ResetBadCountOption.Action((args, j) => {
                transformOptions.ResetBad = true;
                return(j);
            }),
                                         ResetQuestionableCountOption.Action((args, j) => {
                transformOptions.ResetQuestionable = true;
                return(j);
            })
                                         );
            return(transformOptions);
        }
Esempio n. 10
0
        protected override ConfigureOptions CreateConfigureOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string configureOptionsString, bool forceReload)
        {
            var           localVars          = new ValuesFrame();
            var           options            = new ConfigureOptions();
            ProjectionSet orderedProjections = null;

            _projector = null;

            Option.Parse(globalContext, configureOptionsString,
                         MatcherStrategyOption.Action((args, j) => {
                string strategy = Option.ExtractRequiredOptionValue(args, ref j, "missing strategy");
                switch (strategy)
                {
                case "S":
                    _createProjector = (p, i) => new SimpleProjector(p, name: "default projector");
                    break;

                case "PT":
                    _createProjector = (p, i) => new SelfOptimizingPrefixTrieProjector(p, i, 10000, name: "PT projector");
                    break;

                case "FL":
                    _createProjector = (p, i) => new SelfOptimizingFirstLetterProjector(p, i, 10000, name: "FL projector");
                    break;

                default:
                    Log.WriteWarning($"Unrecognized matcher optimization strategy {strategy} - using default");
                    break;
                }
                return(j);
            }), ProjectionFileOption.Action((args, j) => {
                string fullSourceName =
                    Path.GetFullPath(Option.ExtractRequiredOptionValue(args, ref j, "missing projections filename"));
                orderedProjections = GetOrReadChildConfiguration(globalContext, () => new StreamReader(fullSourceName),
                                                                 fullSourceName, globalContext.IgnoreCase, "????", forceReload, localVars);
                return(j);
            }), ProjectionsOption.Action((args, j) => {
                orderedProjections = GetOrReadChildConfiguration(globalContext,
                                                                 () => new StringReader(string.Join(Environment.NewLine, args.Skip(j + 1))),
                                                                 ProjectionsOption.ShortName, globalContext.IgnoreCase, "????", forceReload: true, localVars: localVars);
                // ... and all args are read in, so the next arg index is past every argument.
                return(int.MaxValue);
            }));

            if (orderedProjections == null || !orderedProjections.AllProjections.Any())
            {
                Log.WriteWarning("No projections defined");
                _projector = new SimpleProjector(new Projection[0], name: "empty");
                _allProjectionsForMatchCountLoggingOnly = new Projection[0];
            }
            else
            {
                _projector = _createProjector(orderedProjections.AllProjections, globalContext.IgnoreCase);
                _allProjectionsForMatchCountLoggingOnly = orderedProjections.AllProjections;
            }
            return(options);
        }
Esempio n. 11
0
 public static void Parse(string[] args)
 {
     foreach (string arg in args)
     {
         if (arg.StartsWith("-"))
         {
             Option option = Dict.GetOrDefault(arg, Option.Help);
             option.Action()();
         }
     }
 }
Esempio n. 12
0
        protected override Options CreateRenderOptions(GlobalContext globalContext, string options)
        {
            var result = new Options();

            DependencyMatchOptions.Parse(globalContext, options, globalContext.IgnoreCase, result.Matches, result.Excludes,
                                         NoExampleInfoOption.Action((args, j) => {
                result.NoExampleInfo = true;
                return(j);
            }));
            return(result);
        }
 public override void Render([NotNull] GlobalContext globalContext, [NotNull, ItemNotNull] IEnumerable <Dependency> dependencies, string options, [NotNull] WriteTarget target, bool ignoreCase)
 {
     DoRender(globalContext, dependencies, options, target,
              InterfaceSelectorOption.Action((args, j) => {
         _interfaceSelector = new Regex(Option.ExtractRequiredOptionValue(args, ref j, "Regex for interface selector missing"));
         return(j);
     }),
              OrderFieldOption.Action((args, j) => {
         string orderPattern = Option.ExtractRequiredOptionValue(args, ref j, "order field missing");
         _orderSupport       = OrderSupport.Create(orderPattern, ignoreCase);
         return(j);
     }));
 }
Esempio n. 14
0
        private static GameObject CreateItem(Transform2 transform, Option option, int itemNumber)
        {
            var itemTransform = transform.Copy();

            itemTransform.Location += new Vector2(0, transform.Size.Height * itemNumber);
            return(Entity.Create($"Picker Option: {option.Name}", itemTransform)
                   .Add((o, r) => new Texture(r.CreateRectangle(Color.Purple, o)))
                   .Add(new TextDisplay {
                Text = () => option.Name
            })
                   .Add(new MouseClickTarget {
                OnHit = () => option.Action()
            }));
        }
Esempio n. 15
0
        protected override Options CreateRenderOptions(GlobalContext globalContext, string options)
        {
            var result = new Options();

            Option.Parse(globalContext, options,
                         PathMarkerOption.Action((args, j) => {
                result.MarkerMatchers.Add(MarkerMatch.CreateMatcher(Option.ExtractRequiredOptionValue(args, ref j, "Missing item match"), globalContext.IgnoreCase));
                return(j);
            }),
                         ShowItemMarkersOption.Action((args, j) => {
                result.ShowItemMarkers = true;
                return(j);
            }));
            return(result);
        }
Esempio n. 16
0
        public int Transform([NotNull] GlobalContext globalContext, [NotNull][ItemNotNull] IEnumerable <Dependency> dependencies,
                             string transformOptions, [NotNull] List <Dependency> transformedDependencies, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            bool      backwards;
            ItemMatch pathAnchor;
            bool      pathAnchorIsCountMatch;
            var       expectedPathMatches = new List <AbstractPathMatch <Dependency, Item> >();
            AbstractPathMatch <Dependency, Item> countMatch;
            string marker            = "_";
            bool   addIndex          = false;
            bool   keepOnlyPathEdges = false;
            int?   maxPathLength;

            PathOptions.Parse(globalContext, transformOptions, out backwards, out pathAnchor, out pathAnchorIsCountMatch,
                              expectedPathMatches, out countMatch, out maxPathLength,
                              AddMarkerOption.Action((args, j) => {
                marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                return(j);
            }),
                              AddIndexedMarkerOption.Action((args, j) => {
                marker   = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                addIndex = true;
                return(j);
            }),
                              KeepOnlyPathsOption.Action((args, j) => {
                keepOnlyPathEdges = true;
                return(j);
            })
                              );
            AbstractPathMatch <Dependency, Item>[] expectedPathMatchesArray = expectedPathMatches.ToArray();
            var c = new PathMarkerTraverser <Dependency, Item>(maxPathLength ?? 1 + expectedPathMatchesArray.Length * 2,
                                                               backwards, countMatch, globalContext.CheckAbort);

            c.Traverse(dependencies, pathAnchor, pathAnchorIsCountMatch, expectedPathMatchesArray);

            string addIndexToMarkerFormat = addIndex ? "D" + ("" + c.NodesWithEndFlag).Length : null;

            var t = new PathNodesTraverser(pathMarker: marker, addIndexToMarkerFormat: addIndexToMarkerFormat,
                                           checkAbort: globalContext.CheckAbort);

            t.Traverse(c.Paths, c.Counts.ToDictionary(kvp => kvp.Key, kvp => kvp.Value.Count));

            Log.WriteInfo($"... marked {t.PathCount} paths");

            transformedDependencies.AddRange(keepOnlyPathEdges ? t.PathDependencies : dependencies);

            return(Program.OK_RESULT);
        }
Esempio n. 17
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            Option.Parse(globalContext, transformOptionsString, BackwardsOption.Action((args, j) => {
                transformOptions.Backwards = true;
                return(j);
            }), MaxPathLengthOption.Action((args, j) => {
                transformOptions.MaxPathLength = Option.ExtractIntOptionValue(args, ref j, "Invalid maximum path length");
                return(j);
            }), AddMarkerOption.Action((args, j) => {
                transformOptions.Marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                return(j);
            }), AddIndexedMarkerOption.Action((args, j) => {
                transformOptions.Marker   = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                transformOptions.AddIndex = true;
                return(j);
            }), KeepOnlyPathsOption.Action((args, j) => {
                transformOptions.KeepOnlyPathEdges = true;
                return(j);
            }), IgnorePrefixPathsOption.Action((args, j) => {
                transformOptions.IgnorePrefixPaths = true;
                return(j);
            }), IgnoreSubpathsOption.Action((args, j) => {
                transformOptions.IgnoreSubpaths = true;
                return(j);
            }), AddDependencyOption.Action((args, j) => {
                transformOptions.AddTransitiveDependencyInsteadOfMarking = true;
                return(j);
            }), DefineDependencyMatchOption.Action((args, j) => {
                string name    = Option.ExtractRequiredOptionValue(args, ref j, "missing name");
                string pattern = Option.ExtractNextRequiredValue(args, ref j, "missing pattern");
                transformOptions.DefinedDependencyMatches[name] = DependencyMatch.Create(pattern, globalContext.IgnoreCase);
                return(j);
            }), DefineItemMatchOption.Action((args, j) => {
                string name    = Option.ExtractRequiredOptionValue(args, ref j, "missing name");
                string pattern = Option.ExtractNextRequiredValue(args, ref j, "missing pattern");
                transformOptions.DefinedItemMatches[name] = new ItemMatch(pattern, globalContext.IgnoreCase, anyWhereMatcherOk: true);
                return(j);
            }), RegexOption.Action((args, j) => {
                transformOptions.Regex = Option.ExtractRequiredOptionValue(args, ref j, "missing regex");
                return(j);
            }));

            return(transformOptions);
        }
Esempio n. 18
0
        protected override Options CreateRenderOptions(GlobalContext globalContext, string options)
        {
            var result = new Options();

            Option.Parse(globalContext, options,
                         MaxExampleLengthOption.Action((args, j) => {
                result.MaxExampleLength = Option.ExtractIntOptionValue(args, ref j,
                                                                       "No valid length after " + MaxExampleLengthOption.Name);
                return(j);
            }),
                         AbstractMatrixRenderer.InnerMatchOption.Action((args, j) => {
                result.InnerMatch = new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Pattern for selecting inner items missing"),
                                                  globalContext.IgnoreCase, anyWhereMatcherOk: true);
                return(j);
            }));
            return(result);
        }
Esempio n. 19
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            Option.Parse(globalContext, transformOptionsString,
                         BackProjectionGraphOption.Action((args, j) => {
                string backProjectionGraphName = Option.ExtractOptionValue(args, ref j);
                transformOptions.BackProjectionDependencies = findOtherWorkingGraph(backProjectionGraphName);
                if (transformOptions.BackProjectionDependencies == null)
                {
                    throw new ArgumentException($"Could not find graph '{backProjectionGraphName}'");
                }
                return(j);
            })
                         );
            return(transformOptions);
        }
Esempio n. 20
0
        protected override Options CreateRenderOptions(GlobalContext globalContext, string options)
        {
            var result = new Options();

            Option.Parse(globalContext, options,
                         MatchOption.Action((args, j) => {
                result.ItemMatches.Add(new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Missing item match"), globalContext.IgnoreCase, anyWhereMatcherOk: true));
                return(j);
            }),
                         NoMatchOption.Action((args, j) => {
                result.ItemExcludes.Add(new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Missing item match"), globalContext.IgnoreCase, anyWhereMatcherOk: true));
                return(j);
            }),
                         IndegreeMatchOption.Action((args, j) => {
                result.IndegreeMatches.Add(DependencyMatch.Create(Option.ExtractRequiredOptionValue(args, ref j, "Missing dependency match"), globalContext.IgnoreCase));
                return(j);
            }),
                         IndegreeNoMatchOption.Action((args, j) => {
                result.IndegreeExcludes.Add(DependencyMatch.Create(Option.ExtractRequiredOptionValue(args, ref j, "Missing dependency match"), globalContext.IgnoreCase));
                return(j);
            }),
                         OutdegreeMatchOption.Action((args, j) => {
                result.OutdegreeMatches.Add(DependencyMatch.Create(Option.ExtractRequiredOptionValue(args, ref j, "Missing dependency match"), globalContext.IgnoreCase));
                return(j);
            }),
                         OutdegreeNoMatchOption.Action((args, j) => {
                result.OutdegreeExcludes.Add(DependencyMatch.Create(Option.ExtractRequiredOptionValue(args, ref j, "Missing dependency match"), globalContext.IgnoreCase));
                return(j);
            }),
                         IndegreeNotZeroOption.Action((args, j) => {
                result.WriteOnlyIfIndegreeNotZero = true;
                return(j);
            }),
                         OutdegreeNotZeroOption.Action((args, j) => {
                result.WriteOnlyIfOutdegreeNotZero = true;
                return(j);
            }),
                         ShowMarkersOption.Action((args, j) => {
                result.ShowMarkers = true;
                return(j);
            }));
            return(result);
        }
Esempio n. 21
0
        private static Options ParseArgs([NotNull] GlobalContext globalContext, [CanBeNull] string options)
        {
            var result = new Options();

            Option.Parse(globalContext, options,
                         XmlOutputOption.Action((args, j) => {
                result.XmlOutput = true;
                return(j);
            }),
                         RuleOutputOption.Action((args, j) => {
                result.SimpleRuleOutput = true;
                return(j);
            }),
                         NewlineOption.Action((args, j) => {
                result.NewLine = true;
                return(j);
            }));
            return(result);
        }
Esempio n. 22
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            PathOptions.Parse(globalContext, transformOptionsString, out transformOptions.Backwards,
                              out transformOptions.PathAnchor, out transformOptions.PathAnchorIsCountMatch,
                              transformOptions.ExpectedPathMatches, out transformOptions.CountMatch, out transformOptions.MaxPathLength,
                              AddMarkerOption.Action((args, j) => {
                transformOptions.Marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                return(j);
            })
                              ////KeepOnlyPathsOption.Action((args, j) => {
                              ////    keepOnlyPathEdges = true;
                              ////    return j;
                              ////})
                              );
            return(transformOptions);
        }
Esempio n. 23
0
 public void Parse([NotNull] GlobalContext globalContext, [CanBeNull] string argsAsString, bool ignoreCase,
                   [NotNull][ItemNotNull] List <DependencyMatch> matches, [NotNull][ItemNotNull] List <DependencyMatch> excludes,
                   [NotNull][ItemNotNull] params OptionAction[] moreOptions)
 {
     Option.Parse(globalContext, argsAsString, new[] {
         DependencyMatchOption.Action((args, j) => {
             string pattern = Option.ExtractRequiredOptionValue(args, ref j, "missing dependency match pattern",
                                                                allowOptionWithLeadingMinus: true);
             matches.Add(DependencyMatch.Create(pattern, ignoreCase));
             return(j);
         }),
         NoMatchOption.Action((args, j) => {
             string pattern = Option.ExtractRequiredOptionValue(args, ref j, "missing dependency match pattern",
                                                                allowOptionWithLeadingMinus: true);
             excludes.Add(DependencyMatch.Create(pattern, ignoreCase));
             return(j);
         })
     }.Concat(moreOptions).ToArray());
 }
Esempio n. 24
0
        protected override TransformOptions CreateTransformOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var transformOptions = new TransformOptions();

            DependencyMatchOptions.Parse(globalContext, transformOptionsString, globalContext.IgnoreCase, transformOptions.Matches, transformOptions.Excludes,
                                         IdempotentOption.Action((args, j) => {
                transformOptions.Idempotent = true;
                return(j);
            }),
                                         RemoveOriginalOption.Action((args, j) => {
                transformOptions.RemoveOriginal = true;
                return(j);
            }),
                                         AddMarkerOption.Action((args, j) => {
                transformOptions.MarkerToAdd = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name").Trim('\'').Trim();
                return(j);
            }));

            return(transformOptions);
        }
Esempio n. 25
0
        protected override TransformOptions CreateTransformOptions(GlobalContext globalContext,
                                                                   string transformOptionsString, Func <string, IEnumerable <Dependency> > findOtherWorkingGraph)
        {
            var options = new TransformOptions();

            options.ShowUnusedQuestionableRules = options.ShowUnusedRules = options.AddMarker = false;

            Option.Parse(globalContext, transformOptionsString,
                         ShowUnusedQuestionableRulesOption.Action((args, j) => {
                options.ShowUnusedQuestionableRules = true;
                return(j);
            }), ShowAllUnusedRulesOption.Action((args, j) => {
                options.ShowUnusedRules = true;
                return(j);
            }), AddMarkersForBadGroups.Action((args, j) => {
                options.AddMarker = true;
                return(j);
            }));

            return(options);
        }
Esempio n. 26
0
 public override void Render([NotNull] GlobalContext globalContext, [NotNull, ItemNotNull] IEnumerable <Dependency> dependencies, string options, [NotNull] WriteTarget target, bool ignoreCase)
 {
     DoRender(globalContext, dependencies, options, target,
              BottomRegexOption.Action((args, j) => {
         string pattern   = Option.ExtractRequiredOptionValue(args, ref j, "Pattern for selection of bottom items missing");
         _bottomItemMatch = new ItemMatch(null, pattern, 0, ignoreCase, anyWhereMatcherOk: true);
         return(j);
     }),
              OrderFieldOption.Action((args, j) => {
         string orderPattern = Option.ExtractRequiredOptionValue(args, ref j, "order field missing");
         _orderSupport       = OrderSupport.Create(orderPattern, ignoreCase);
         return(j);
     }),
              NoEmptiesOnBottomOption.Action((args, j) => {
         _showOnlyReferencedOnBottom = true;
         return(j);
     }),
              NoEmptiesOnLeftOption.Action((args, j) => {
         _showOnlyReferencingOnLeft = true;
         return(j);
     }));
 }
Esempio n. 27
0
        protected override ConfigureOptions CreateConfigureOptions([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string configureOptionsString, bool forceReload)
        {
            var localVars = new ValuesFrame();

            var options = new ConfigureOptions();

            Option.Parse(globalContext, configureOptionsString,
                         ModificationsFileOption.Action((args, j) => {
                string fullSourceName  = Path.GetFullPath(Option.ExtractRequiredOptionValue(args, ref j, "missing modifications filename"));
                options.OrderedActions = GetOrReadChildConfiguration(globalContext,
                                                                     () => new StreamReader(fullSourceName), fullSourceName, globalContext.IgnoreCase, "????", forceReload, localVars);
                return(j);
            }),
                         ModificationsOption.Action((args, j) => {
                options.OrderedActions = GetOrReadChildConfiguration(globalContext,
                                                                     () => new StringReader(string.Join(Environment.NewLine, args.Skip(j + 1))),
                                                                     ModificationsOption.ShortName, globalContext.IgnoreCase, "????", forceReload: true, localVars: localVars);
                // ... and all args are read in, so the next arg index is past every argument.
                return(int.MaxValue);
            })
                         );
            return(options);
        }
        protected static void ParseOptions([NotNull] GlobalContext globalContext, string argsAsString, bool ignoreCase,
                                           out int?labelWidthOrNull, out bool withNotOkCt, out ItemMatch innerMatch)
        {
            int?      lw  = null;
            bool      wct = false;
            ItemMatch im  = null;

            Option.Parse(globalContext, argsAsString,
                         MaxNameWidthOption.Action((args, j) => {
                lw = Option.ExtractIntOptionValue(args, ref j, "");
                return(j);
            }),
                         WriteBadCountOption.Action((args, j) => {
                wct = true;
                return(j);
            }),
                         InnerMatchOption.Action((args, j) => {
                im = new ItemMatch(Option.ExtractRequiredOptionValue(args, ref j, "Missing pattern for inner match"), ignoreCase, anyWhereMatcherOk: true);
                return(j);
            }));
            labelWidthOrNull = lw;
            withNotOkCt      = wct;
            innerMatch       = im;
        }
Esempio n. 29
0
        protected internal virtual IEnumerable <Action <T> > Parse([NotNull] GlobalContext globalContext,
                                                                   [CanBeNull] string argsAsString, string defaultReasonForSetBad, bool ignoreCase,
                                                                   [NotNull][ItemNotNull] IEnumerable <OptionAction> moreOptionActions)
        {
            var result = new List <Action <T> >();

            Option.Parse(globalContext, argsAsString, new[] {
                AddMarkerOption.Action((args, j) => {
                    string marker = Option.ExtractRequiredOptionValue(args, ref j, "missing marker name");
                    result.Add(obj => obj.IncrementMarker(marker));
                    return(j);
                }),
                RemoveMarkerOption.Action((args, j) => {
                    string markerpattern = Option.ExtractRequiredOptionValue(args, ref j, "missing marker pattern");
                    result.Add(obj => obj.RemoveMarkers(markerpattern, ignoreCase));
                    return(j);
                }),
                DeleteOption.Action((args, j) => {
                    result.Add(DELETE_ACTION_MARKER);
                    return(j);
                })
            }.Concat(moreOptionActions).ToArray());
            return(result);
        }
Esempio n. 30
0
        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;
        }