/// <summary> /// Scans ahead for a possibly Identifier/Alias and returns the value /// if it finds one. if it does find one, it will move the Window accordingly /// </summary> /// <param name="xoToken"></param> /// <param name="xoList"></param> /// <returns></returns> public static String ScanAheadForAlias(SyntaxList xoList) { String sAlias = String.Empty; // SCAN AHEAD - To grab an alias if there is one if (xoList.HasTokensLeftToProcess()) { ISyntax oNextNode = xoList.Peek(); // Explicit if (oNextNode.ExpectedType == SyntaxKind.AsKeyword) { // And the next node after that is an identifier if (xoList.Peek(1).ExpectedType == SyntaxKind.IdentifierToken) { // Alias found sAlias = xoList.Peek(1).RawSQLText; xoList.Pop(2); } } // Implicit else if (oNextNode.ExpectedType == SyntaxKind.IdentifierToken) { // Alias found sAlias = oNextNode.RawSQLText; xoList.Pop(); } } // Return the newly created table node return(sAlias); }
/// <summary> /// Core function for this object. It will attempt to build a source /// program tree from the stored list of tokens /// </summary> /// <returns></returns> public SyntaxNode ParseTree() { // Initialise the Query QuerySyntaxNode oQuery = new QuerySyntaxNode(); // WHILE has tokens to process // Anytime we get here, create a new statement? while (TokenList.HasTokensLeftToProcess()) { // Initialise a new statement every time we get here StatementSyntaxNode oStatement = new StatementSyntaxNode(); // Pull off the first node SyntaxNode CurrentNode = SyntaxNodeFactory.ContextSensitiveConvertTokenToNode(new ParsingContext(oQuery, TokenList)); // If we consumed anything if (CurrentNode.TryConsumeFromContext(new ParsingContext(CurrentNode, TokenList))) { } // Append to the statement anyways oStatement.Add(CurrentNode); oQuery.Add(oStatement); } // Return the Query return(oQuery); }