Пример #1
0
        private RegexTerm VisitRegexTermNode(IInternalTreeNode internalNode)
        {
            RegexFactor factor = null;
            RegexTerm   term   = null;

            for (var c = 0; c < internalNode.Children.Count; c++)
            {
                var child = internalNode.Children[c];
                if (child.NodeType != TreeNodeType.Internal)
                {
                    continue;
                }
                var childInternalNode            = child as IInternalTreeNode;
                var childInternalNodeSymbolValue = childInternalNode.Symbol.Value;

                if (RegexGrammar.Factor == childInternalNodeSymbolValue)
                {
                    factor = VisitRegexFactorNode(childInternalNode);
                }
                else if (RegexGrammar.Term == childInternalNodeSymbolValue)
                {
                    term = VisitRegexTermNode(childInternalNode);
                }
            }
            if (term == null)
            {
                return(new RegexTerm(factor));
            }

            return(new RegexTermFactor(factor, term));
        }
        private static INfa Term(RegexTerm term)
        {
            switch (term.NodeType)
            {
            case RegexNodeType.RegexTerm:
                return(Factor(term.Factor));

            case RegexNodeType.RegexTermFactor:
                var regexTermFactor = term as RegexTermFactor;
                var factorNfa       = Factor(regexTermFactor.Factor);
                var termNfa         = Term(regexTermFactor.Term);
                return(Concatenation(factorNfa, termNfa));
            }
            throw new InvalidOperationException("Unrecognized Regex Term");
        }
Пример #3
0
        private RegexExpression VisitRegexExpressionNode(IInternalTreeNode internalNode)
        {
            RegexExpression expression = null;
            RegexTerm       term       = null;

            for (var c = 0; c < internalNode.Children.Count; c++)
            {
                var child = internalNode.Children[c];
                if (child.NodeType != TreeNodeType.Internal)
                {
                    continue;
                }
                var childInternalNode            = child as IInternalTreeNode;
                var childInternalNodeSymbolValue = childInternalNode.Symbol.Value;

                if (RegexGrammar.Expression == childInternalNodeSymbolValue)
                {
                    expression = VisitRegexExpressionNode(childInternalNode);
                }

                else if (RegexGrammar.Term == childInternalNodeSymbolValue)
                {
                    term = VisitRegexTermNode(childInternalNode);
                }
            }

            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.");
        }
Пример #4
0
 public RegexExpressionAlteration(RegexTerm term, RegexExpression expression)
     : base(term)
 {
     Expression = expression;
     _hashCode  = ComputeHashCode();
 }
Пример #5
0
 public RegexExpressionTerm(RegexTerm term)
 {
     Term      = term;
     _hashCode = ComputeHashCode();
 }
Пример #6
0
 public RegexTermFactor(RegexFactor factor, RegexTerm term)
     : base(factor)
 {
     Term = term;
     _hashCode = ComputeHashCode();
 }
Пример #7
0
 public RegexTermFactor(RegexFactor factor, RegexTerm term)
     : base(factor)
 {
     Term      = term;
     _hashCode = ComputeHashCode();
 }
Пример #8
0
 public RegexExpressionAlteration(RegexTerm term, RegexExpression expression)
     : base(term)
 {
     Expression = expression;
     _hashCode = ComputeHashCode();
 }
Пример #9
0
 public RegexExpressionTerm(RegexTerm term)
 {
     Term = term;
     _hashCode = ComputeHashCode();
 }
        private static INfa Term(RegexTerm term)
        {
            switch (term.NodeType)
            {
                case RegexNodeType.RegexTerm:
                    return Factor(term.Factor);

                case RegexNodeType.RegexTermFactor:
                    var regexTermFactor = term as RegexTermFactor;
                    var factorNfa = Factor(regexTermFactor.Factor);
                    var termNfa = Term(regexTermFactor.Term);
                    return Concatenation(factorNfa, termNfa);
            }
            throw new InvalidOperationException("Unrecognized Regex Term");
        }