Ejemplo n.º 1
0
        public static SyntaxNode FactoryCreateNot(ParsingContext xoContext)
        {
            int     iMaxChildCount = 1;
            ISyntax oReturn        = xoContext.List.Pop();

            if (xoContext.List.Peek().ExpectedType == SyntaxKind.InKeyword)
            {
                oReturn.ExpectedType = SyntaxKind.NotInKeyword;
                oReturn.RawSQLText  += " " + xoContext.List.Pop().RawSQLText;
                iMaxChildCount       = 2;
            }
            else if (xoContext.List.Peek().ExpectedType == SyntaxKind.LikeKeyword)
            {
                oReturn.ExpectedType = SyntaxKind.NotLikeKeyword;
                oReturn.RawSQLText  += " " + xoContext.List.Pop().RawSQLText;
                iMaxChildCount       = 2;
            }

            return(new SyntaxNode(oReturn, NodeStrategyFactory.FactoryCreateStrategy(oReturn.ExpectedType), iMaxChildCount));
        }
Ejemplo n.º 2
0
        private static SyntaxNode FactoryCreateCompoundJoin(ParsingContext xoContext)
        {
            // Break early if we got 1 join keyword
            if (xoContext.List.Peek().ExpectedType == SyntaxKind.JoinKeyword)
            {
                // All Join nodes on their own become Inner joins
                SyntaxNode oJoinNode = new SyntaxNode(
                    xoContext.List.Peek(),
                    NodeStrategyFactory.FactoryCreateStrategy(xoContext.List.Pop().ExpectedType),
                    2);
                oJoinNode.ExpectedType = SyntaxKind.InnerJoinKeyword;
                return(oJoinNode);
            }

            // Create the Join Node
            SyntaxNode oTemp = new SyntaxNode(xoContext.List.Peek(),
                                              NodeStrategyFactory.FactoryCreateStrategy(xoContext.List.Pop().ExpectedType));

            // If the next node is actually an OUTER keyword
            if (xoContext.List.Peek().ExpectedType == SyntaxKind.OuterKeyword)
            {
                // Construct a proper Join keyword with the type declared
                oTemp.RawSQLText += " " + xoContext.List.Pop().RawSQLText; // add the text (OUTER)
            }

            // If the next node is actually a Join
            if (xoContext.List.Peek().ExpectedType == SyntaxKind.JoinKeyword)
            {
                // Construct a proper Join keyword with the type declared
                oTemp.RawSQLText += " " + xoContext.List.Pop().RawSQLText; // add the text (JOIN)
            }
            else
            {
                // Add an error
                oTemp.Comments.Add(ErrorMessageLibrary.GetErrorMessage(8000, xoContext.List.Pop().RawSQLText, "JOIN"));
            }
            // Return the Join node
            return(oTemp);
        }
Ejemplo n.º 3
0
 public SyntaxNode(ISyntax xoToken, int xiMaxChildCount = -1) : this(xoToken, NodeStrategyFactory.FactoryCreateStrategy(xoToken.ExpectedType), xiMaxChildCount)
 {
 }
Ejemplo n.º 4
0
 public Symbol(ISyntax xoToken) : this(xoToken, NodeStrategyFactory.FactoryCreateStrategy(xoToken.ExpectedType))
 {
 }
Ejemplo n.º 5
0
 public SymbolList(ISyntax xoToken) : base(xoToken, NodeStrategyFactory.FactoryCreateStrategy(xoToken.ExpectedType))
 {
 }
