Case insensitive implementation of an input stream.
Inheritance: Antlr.Runtime.ANTLRInputStream
コード例 #1
0
 /// <summary>
 /// Removes a token using the enhanced token stream class.
 /// </summary>
 /// <param name="sql"></param>
 /// <param name="position"></param>
 /// <returns></returns>
 private CommonTokenStream RemoveToken(string sql, SnapshotPoint snapPos)
 {
   MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql));
   CaseInsensitiveInputStream input = new CaseInsensitiveInputStream(ms);
   //ANTLRInputStream input = new ANTLRInputStream(ms);
   Version ver = LanguageServiceUtil.GetVersion(LanguageServiceUtil.GetConnection().ServerVersion);
   MySQLLexer lexer = new MySQLLexer(input);
   lexer.MySqlVersion = ver;
   TokenStreamRemovable tokens = new TokenStreamRemovable(lexer);      
   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;
 }    
コード例 #2
0
ファイル: Utility.cs プロジェクト: eeeee/mysql-connector-net
 public static MySQL51Parser.program_return ParseSql(string sql, bool expectErrors, out StringBuilder sb, Version version )
 {
   // The grammar supports upper case only
   MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql/*.ToUpper() */));
   CaseInsensitiveInputStream input = new CaseInsensitiveInputStream(ms);
   //ANTLRInputStream input = new ANTLRInputStream(ms);
   MySQLLexer lexer = new MySQLLexer(input);
   lexer.MySqlVersion = version;
   CommonTokenStream tokens = new CommonTokenStream(lexer);
   MySQLParser parser = new MySQLParser(tokens);
   parser.MySqlVersion = version;
   sb = new StringBuilder();
   TextWriter tw = new StringWriter(sb);
   parser.TraceDestination = tw;
   MySQL51Parser.program_return r = parser.program();
   if (!expectErrors)
   {
     if (0 != parser.NumberOfSyntaxErrors)
       Assert.AreEqual("", sb.ToString());
     //Assert.AreEqual( 0, parser.NumberOfSyntaxErrors);
   }
   else
   {
     Assert.AreNotEqual(0, parser.NumberOfSyntaxErrors);
   }
   return r;
 }
コード例 #3
0
 internal static MySQL51Parser.program_return ParseSql(
   string sql, bool expectErrors, out StringBuilder sb, out CommonTokenStream tokensOutput)
 {
   // The grammar supports upper case only
   MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql));
   CaseInsensitiveInputStream input = new CaseInsensitiveInputStream(ms);
   //ANTLRInputStream input = new ANTLRInputStream(ms);
   MySQL51Lexer lexer = new MySQL51Lexer(input);
   CommonTokenStream tokens = new CommonTokenStream(lexer);
   tokensOutput = tokens;
   return DoParse(tokens, expectErrors, out sb);
 }
コード例 #4
0
 private CommonTokenStream RemoveToken(string sql, int position)
 {
   MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql));
   CaseInsensitiveInputStream input = new CaseInsensitiveInputStream(ms);
   //ANTLRInputStream input = new ANTLRInputStream(ms);
   MySQL51Lexer lexer = new MySQL51Lexer(input);
   TokenStreamRemovable tokens = new TokenStreamRemovable(lexer);
   //CommonTokenStream tokens = new CommonTokenStream(lexer);
   IToken tr = null;
   position--;   // we want a zero-based index.
   foreach (IToken t in tokens.GetTokens())
   {
     if ((t.StartIndex <= position) && (t.StopIndex >= position))
     {
       tr = t;
       break;
     }
   }
   tokens.Remove(tr);
   return tokens;
 }
コード例 #5
0
 public void TestTokenRemove()
 {
   string sql = "select *, a, c, d from table1 where a is null";
   MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql));
   CaseInsensitiveInputStream input = new CaseInsensitiveInputStream(ms);
   //ANTLRInputStream input = new ANTLRInputStream(ms);
   MySQLLexer lexer = new MySQLLexer(input);
   MySql.Parser.TokenStreamRemovable tsr = new MySql.Parser.TokenStreamRemovable(lexer);
   tsr.Fill();
   List<IToken> tokens = tsr.GetTokens();
   IToken removed = null;
   foreach( IToken t in tokens )
   {
     if (t.Text == "d")
     {
       removed = t;
       break;
     }
   }
   tsr.Remove(removed);
   tokens = tsr.GetTokens();
 }
コード例 #6
0
 public static string GetRoutineName(string sql)
 {
   MySQL51Parser.program_return r = new MySQL51Parser.program_return();
   StringBuilder sb;
   bool expectErrors = false;
   CommonTokenStream cts;
   
   MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql));
   CaseInsensitiveInputStream input = new CaseInsensitiveInputStream(ms);
   MySQLLexer lexer = new MySQLLexer(input);
   CommonTokenStream tokens = new CommonTokenStream(lexer);
   MySQLParser parser = new MySQLParser(tokens);
   sb = new StringBuilder();
   TextWriter tw = new StringWriter(sb);
   parser.TraceDestination = tw;
   try
   {
     r = parser.program();
   }
   catch (RewriteEmptyStreamException e)
   {
     sb.AppendLine();
     sb.Append(e.Message);
   }
   cts = tokens;
   if (!expectErrors && sb.Length != 0)
   {
     throw new DebugSyntaxException(sb.ToString());
   }
   CommonTree t = (CommonTree)r.Tree;
   if (t.IsNil)
     t = (CommonTree)t.GetChild(0);
   return GetRoutineName(t);
 }
コード例 #7
0
 public MySQL51Parser.program_return ParseSql(string sql, bool expectErrors, out StringBuilder sb, out CommonTokenStream cts)
 {
   Version ver = ParserUtils.GetVersion( _connection.ServerVersion );
   // The grammar supports upper case only
   MemoryStream ms = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(sql));
   CaseInsensitiveInputStream input = new CaseInsensitiveInputStream(ms);
   MySQLLexer lexer = new MySQLLexer(input);
   lexer.MySqlVersion = ver;
   CommonTokenStream tokens = new CommonTokenStream(lexer);
   MySQLParser parser = new MySQLParser(tokens);
   parser.MySqlVersion = ver;
   sb = new StringBuilder();
   TextWriter tw = new StringWriter(sb);
   parser.TraceDestination = tw;
   MySQL51Parser.program_return r = new MySQL51Parser.program_return();
   r.Tree = null;
   try
   {
     r = parser.program();
   }
   catch (RewriteEmptyStreamException e)
   {
     sb.AppendLine();
     sb.Append(e.Message);
   }
   cts = tokens;
   if (!expectErrors && sb.Length != 0)
   {
     throw new DebugSyntaxException(sb.ToString());
   }
   return r;
 }