Exemplo n.º 1
0
 internal TSQLKeyword(
     int beginPostion,
     string text) :
     base(
         beginPostion,
         text)
 {
     Keyword = TSQLKeywords.Parse(text);
 }
Exemplo n.º 2
0
        public ITSQLStatementParser Create(TSQLToken token)
        {
            if (token.Type == TSQLTokenType.Keyword)
            {
                TSQLKeywords keyword = token.AsKeyword.Keyword;

                if (keyword == TSQLKeywords.SELECT)
                {
                    return(new TSQLSelectStatementParser());
                }
                // not fully implemented yet
                //else if (keyword == TSQLKeywords.INSERT)
                //{
                //	return new TSQLInsertStatementParser();
                //}
                //else if (keyword == TSQLKeywords.UPDATE)
                //{
                //	return new TSQLUpdateStatementParser();
                //}
                //else if (keyword == TSQLKeywords.DELETE)
                //{
                //	return new TSQLDeleteStatementParser();
                //}
                //else if (keyword == TSQLKeywords.MERGE)
                //{
                //	return new TSQLMergeStatementParser();
                //}
                //else if (keyword == TSQLKeywords.WITH)
                //{
                //	return new TSQLWithAggregateStatementParser();
                //}
                else
                {
                    return(new TSQLUnknownStatementParser());
                }
            }
            else
            {
                return(new TSQLUnknownStatementParser());

                // not fully implemented yet
                //return new TSQLExecuteStatementParser();
            }
        }
