BuildLiteralNode() public static method

public static BuildLiteralNode ( LiteralToken literalToken ) : LiteralNode
literalToken LiteralToken
return LiteralNode
Example #1
0
        private static IEnumerable <LiteralNode> Expand(INode bracketNode)
        {
            foreach (var childNode in bracketNode.ChildNodes)
            {
                switch (childNode.Token.TokenType)
                {
                case TokenType.Literal:
                    yield return((LiteralNode)childNode);

                    break;

                case TokenType.Range:
                    var min = (int)((LiteralNode)childNode.ChildNodes[0]).Token.Character;
                    var max = (int)((LiteralNode)childNode.ChildNodes[1]).Token.Character;
                    for (var i = min; i <= max; i++)
                    {
                        var c = (char)i;
                        yield return(NodeBuilder.BuildLiteralNode(TokenBuilder.BuildLiteralToken(c)));
                    }
                    break;

                case TokenType.BracketRight:
                    foreach (var node in Expand(childNode))
                    {
                        yield return(node);
                    }
                    break;
                }
            }
        }
Example #2
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);
        }