aharpervc commented on code in PR #1949: URL: https://github.com/apache/datafusion-sqlparser-rs/pull/1949#discussion_r2248411515
########## src/parser/mod.rs: ########## @@ -16464,7 +16505,28 @@ impl<'a> Parser<'a> { /// Parse [Statement::Return] fn parse_return(&mut self) -> Result<Statement, ParserError> { - match self.maybe_parse(|p| p.parse_expr())? { + let rs = self.maybe_parse(|p| { + let expr = p.parse_expr()?; + + match &expr { + Expr::Value(_) + | Expr::Function(_) + | Expr::UnaryOp { .. } + | Expr::BinaryOp { .. } + | Expr::Case { .. } + | Expr::Cast { .. } + | Expr::Convert { .. } + | Expr::Subquery(_) => Ok(expr), + // todo: how to retstrict to variables? Review Comment: I don't see this being about the if statement, but rather about the return statement. The question for the parse is, given a return keyword, how many more tokens (or similarly, which expr's) should be considered part of that ReturnStatement? For T-SQL, there is a restricted answer to that question, but it is somewhat awkward to express here. > if it does support IF statements then the grammar indeed looks either ambiguous or relying on the newline character to differentiate between the two scenarios? Newlines don't really help you here, I put them in the example above for readability, but this should parse identically (and does if you run on a real SQL Server instance): ``` CREATE OR ALTER PROCEDURE example_sp AS IF USER_NAME() = 'X' RETURN IF 1 = 2 RETURN (SELECT 1) RETURN CONVERT(INT, 123) ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org