Exemplo n.º 1
0
        public MySQLLexer(char[] sql)
        {
            if ((this.sbuf = sbufRef.Value) == null)
            {
                this.sbuf     = new char[1024];
                sbufRef.Value = this.sbuf;
            }

            if (CharTypes.IsWhitespace(sql[sql.Length - 1]))
            {
                this.sql = sql;
            }
            else
            {
                this.sql = new char[sql.Length + 1];
                Array.ConstrainedCopy(sql, 0, this.sql, 0, sql.Length);
            }
            this.eofIndex           = this.sql.Length - 1;
            this.sql[this.eofIndex] = (char)MySQLLexer.EOI;
        }
Exemplo n.º 2
0
        protected void SkipSeparator()
        {
            for (; !IsEof();)
            {
                for (; CharTypes.IsWhitespace(ch); ScanChar())
                {
                    ;
                }

                switch (ch)
                {
                case '#':     // MySQL specified
                    for (; ScanChar() != '\n';)
                    {
                        if (IsEof())
                        {
                            return;
                        }
                    }
                    ScanChar();
                    continue;

                case '/':
                    if (HasChars(2) && '*' == sql[curIndex + 1])
                    {
                        bool commentSkip;
                        if ('!' == sql[curIndex + 2])
                        {
                            ScanChar(3);
                            inCStyleComment       = true;
                            inCStyleCommentIgnore = false;
                            commentSkip           = false;
                            // MySQL use 5 digits to indicate version. 50508 means MySQL 5.5.8
                            if (HasChars(5) &&
                                CharTypes.IsDigit(ch) &&
                                CharTypes.IsDigit(sql[curIndex + 1]) &&
                                CharTypes.IsDigit(sql[curIndex + 2]) &&
                                CharTypes.IsDigit(sql[curIndex + 3]) &&
                                CharTypes.IsDigit(sql[curIndex + 4]))
                            {
                                int version = ch - '0';
                                version *= 10;
                                version += sql[curIndex + 1] - '0';
                                version *= 10;
                                version += sql[curIndex + 2] - '0';
                                version *= 10;
                                version += sql[curIndex + 3] - '0';
                                version *= 10;
                                version += sql[curIndex + 4] - '0';
                                ScanChar(5);
                                if (version > C_STYLE_COMMENT_VERSION)
                                {
                                    inCStyleCommentIgnore = true;
                                }
                            }
                            SkipSeparator();
                        }
                        else
                        {
                            ScanChar(2);
                            commentSkip = true;
                        }

                        if (commentSkip)
                        {
                            for (int state = 0; !IsEof(); ScanChar())
                            {
                                if (state == 0)
                                {
                                    if ('*' == ch)
                                    {
                                        state = 1;
                                    }
                                }
                                else
                                {
                                    if ('/' == ch)
                                    {
                                        ScanChar();
                                        break;
                                    }
                                    else if ('*' != ch)
                                    {
                                        state = 0;
                                    }
                                }
                            }
                            continue;
                        }
                    }
                    return;

                case '-':
                    if (HasChars(3) && '-' == sql[curIndex + 1] && CharTypes.IsWhitespace(sql[curIndex + 2]))
                    {
                        ScanChar(3);
                        for (; !IsEof(); ScanChar())
                        {
                            if ('\n' == ch)
                            {
                                ScanChar();
                                break;
                            }
                        }
                        continue;
                    }
                    break;

                default:
                    return;
                }
            }
        }