Inheritance: NodeBase
Example #1
0
        public void Visit(BracketNode node)
        {
            if (node.ChildNodes[0].Token.TokenType == TokenType.Not)
            {
                node.ChildNodes[0].Accept(this);
                return;
            }

            INode current = node;

            while (current.ChildNodes[0].Token.TokenType == TokenType.Concatenation)
            {
                current = node.ChildNodes[0];
            }

            var nodes = new LiteralNodeCollection();

            foreach (var expandedNode in Expand(current))
            {
                if (nodes.Contains(expandedNode) == false)
                {
                    nodes.Add(expandedNode);
                }
            }

            var index = RandomNumberProvider.GetRandomNumber(0, nodes.Count);

            nodes[index].Accept(this);
        }
Example #2
0
        public void Visit(BracketNode node)
        {
            var tab = GetTab(_level);

            _builder.AppendFormat("{0}<{1}>{2}", tab, "set", _lr);
            _level++;
            foreach (var childNode in node.ChildNodes)
            {
                childNode.Accept(this);
            }
            _level--;
            _builder.AppendFormat("{0}</{1}>{2}", tab, "set", _lr);
        }
Example #3
0
 public void Visit(BracketNode node)
 {
     var tab = GetTab(_level);
     _builder.AppendFormat("{0}<{1}>{2}", tab, "set", _lr);
     _level++;
     foreach (var childNode in node.ChildNodes)
     {
         childNode.Accept(this);
     }
     _level--;
     _builder.AppendFormat("{0}</{1}>{2}", tab, "set", _lr);
 }
Example #4
0
 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;
     }
 }
Example #5
0
        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;
            }
        }