コード例 #1
0
 internal TSQLSystemIdentifier(
     int beginPosition,
     string text) :
     base(
         beginPosition,
         text)
 {
     Identifier = TSQLIdentifiers.Parse(text);
 }
コード例 #2
0
        public static bool IsIdentifier(this TSQLToken token, TSQLIdentifiers identifier)
        {
            if (token == null)
            {
                return(false);
            }

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

            if (token.AsSystemIdentifier.Identifier != identifier)
            {
                return(false);
            }

            return(true);
        }
コード例 #3
0
 public void Identifiers_ParseNull()
 {
     Assert.AreEqual(TSQLIdentifiers.None, TSQLIdentifiers.Parse(null));
 }
コード例 #4
0
 public void Identifiers_IsNull()
 {
     Assert.IsFalse(TSQLIdentifiers.IsIdentifier(null));
 }
コード例 #5
0
 public void Identifiers_IsFalse()
 {
     Assert.IsFalse(TSQLIdentifiers.IsIdentifier("blah"));
 }
コード例 #6
0
 public void Identifiers_IsTrue()
 {
     Assert.IsTrue(TSQLIdentifiers.IsIdentifier("convert"));
 }
コード例 #7
0
 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));
         }
     }
 }