Esempio n. 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);
        }
        public static Boolean ScanKeywordOrIdentifier(SlidingTextWindow TextWindow, out SyntaxToken xoToken)
        {
            // Found some valid identifier
            if (ScanIdentifier(TextWindow, out xoToken))
            {
                SyntaxKind eNewType = SyntaxKindUtilities.GetKindFromString(xoToken.RawSQLText);
                //SyntaxKind eNewType = SyntaxKindConverter.ConvertKeywordIntoSyntaxKind(xoToken.RawSQLText);

                // If it is not a core keyword then presume its an identifier
                xoToken.ExpectedType = eNewType != SyntaxKind.UnknownNode ? eNewType : SyntaxKind.IdentifierToken;

                return(true);
            }

            // No identifier could be generated
            return(false);
        }