Esempio n. 1
0
 public override void Build()
 {
     ClaimColumns(columns);
     by = GetNextToken(TokenType.Keyword, this, "by") as Keyword;
 }
Esempio n. 2
0
        private void Parse()
        {
            string debugAt      = "";
            string word         = "";
            bool   inNumber     = false;
            bool   inString     = false;
            bool   inIdentifier = false;
            bool   inOperator   = false;
            int    wordStart    = -1;

            for (int at = 0; at < sql.Length; at++)
            {
                char c = sql[at];
                debugAt = sql.Substring(at);
                if (inString && c == '\'' && at < sql.Length - 1 && sql[at + 1] == '\'')
                {
                    word += '\'';
                    at++;
                    continue;
                }
                if (c == '\'' && inString)
                {
                    AddParsedToken(new Literal(wordStart, word + c));
                    word     = "";
                    inString = false;
                    continue;
                }
                else if (inNumber && !numberChars.Contains(c))
                {
                    AddParsedToken(new Literal(wordStart, word));
                    inNumber = false;
                }
                else if (inOperator && !operatorChars.Contains(c))
                {
                    AddParsedToken(new Operator(wordStart, word));
                    inOperator = false;
                }
                else if (inIdentifier && !IsIdentifierChar(at))
                {
                    if (Query.keywords.Contains(word))
                    {
                        AddParsedToken(Keyword.CreateKeyword(wordStart, word));
                    }
                    else if (Db.tables.ContainsKey(word))
                    {
                        AddParsedToken(new Table(wordStart, word));
                    }
                    else
                    {
                        AddParsedToken(new Identifier(wordStart, word));
                    }
                    inIdentifier = false;
                }
                if (inOperator == false && inIdentifier == false && inString == false && inNumber == false)
                {
                    wordStart = at;
                    word      = "";
                    if (numberStartChars.Contains(c))
                    {
                        inNumber = true;
                    }
                    else if (operatorChars.Contains(c))
                    {
                        inOperator = true;
                    }
                    else if (IsIdentifierChar(at))
                    {
                        inIdentifier = true;
                    }
                    else if (c == '\'')
                    {
                        inString = true;
                    }
                    else if (punctuationChars.Contains(c))
                    {
                        AddParsedToken(new Punctuation(at, c));
                    }
                }
                if (inOperator || inIdentifier || inString || inNumber)
                {
                    word += c;
                }
            }

            if (inString)
            {
                AddParsedToken(new Literal(wordStart, word));
            }
            else if (inNumber)
            {
                AddParsedToken(new Literal(wordStart, word));
            }
            if (inOperator)
            {
                AddParsedToken(new Operator(wordStart, word));
            }
            if (inIdentifier)
            {
                if (Query.keywords.Contains(word))
                {
                    AddParsedToken(Keyword.CreateKeyword(wordStart, word));
                }
                else if (Db.tables.Keys.Contains(word))
                {
                    AddParsedToken(new Table(wordStart, word));
                }
                else
                {
                    AddParsedToken(new Identifier(wordStart, word));
                }
            }
        }