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; }
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; try { r = parser.program(); } catch (RewriteEmptyStreamException e) { if (!expectErrors) { sb.AppendLine(); sb.Append(e.Message); } } return r; }
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); }
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; }