Ejemplo n.º 1
0
        void IAstNodeInit.Init(AstContext context, ParseTreeNode parseNode)
        {
            NodeName = parseNode.Term == null?GetType().Name : parseNode.Term.Name;

            var tokens = new List <Token>();

            var iToken = parseNode.FindToken();

            if (iToken != null)
            {
                tokens.Add(new Token(iToken.Location.Column, iToken.Location.Line, iToken.Text, iToken.Value));
            }

            var childNodes = new List <ISqlNode>();

            foreach (var childNode in parseNode.ChildNodes)
            {
                ISqlNode child;
                if (childNode.Term is KeyTerm)
                {
                    var childIToken = childNode.FindToken();
                    child = new SqlKeyNode(new Token(childIToken.Location.Column, childIToken.Location.Line, childIToken.Text, childIToken.Value));
                }
                else
                {
                    child = (ISqlNode)childNode.AstNode;
                }

                child = OnChildNode(child);

                if (child != null)
                {
                    if (child is ISqlChildNode)
                    {
                        (child as ISqlChildNode).SetParent(this);
                    }

                    childNodes.Add(child);
                    tokens.AddRange(child.Tokens);
                }
            }

            ChildNodes = childNodes.ToArray();
            Tokens     = tokens.ToArray();

            OnNodeInit();
        }
Ejemplo n.º 2
0
        void IAstNodeInit.Init(AstContext context, ParseTreeNode parseNode)
        {
            NodeName = parseNode.Term == null ? GetType().Name : parseNode.Term.Name;

            var tokens = new List<Token>();

            var iToken = parseNode.FindToken();
            if (iToken != null) {
                tokens.Add(new Token(iToken.Location.Column, iToken.Location.Line, iToken.Text, iToken.Value));
            }

            var childNodes = new List<ISqlNode>();

            foreach (var childNode in parseNode.ChildNodes) {
                ISqlNode child;
                if (childNode.Term is KeyTerm) {
                    var childIToken = childNode.FindToken();
                    child = new SqlKeyNode(new Token(childIToken.Location.Column, childIToken.Location.Line, childIToken.Text, childIToken.Value));
                } else {
                    child = (ISqlNode)childNode.AstNode;
                }

                child = OnChildNode(child);

                if (child != null) {
                    if (child is ISqlChildNode)
                        (child as ISqlChildNode).SetParent(this);

                    childNodes.Add(child);
                    tokens.AddRange(child.Tokens);
                }
            }

            ChildNodes = childNodes.ToArray();
            Tokens = tokens.ToArray();

            OnNodeInit();
        }