Ejemplo n.º 1
0
        /// <summary>
        /// Removes a token using the enhanced token stream class.
        /// </summary>
        /// <param name="sql"></param>
        /// <param name="snapPos"></param>
        /// <returns></returns>
        private CommonTokenStream RemoveToken(string sql, SnapshotPoint snapPos)
        {
            Version ver = LanguageServiceUtil.GetVersion(LanguageServiceUtil.GetConnection().ServerVersion);
            TokenStreamRemovable tokens = LanguageServiceUtil.GetTokenStream(sql, ver);
            IToken tr       = null;
            int    position = snapPos.Position;

            tokens.Fill();
            if (!char.IsWhiteSpace(snapPos.GetChar()))
            {
                foreach (IToken t in tokens.GetTokens())
                {
                    if ((t.StartIndex <= position) && (t.StopIndex >= position))
                    {
                        tr = t;
                        break;
                    }
                }
                tokens.Remove(tr);
            }
            return(tokens);
        }
Ejemplo n.º 2
0
        private static MySQL51Parser.program_return DoParse(
            CommonTokenStream tokens, bool expectErrors, out StringBuilder sb, Version version)
        {
            MySQLParser parser = new MySQLParser(tokens);

            parser.MySqlVersion = version;
            sb = new StringBuilder();
            TextWriter tw = new StringWriter(sb);

            parser.TraceDestination = tw;
            MySQL51Parser.program_return r = null;
            int tokCount = tokens.Count;

            try
            {
                r = parser.program();
            }
            catch (RewriteEmptyStreamException e)
            {
                if (!expectErrors)
                {
                    sb.AppendLine();
                    sb.Append(e.Message);
                }
            }

            /*
             * The parser inserts a new <EOF> to the token stream, this is probably an ANTLR bug, the code here takes care of it.
             * */
            if ((tokens.Count - 1) == tokCount)
            {
                TokenStreamRemovable tsr = (TokenStreamRemovable)tokens;
                tsr.Remove(tokens.Get(tokens.Count - 1));
            }
            tokens.Reset();
            return(r);
        }