Ejemplo n.º 6
0
        private static SyntaxNode FactoryCreateColumnOrExpression(ParsingContext xoContext)
        {
            SyntaxKind eNextTokenKind = xoContext.List.Peek().ExpectedType;
            SyntaxNode oReturnNode;

            // Is any identifier or Expression (function/literal)
            if (SyntaxKindFacts.IsFunction(eNextTokenKind))
            {
                // COUNT (*)
                oReturnNode = FactoryCreateColumnFunction(xoContext);
            }
            else if (eNextTokenKind == SyntaxKind.OpenParenthesisToken)
            {
                oReturnNode = FactoryInterpretOpenParenthesisToken(xoContext);
            }
            else if (
                SyntaxKindFacts.IsIdentifier(eNextTokenKind) ||
                SyntaxKindFacts.IsLiteral(eNextTokenKind))
            {
                // Only Column List Nodes can create an Alias
                Boolean bIsAliasNeeded = xoContext.CurrentNode.ExpectedType == SyntaxKind.ColumnListNode &&
                                         eNextTokenKind != SyntaxKind.StarToken; // Stars do not get alias'

                oReturnNode = FactoryCreateColumn(xoContext, bIsAliasNeeded);
            }
            else if (eNextTokenKind == SyntaxKind.CaseKeyword)
            {
                if (xoContext.CurrentNode.ExpectedType == SyntaxKind.ColumnListNode)
                {
                    return(new Symbol(
                               xoContext.List.Peek(),
                               NodeStrategyFactory.FactoryCreateStrategy(xoContext.List.Pop().ExpectedType), -1));
                }
                else
                {
                    return(new SyntaxNode(
                               xoContext.List.Peek(),
                               NodeStrategyFactory.FactoryCreateStrategy(xoContext.List.Pop().ExpectedType)));
                }
            }
            else
            {
                oReturnNode = new SyntaxLeaf(xoContext.List.Pop());
            }

            // If we have a trailing || and we arent already using a bar bar
            if (xoContext.CurrentNode.ExpectedType != SyntaxKind.BarBarToken &&
                xoContext.List.Peek().ExpectedType == SyntaxKind.BarBarToken)
            {
                // Create a new bar bar node (to hold the children)
                SyntaxNode oBarNode = new SyntaxNode(xoContext.List.Pop());

                // Add the child
                oBarNode.Add(oReturnNode);

                // return this collection
                return(oBarNode);
            }
            // Valid case, no fixing necessary
            else
            {
                return(oReturnNode);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Context sensitive conversion which will scan ahead to determine the best candidate
        /// for this node
        /// </summary>
        /// <param name="xoCurrentToken"></param>
        /// <param name="xoList"></param>
        /// <returns></returns>
        public static SyntaxNode ContextSensitiveConvertTokenToNode(
            ParsingContext xoContext)
        {
            SyntaxKind eNextTokenKind = xoContext.List.Peek().ExpectedType;

            // Is any identifier or Expression (function/literal)
            if (SyntaxKindFacts.IsIdentifierOrExpression(eNextTokenKind))
            {
                return(FactoryCreateColumnOrExpression(xoContext));
            }
            else if (SyntaxKindFacts.IsJoinKeyword(eNextTokenKind))
            {
                return(FactoryCreateCompoundJoin(xoContext));
            }
            else
            {
                int iMaxChildCount = -1;

                switch (eNextTokenKind)
                {
                case SyntaxKind.SelectKeyword:
                    break;

                case SyntaxKind.FromKeyword:
                case SyntaxKind.WhereKeyword:
                case SyntaxKind.OnKeyword:
                    iMaxChildCount = 1;
                    break;

                case SyntaxKind.NotKeyword:
                    return(FactoryCreateNot(xoContext));

                    #region Operators
                case SyntaxKind.IsKeyword:
                case SyntaxKind.InKeyword:
                case SyntaxKind.LikeKeyword:
                case SyntaxKind.EqualsToken:
                case SyntaxKind.GreaterThanOrEqualToken:
                case SyntaxKind.GreaterThanToken:
                case SyntaxKind.LessThanOrEqualToToken:
                case SyntaxKind.LessThanToken:
                case SyntaxKind.DiamondToken:
                case SyntaxKind.AndKeyword:
                case SyntaxKind.OrKeyword:
                case SyntaxKind.PlusToken:
                case SyntaxKind.MinusToken:
                case SyntaxKind.SlashToken:
                    iMaxChildCount = 2;
                    break;

                case SyntaxKind.StarToken:
                    // No items in the list to consume (Solitary *)
                    if (xoContext.CurrentNode.Count == 0)
                    {
                        //
                        return(FactoryCreateColumn(xoContext));
                    }
                    else
                    {
                        iMaxChildCount = 2;
                        break;
                    }

                    #endregion

                //case SyntaxKind.CaseKeyword:
                case SyntaxKind.WhenKeyword:
                case SyntaxKind.ThenKeyword:
                case SyntaxKind.ElseKeyword:
                case SyntaxKind.BarBarToken:
                    break;
                }

                return(new SyntaxNode(
                           xoContext.List.Peek(),
                           NodeStrategyFactory.FactoryCreateStrategy(xoContext.List.Pop().ExpectedType),
                           iMaxChildCount)); // Can have multiple children
            }
        }