/// <summary> /// Visits the create procedure. /// </summary> /// <param name="context">The context.</param> /// <returns></returns> public override object VisitCreateProcedure(TSQLParser.CreateProcedureContext context) { // We want the CREATE PROCEDURE to be segmented into pieces so // that the "AS" portion of the procedure sits on a line of its // own. var asTerminal = context.AS().Symbol; // We know that comments are "skipped" and are not visible to use through // the grammar. That's fine, what we care about is the terminal or token // that occurs just prior to this one and just after this one. var nextParseTree = context.procedureBody(); if (nextParseTree.Start.Line == asTerminal.Line) { // this happens when the "AS" is followed by a statement on the same line. // we correct this by placing a carriage return just before the next terminal. InsertBefore(nextParseTree.Start, "\n", false); } if (((context.procedureOptions() != null) && (context.procedureOptions().Stop.Line == asTerminal.Line)) || ((context.procedureParameters() != null) && (context.procedureParameters().Stop.Line == asTerminal.Line)) || (context.qualifiedName().Stop.Line == asTerminal.Line)) { InsertBefore(asTerminal, "\n", false); } // the statementList portion of the block should be wrapped in a BEGIN and END token // this makes downstream processing of the procedure body easier for the PgsqlConverter var procedureBody = context.procedureBody().statementList(); var procedureParts = procedureBody.statement(); if (procedureParts.Length > 1 || procedureParts[0].BEGIN() == null) { InsertAfter(asTerminal, "\nBEGIN", false); InsertAfter(procedureBody, "\nEND;", false); } return(base.VisitCreateProcedure(context)); }
/// <summary> /// Visit a parse tree produced by <see cref="TSQLParser.createProcedure" />. /// </summary> /// <param name="context">The parse tree.</param> /// <returns></returns> /// <return>The visitor result.</return> public override object VisitCreateProcedure(TSQLParser.CreateProcedureContext context) { var procedureParameters = context.procedureParameters(); if (!IsWrappedInParenthesis(procedureParameters)) { if (procedureParameters == null || procedureParameters.procedureParameter().Length == 0) { InsertAfter(context.qualifiedName(), "()", false); } else { InsertAfter(context.qualifiedName(), "\n(", false); InsertAfter(procedureParameters, "\n)", false); } } return(base.VisitCreateProcedure(context)); }