Example #1
0
        /// <summary>
        /// This is very unsafe as everything is converted to Upper
        /// before the conversion (ie. it matches against any case)
        /// </summary>
        /// <param name="xoTrivia"></param>
        /// <returns></returns>
        private static Boolean ScanTriviaForKeywords(
            ParsingContext xoContext,
            SyntaxTrivia xoTrivia,
            out List <ISyntax> xaoReturnList)
        {
            // Initialise the out var
            xaoReturnList = new List <ISyntax>();

            // Exit early if invalid argument passed
            if (xoTrivia == null)
            {
                return(false);
            }

            // Break apart the trivia text
            String[] asTriviaTextTokens = xoTrivia.RawSQLText.Split();

            // Start looping through the trivia text
            for (int iIndex = 0; iIndex < asTriviaTextTokens.Length; iIndex++)
            {
                // For each string in the Comment/Trivia
                String     sLoopingVar   = asTriviaTextTokens[iIndex];
                SyntaxKind ePossibleKind = SyntaxKindUtilities.GetKindFromString(sLoopingVar); // Try and get a kind

                // If we have a positive match
                if (ePossibleKind != SyntaxKind.UnknownNode)
                {
                    // Mayfly
                    SyntaxToken oToken = new SyntaxToken(ePossibleKind, sLoopingVar);

                    // If we can consume this node (it is something we expect)
                    if (xoContext.CurrentNode.CanConsumeNode(
                            new ParsingContext(xoContext.CurrentNode,
                                               new SyntaxList(oToken)),
                            false) == CanConsumeResult.Consume)
                    {
                        // Create tokens from everything beyond this Keyword we can use (because they will most likely be
                        // a part of the new keyword)
                        String sRemainingText = String.Join(" ", asTriviaTextTokens.Skip(iIndex));
                        xoTrivia.RawSQLText = String.Join(" ", asTriviaTextTokens.Take(iIndex));

                        // Start lexing the rest of the terms
                        SyntaxLexer oLexer = new SyntaxLexer(new SlidingTextWindow(sRemainingText));

                        // Add the new tokens to our list
                        while (oLexer.HasTokensLeftToProcess())
                        {
                            xaoReturnList.Add(oLexer.LexNextToken());
                        }
                    }
                }
            }

            return(xaoReturnList.Count > 0);
        }
Example #2
0
        /// <summary>
        /// Container method for any cumbersome initialisation methods
        /// </summary>
        private void Initialise()
        {
            // Generate a list of tokens from the available text
            while (oLexer.HasTokensLeftToProcess())
            {
                // Add any tokens found into our list
                TokenList.Add(oLexer.LexNextToken());
            }

            // make sure we have an EOF at the end
            if (TokenList[TokenList.Count - 1].ExpectedType != SyntaxKind.EOFNode)
            {
                TokenList.Add(new SyntaxToken(SyntaxKind.EOFNode, ""));
            }
        }