private static SyntaxNode FactoryCreateColumnFunction(ParsingContext xoContext) { // generate the item Symbol oColumnExp = new Symbol(xoContext.List.Pop()); // Consume Ahead oColumnExp.TryConsumeFromContext(xoContext); // Assign the alias oColumnExp.Alias = SyntaxNodeFactory.ScanAheadForAlias(xoContext.List); // Return the column return(oColumnExp); }
/// <summary> /// Generates a simple Table Symbol /// </summary> /// <param name="xoList"></param> /// <returns></returns> public static SyntaxNode FactoryCreateTable(ParsingContext xoContext) { ISyntax xoCurrentToken = xoContext.List.Peek(); if (xoCurrentToken.ExpectedType == SyntaxKind.OpenParenthesisToken) { // Subquery start ISyntax oNextToken = xoContext.List.Pop(); oNextToken.ExpectedType = SyntaxKind.IdentifierSubQuerySymbol; // give it a better type // Create a table symbol Symbol oSubquery = new Symbol(oNextToken); return(oSubquery); } SyntaxNode oDatabase; SyntaxNode oSchema; // A Symbol consists of multiple parts SyntaxNode oTable; int iSchemaLocation = 0; int iTableLocation = 0; // Trailing item is a .. (Database) if (xoContext.List.Peek(1).ExpectedType == SyntaxKind.DotDotToken) { iSchemaLocation = -1; iTableLocation = 2; } else if (xoContext.List.Peek(1).ExpectedType == SyntaxKind.DotToken) { iSchemaLocation = 2; iTableLocation = 4; } // Standalone Table else { iSchemaLocation = -1; iTableLocation = 0; } oDatabase = new Symbol(new SyntaxToken(SyntaxKind.IdentifierDatabaseSymbol, iTableLocation != 0 ? xoCurrentToken.RawSQLText : String.Empty)); // Generate the Schema Node oSchema = new Symbol(new SyntaxToken(SyntaxKind.IdentifierSchemaSymbol, iSchemaLocation != -1 ? xoContext.List.Peek(iSchemaLocation).RawSQLText : String.Empty)); oTable = new Symbol(new SyntaxToken(SyntaxKind.IdentifierTableSymbol, xoContext.List.Peek(iTableLocation).RawSQLText)); // create the decorator obj oSchema.Add(oTable); oDatabase.Add(oSchema); // Pop the tokens xoContext.List.Pop(Math.Max(iSchemaLocation, iTableLocation) + 1); // Assign the alias ((Symbol)oTable).Alias = SyntaxNodeFactory.ScanAheadForAlias(xoContext.List); return(oDatabase); }