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"); }
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."); }
public RegexExpressionAlteration(RegexTerm term, RegexExpression expression) : base(term) { Expression = expression; _hashCode = ComputeHashCode(); }
public RegexExpressionTerm(RegexTerm term) { Term = term; _hashCode = ComputeHashCode(); }
public RegexTermFactor(RegexFactor factor, RegexTerm term) : base(factor) { 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"); }