s5dsn-eqee commented on code in PR #2469:
URL:
https://github.com/apache/datafusion-sqlparser-rs/pull/2469#discussion_r4421849665
##########
src/parser/mod.rs:
##########
@@ -21043,44 +21048,53 @@ 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,
+ };
+ // SQLite only permits a sign before a number
+ if !matches!(
+ self.peek_token_ref().token,
+ Token::Number(..) | Token::HexNumber(_)
+ ) {
+ return self.expected_ref("number", self.peek_token_ref());
}
+ return Ok(Expr::UnaryOp {
+ op,
+ expr: Box::new(Expr::Value(self.parse_value()?)),
+ });
+ }
+ if matches!(
+ self.peek_token_ref().token,
+ Token::Word(Word {
+ keyword: Keyword::NULL,
+ ..
+ }) | Token::HexStringLiteral(_)
+ ) {
+ return self.expected_ref("number, name or string",
self.peek_token_ref());
+ }
+ match self.try_parse(|parser| parser.parse_value()) {
Review Comment:
might be smt like this?
```
// A bare word that is not a literal (`WAL`, `NORMAL`) is a pragma name.
if let Token::Word(_) = self.peek_token_ref().token {
if let Some(value) = self.maybe_parse(|parser|
parser.parse_value())? {
return Ok(Expr::Value(value));
}
return Ok(Expr::Identifier(self.parse_identifier()?));
}
Ok(Expr::Value(self.parse_value()?))
```
Current approach falls back to parse_identifier on any error, so real
parse_value errors are hidden.
--
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]