コード例 #1
0
ファイル: RegexVisitor.cs プロジェクト: DinkDev/Pliant
        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));
        }
コード例 #2
0
        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
ファイル: RegexVisitor.cs プロジェクト: DinkDev/Pliant
        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
ファイル: RegexTerm.cs プロジェクト: bilsaboob/Pliant
 public RegexTermFactor(RegexFactor factor, RegexTerm term)
     : base(factor)
 {
     Term = term;
     _hashCode = ComputeHashCode();
 }
コード例 #7
0
ファイル: RegexTerm.cs プロジェクト: DinkDev/Pliant
 public RegexTermFactor(RegexFactor factor, RegexTerm term)
     : base(factor)
 {
     Term      = term;
     _hashCode = ComputeHashCode();
 }
コード例 #8
0
ファイル: RegexExpression.cs プロジェクト: bilsaboob/Pliant
 public RegexExpressionAlteration(RegexTerm term, RegexExpression expression)
     : base(term)
 {
     Expression = expression;
     _hashCode = ComputeHashCode();
 }
コード例 #9
0
ファイル: RegexExpression.cs プロジェクト: bilsaboob/Pliant
 public RegexExpressionTerm(RegexTerm term)
 {
     Term = term;
     _hashCode = ComputeHashCode();
 }
コード例 #10
0
        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");
        }