Example #1
0
        /// <summary>
        /// Calls Rule's Parse and adds as child result if succesful.
        /// </summary>
        /// <param name="token"></param>
        /// <returns></returns>
        public TokenParseResult ParseRule(Token token, ParserSettings settings)
        {
            TokenParseResult result = Rule.Parse(token, settings);

            if (result.IsSuccesful)
            {
                SyntaxNode parentNode = new SyntaxNode(Source, token);
                parentNode.Add(result.Node);
                result.Node = parentNode;
            }
            return(result);
        }
Example #2
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);
            }
        }