static public ParserNode Parse(string data, ParserType parserType, bool strict) { switch (parserType) { case ParserType.Balanced: return(BalancedVisitor.Parse(data, strict)); case ParserType.Columns: return(ColumnsVisitor.Parse(data, strict)); case ParserType.CSharp: return(CSharpVisitor.Parse(data, strict)); case ParserType.CSV: return(CSVVisitor.Parse(data, strict)); case ParserType.ExactColumns: return(ExactColumnsVisitor.Parse(data, strict)); case ParserType.HTML: return(HTMLVisitor.Parse(data, strict)); case ParserType.JSON: return(JSONVisitor.Parse(data, strict)); case ParserType.SQL: return(SQLVisitor.Parse(data, strict)); case ParserType.TSV: return(TSVVisitor.Parse(data, strict)); case ParserType.XML: return(XMLVisitor.Parse(data, strict)); default: throw new ArgumentException("Unable to parse this type"); } }
static bool SqlHasInsertWithoutColumnList(string SQL) { SQLVisitor visitor = new SQLVisitor(); // visitor.TolerateTempTables = true; TSql130Parser parser = new TSql130Parser(true); IList <ParseError> errors; var fragment = parser.Parse(new System.IO.StringReader(SQL), out errors); fragment.Accept(visitor); return(visitor.HasInsertWithoutColumnSpecification); }
public SQLVisitor ParseScript(string script) { IList <ParseError> parseErrors; TSqlParser tsqlParser = new TSql140Parser(true); TSqlFragment result; using (var stringReader = new StringReader(script)) { result = tsqlParser.Parse(stringReader, out parseErrors); var myVisitor = new SQLVisitor(); result.Accept(myVisitor); return(myVisitor); } }
public static List <String> GetStatementTargets(string storedProcedureDefinition) { StringReader reader = new StringReader(storedProcedureDefinition); //specify parser for appropriate SQL version var parser = new TSql140Parser(true); IList <ParseError> errors; TSqlFragment sqlFragment = parser.Parse(reader, out errors); if (errors.Count > 0) { throw new Exception("Error parsing stored procedure definition"); } SQLVisitor sqlVisitor = new SQLVisitor(); sqlFragment.Accept(sqlVisitor); return(sqlVisitor.StatementTargets); }
internal PrefSQLModel GetPrefSqlModelFromPreferenceSql(string preferenceSql) { PrefSQLParser parser = new PrefSQLParser(new CommonTokenStream(new PrefSQLLexer(new AntlrInputStream(preferenceSql)))); // An error listener helps to return detailed parser syntax errors ErrorListener listener = new ErrorListener(); parser.AddErrorListener(listener); IParseTree tree = parser.parse(); // PrefSQLModel is built during the visit of the parse tree SQLVisitor visitor = new SQLVisitor {IsNative = _skylineType.IsNative()}; visitor.Visit(tree); PrefSQLModel prefSql = visitor.Model; if (prefSql != null) { prefSql.OriginalPreferenceSql = preferenceSql; } return prefSql; }