LucaCappelletti94 commented on code in PR #2469:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2469#discussion_r3966602833
##########
src/parser/mod.rs:
##########
@@ -20157,44 +20157,37 @@ impl<'a> Parser<'a> {
})
}
- fn parse_pragma_value(&mut self) -> Result<ValueWithSpan, ParserError> {
- let v = self.parse_value()?;
- match &v.value {
- Value::SingleQuotedString(_) => Ok(v),
- Value::DoubleQuotedString(_) => Ok(v),
- Value::Number(_, _) => Ok(v),
- Value::Placeholder(_) => Ok(v),
- _ => {
- self.prev_token();
- self.expected_ref("number or string or ? placeholder",
self.peek_token_ref())
- }
+ /// Parse a SQLite `pragma-value`: `signed-number | name | signed-literal`.
+ fn parse_pragma_value(&mut self) -> Result<Expr, ParserError> {
+ if matches!(self.peek_token_ref().token, Token::Plus | Token::Minus) {
+ let op = match self.next_token().token {
+ Token::Plus => UnaryOperator::Plus,
+ _ => UnaryOperator::Minus,
+ };
+ return Ok(Expr::UnaryOp {
+ op,
+ expr: Box::new(Expr::Value(self.parse_value()?)),
+ });
+ }
+ match self.maybe_parse(|parser| parser.parse_value())? {
+ Some(value) => Ok(Expr::Value(value)),
+ None => Ok(Expr::Identifier(self.parse_identifier()?)),
}
Review Comment:
In terms of accepting things, yes it would work, but `parse_expr()` would
over-extend the grammar accepting arbitrary expressions like `PRAGMA p = 1 +
2`, `foo(bar)`, `a AND b` or `(SELECT 1)`.
SQLite defines a pragma value as `signed-number | name | signed-literal`, so
`parse_pragma_value` mirrors that production exactly while still leaving the
per-pragma value validation to execution.
I understand I tend to lean much more strongly on the strict parser
approach, but here I really believe allowing any expr would be excessively
loose.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]