Exemplo n.º 1
0
        private RegexExpression VisitRegexExpressionNode(IInternalTreeNode node)
        {
            RegexExpression expression = null;
            IRegexTerm      term       = null;

            foreach (var internalNode in node.Children.OfType <IInternalTreeNode>())
            {
                if (internalNode.Is(RegexGrammar.Expression))
                {
                    expression = VisitRegexExpressionNode(internalNode);
                }
                else if (internalNode.Is(RegexGrammar.Term))
                {
                    term = VisitRegexTermNode(internalNode);
                }
            }

            if (expression != null && term != null)
            {
                return(new RegexExpressionAlteration(term, expression));
            }

            if (term != null)
            {
                return(new RegexExpressionTerm(term));
            }

            throw new InvalidOperationException("Unable to create null expression.");
        }
Exemplo n.º 2
0
        private static Nfa Term(IRegexTerm termX)
        {
            switch (termX)
            {
            case RegexTermFactor termFactor:
                return(Factor(termFactor.Factor));

            case RegexTermFactorTerm regexTermFactor:
                var factorNfa = Factor(regexTermFactor.Factor);
                var termNfa   = Term(regexTermFactor.Term);
                return(Concatenation(factorNfa, termNfa));
            }

            throw new InvalidOperationException("Unrecognized Regex Term");
        }
Exemplo n.º 3
0
        private IRegexTerm VisitRegexTermNode(IInternalTreeNode node)
        {
            IRegexFactor factorAtom = null;
            IRegexTerm   term       = null;

            foreach (var internalNode in node.Children.OfType <IInternalTreeNode>())
            {
                if (internalNode.Is(RegexGrammar.Factor))
                {
                    factorAtom = VisitRegexFactorNode(internalNode);
                }
                else if (internalNode.Is(RegexGrammar.Term))
                {
                    term = VisitRegexTermNode(internalNode);
                }
            }

            if (term == null)
            {
                return(new RegexTermFactor(factorAtom));
            }

            return(new RegexTermFactorTerm(factorAtom, term));
        }
Exemplo n.º 4
0
 public RegexTermFactorTerm(IRegexFactor factor, IRegexTerm term)
 {
     Factor = factor;
     Term   = term;
 }
Exemplo n.º 5
0
 public RegexExpressionTerm(IRegexTerm term)
 {
     Term = term;
 }
Exemplo n.º 6
0
 public RegexExpressionAlteration(IRegexTerm term, RegexExpression expression)
 {
     Term       = term;
     Expression = expression;
 }