Inheritance: NodeBase
Exemplo n.º 1
0
        public void Visit(NotNode node)
        {
            var nodes = new LiteralNodeCollection();

            for (var i = 32; i < 126; i++)
            {
                nodes.Add(NodeBuilder.BuildLiteralNode(TokenBuilder.BuildLiteralToken((char)i)));
            }

            INode current = node;

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

            foreach (var expandedNode in Expand(current))
            {
                if (nodes.Contains(expandedNode))
                {
                    nodes.Remove(expandedNode);
                }
            }

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

            nodes[index].Accept(this);
        }
Exemplo n.º 2
0
        public void Visit(NotNode node)
        {
            var tab = GetTab(_level);

            _builder.AppendFormat("{0}<{1}>{2}", tab, "not", _lr);
            _level++;
            foreach (var childNode in node.ChildNodes)
            {
                childNode.Accept(this);
            }
            _level--;
            _builder.AppendFormat("{0}</{1}>{2}", tab, "not", _lr);
        }
Exemplo n.º 3
0
 public void Visit(NotNode node)
 {
     var tab = GetTab(_level);
     _builder.AppendFormat("{0}<{1}>{2}", tab, "not", _lr);
     _level++;
     foreach (var childNode in node.ChildNodes)
     {
         childNode.Accept(this);
     }
     _level--;
     _builder.AppendFormat("{0}</{1}>{2}", tab, "not", _lr);
 }
Exemplo n.º 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;
     }
 }
Exemplo n.º 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;
            }
        }