public void Visit(RepetitionNode node) { var tab = GetTab(_level); _builder.AppendFormat("{0}<{1} min='{2}' max='{3}'>{4}", tab, "repeatition", node.Token.MinOccurs, node.Token.MaxOccurs, _lr); _level++; foreach (var childNode in node.ChildNodes) { childNode.Accept(this); } _level--; _builder.AppendFormat("{0}</{1}>{2}", tab, "repeatition", _lr); }
public void Visit(RepetitionNode node) { var index = RandomNumberProvider.GetRandomNumber(node.Token.MinOccurs, node.Token.MaxOccurs > -1 ? node.Token.MaxOccurs + 1 : DefaultMaxOccurs); for (var i = 0; i < index; i++) { foreach (var childNode in node.ChildNodes) { childNode.Accept(this); } } }
public void Handle(Parser context) { var token = context.Current; switch (token.TokenType) { case TokenType.Literal: var literal = (LiteralToken)token; INode literalNode = new LiteralNode(literal); AddOperand(literalNode); break; case TokenType.Repetition: var repetition = (RepetitionToken)token; INode repetitionNode = new RepetitionNode(repetition); AddOperator(repetitionNode); break; case TokenType.ParenthesisLeft: context.ToState(new ParseState()); break; case TokenType.ParenthesisRight: var paranthesis = (ParenthesisRightToken)token; INode paranthesisRightNode = new ParenthesisNode(paranthesis); AddOperator(paranthesisRightNode); context.EndState(); break; case TokenType.Alternation: var alternation = (AlternationToken)token; INode alternationNode = new AlternationNode(alternation); AddOperator(alternationNode); break; case TokenType.Range: var range = (RangeToken)token; INode rangeNode = new RangeNode(range); AddOperator(rangeNode); break; case TokenType.BracketLeft: context.ToState(new ParseState()); break; case TokenType.BracketRight: var set = (BracketRightToken)token; INode setNode = new BracketNode(set); AddOperator(setNode); context.EndState(); break; case TokenType.Any: var anyNode = NodeBuilder.BuildAnyNode(); AddOperand(anyNode); break; case TokenType.Not: var not = (NotToken)token; INode notNode = new NotNode(not); AddOperator(notNode); break; case TokenType.Numeric: var numeric = (NumericToken)token; INode numericNode = NodeBuilder.BuildNumericNode(); AddOperand(numericNode); break; case TokenType.Word: var word = (WordToken)token; INode wordNode = NodeBuilder.BuildWordNode(); AddOperand(wordNode); break; case TokenType.Whitespace: var whitespace = (WhitespaceToken)token; INode whitespaceNode = NodeBuilder.BuildWhitespaceNode(); AddOperand(whitespaceNode); break; case TokenType.NonNumeric: var nonNumeric = (NonNumericToken)token; INode nonNumericNode = NodeBuilder.BuildNonNumericNode(); AddOperand(nonNumericNode); break; case TokenType.NonWord: var nonWord = (NonWordToken)token; INode nonWordNode = NodeBuilder.BuildNonWordNode(); AddOperand(nonWordNode); break; case TokenType.NonWhitespace: var nonWhitespace = (NonWhitespaceToken)token; INode nonWhitespaceNode = NodeBuilder.BuildNonWhitespaceNode(); AddOperand(nonWhitespaceNode); break; default: break; } }