Exemplo n.º 3
0
        public static bool IsKeyword(this TSQLToken token, TSQLKeywords keyword)
        {
            if (token == null)
            {
                return(false);
            }

            if (token.Type != TSQLTokenType.Keyword)
            {
                return(false);
            }

            if (token.AsKeyword.Keyword != keyword)
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 4
0
        public ITSQLStatementParser Create(TSQLToken token)
        {
            if (token.Type == TSQLTokenType.Keyword)
            {
                TSQLKeywords keyword = token.AsKeyword.Keyword;

                if (keyword == TSQLKeywords.SELECT)
                {
                    return(new TSQLSelectStatementParser());
                }
                else
                {
                    return(new TSQLUnknownStatementParser());
                }
            }
            else
            {
                return(new TSQLUnknownStatementParser());

                // TODO: check for an EXEC without the keyword
            }
        }
Exemplo n.º 5
0
        public static bool IsStatementStart(this TSQLKeywords keyword)
        {
            var result = keyword.In(StatementStarts);

            return(result);
        }
Exemplo n.º 6
0
 public static bool IsStatementStart(this TSQLKeywords keyword)
 {
     return(keyword.In(StatementStarts));
 }
 public TSQLToken Parse(
     string tokenValue,
     int startPosition,
     int endPosition,
     bool useQuotedIdentifiers)
 {
     if (
         char.IsWhiteSpace(tokenValue[0]))
     {
         return
             (new TSQLWhitespace(
                  startPosition,
                  tokenValue));
     }
     else if (
         tokenValue[0] == '@')
     {
         if (TSQLVariables.IsVariable(tokenValue))
         {
             return
                 (new TSQLSystemVariable(
                      startPosition,
                      tokenValue));
         }
         else
         {
             return
                 (new TSQLVariable(
                      startPosition,
                      tokenValue));
         }
     }
     else if (tokenValue.StartsWith("--"))
     {
         return
             (new TSQLSingleLineComment(
                  startPosition,
                  tokenValue));
     }
     else if (tokenValue.StartsWith("/*"))
     {
         if (tokenValue.EndsWith("*/"))
         {
             return
                 (new TSQLMultilineComment(
                      startPosition,
                      tokenValue));
         }
         else
         {
             return
                 (new TSQLIncompleteCommentToken(
                      startPosition,
                      tokenValue));
         }
     }
     else if (
         tokenValue.StartsWith("'") ||
         tokenValue.StartsWith("N'"))
     {
         // make sure there's an even number of quotes so that it's closed properly
         if ((tokenValue.Split('\'').Length - 1) % 2 == 0)
         {
             return
                 (new TSQLStringLiteral(
                      startPosition,
                      tokenValue));
         }
         else
         {
             return
                 (new TSQLIncompleteStringToken(
                      startPosition,
                      tokenValue));
         }
     }
     else if (
         !useQuotedIdentifiers &&
         tokenValue.StartsWith("\""))
     {
         // make sure there's an even number of quotes so that it's closed properly
         if ((tokenValue.Split('\"').Length - 1) % 2 == 0)
         {
             return
                 (new TSQLStringLiteral(
                      startPosition,
                      tokenValue));
         }
         else
         {
             return
                 (new TSQLIncompleteStringToken(
                      startPosition,
                      tokenValue));
         }
     }
     else if (
         tokenValue[0] == '$')
     {
         // $IDENTITY
         if (
             tokenValue.Length > 1 &&
             char.IsLetter(tokenValue[1]))
         {
             return
                 (new TSQLSystemColumnIdentifier(
                      startPosition,
                      tokenValue));
         }
         // $45.56
         else
         {
             return
                 (new TSQLMoneyLiteral(
                      startPosition,
                      tokenValue));
         }
     }
     else if (CharUnicodeInfo.GetUnicodeCategory(tokenValue[0]) == UnicodeCategory.CurrencySymbol)
     {
         return
             (new TSQLMoneyLiteral(
                  startPosition,
                  tokenValue));
     }
     else if (tokenValue.StartsWith("0x", StringComparison.OrdinalIgnoreCase))
     {
         return
             (new TSQLBinaryLiteral(
                  startPosition,
                  tokenValue));
     }
     else if (
         char.IsDigit(tokenValue[0]) ||
         (
             tokenValue[0] == '.' &&
             tokenValue.Length > 1 &&
             char.IsDigit(tokenValue[1])
         ))
     {
         return
             (new TSQLNumericLiteral(
                  startPosition,
                  tokenValue));
     }
     else if (
         tokenValue[0] == '=' ||
         tokenValue[0] == '~' ||
         tokenValue[0] == '-' ||
         tokenValue[0] == '+' ||
         tokenValue[0] == '*' ||
         tokenValue[0] == '/' ||
         tokenValue[0] == '<' ||
         tokenValue[0] == '>' ||
         tokenValue[0] == '!' ||
         tokenValue[0] == '&' ||
         tokenValue[0] == '|' ||
         tokenValue[0] == '^' ||
         tokenValue[0] == '%' ||
         tokenValue[0] == ':')
     {
         return
             (new TSQLOperator(
                  startPosition,
                  tokenValue));
     }
     else if (TSQLCharacters.IsCharacter(tokenValue))
     {
         return
             (new TSQLCharacter(
                  startPosition,
                  tokenValue));
     }
     else if (TSQLKeywords.IsKeyword(tokenValue))
     {
         return
             (new TSQLKeyword(
                  startPosition,
                  tokenValue));
     }
     else if (TSQLIdentifiers.IsIdentifier(tokenValue))
     {
         return
             (new TSQLSystemIdentifier(
                  startPosition,
                  tokenValue));
     }
     else
     {
         if (
             (
                 tokenValue.StartsWith("[") &&
                 !tokenValue.EndsWith("]")
             ) ||
             (
                 useQuotedIdentifiers &&
                 tokenValue.StartsWith("\"") &&
                 // see if there's an odd number of quotes
                 (tokenValue.Split('\"').Length - 1) % 2 == 1
             ))
         {
             return
                 (new TSQLIncompleteIdentifierToken(
                      startPosition,
                      tokenValue));
         }
         else
         {
             return
                 (new TSQLIdentifier(
                      startPosition,
                      tokenValue));
         }
     }
 }
Exemplo n.º 8
0
        public static bool IsKeyword(this TSQLToken token, TSQLKeywords keyword)
        {
            if (token == null)
            {
                return false;
            }

            if (token.Type != TSQLTokenType.Keyword)
            {
                return false;
            }

            if (token.AsKeyword.Keyword != keyword)
            {
                return false;
            }

            return true;
        }