Example #1
0
            public ChainingInfo[] ValidateSequence()
            {
                ChainingInfo[] childrenChainingInfos = Elements.Select(e => e.Validate()).ToArray();
                int            n = childrenChainingInfos.Length - 1;

                for (int i = 0; i < n; i++)
                {
                    ChainingInfo info = childrenChainingInfos[i];
                    if (info.CanBeEmpty)
                    {
                        if (info.StartsWithItemMatch !=
                            childrenChainingInfos[i + 1].StartsWithItemMatch)
                        {
                            throw new RegexValidationException(Elements.ElementAt(i), Elements.ElementAt(i + 1),
                                                               "Element after possibly empty element must also start with " + (info.EndsWithItemMatch ? "item" : "dependency"));
                        }
                    }

                    for (int j = i + 1; j <= n && (j - 1 == i || childrenChainingInfos[j - 1].CanBeEmpty); j++)
                    {
                        if (info.EndsWithItemMatch == childrenChainingInfos[j].StartsWithItemMatch)
                        {
                            throw new RegexValidationException(Elements.ElementAt(i), Elements.ElementAt(j),
                                                               "Missing " + (info.EndsWithItemMatch ? "dependency" : "item") +
                                                               "between possible adjacent patterns");
                        }
                    }
                }

                return(childrenChainingInfos);
            }
Example #2
0
            public ChainingInfo[] ValidateMultiple()
            {
                ChainingInfo[] childrenChainingInfos = ValidateSequence();
                ChainingInfo   first = childrenChainingInfos.First();

                if (childrenChainingInfos.Last().EndsWithItemMatch == first.StartsWithItemMatch)
                {
                    throw new RegexValidationException(Elements.Last(), Elements.First(),
                                                       "Repeated sequence ends and starts with " + (first.StartsWithItemMatch ? "item" : "dependency") +
                                                       " pattern");
                }
                return(childrenChainingInfos);
            }
Example #3
0
        public PathRegex(string s, Dictionary <string, ItemMatch> definedItemMatches,
                         Dictionary <string, DependencyMatch> definedDependencyMatches, bool ignoreCase)
        {
            _definedItemMatches       = definedItemMatches;
            _definedDependencyMatches = definedDependencyMatches;
            _ignoreCase = ignoreCase;
            RegexElement e = Parse(s, 0);
            ChainingInfo topChainingInfo = e.Validate();

            if (!topChainingInfo.StartsWithItemMatch)
            {
                throw new RegexValidationException(e, null, "Path regex must start with item match");
            }
            if (!topChainingInfo.EndsWithItemMatch)
            {
                throw new RegexValidationException(e, null, "Path regex must end with item match");
            }
            _rootExecutionNode = e.CreateDeterministicExecutionGraph();
        }