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); }
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; }
/// <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); MySQL51Lexer lexer = new MySQL51Lexer(input); 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; }