mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-19 05:30:19 +00:00
feat: Support escaped string literals (PostgreSQL) (#502)
* feat: Support escaped string literals (PostgreSQL) Signed-off-by: Dmitry Patsura <talk@dmtry.me> * lint * escape ', \r, \t * Update src/ast/value.rs Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> * Update src/tokenizer.rs Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org> * test: two slashes * remove dead code * test: parsing error * support generic dialect too (for DF) Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
4070f3ec6e
commit
2c0886d9fe
4 changed files with 167 additions and 0 deletions
|
@ -497,6 +497,11 @@ impl<'a> Parser<'a> {
|
|||
expr: Box::new(self.parse_subexpr(Self::PLUS_MINUS_PREC)?),
|
||||
})
|
||||
}
|
||||
Token::EscapedStringLiteral(_) if dialect_of!(self is PostgreSqlDialect | GenericDialect) =>
|
||||
{
|
||||
self.prev_token();
|
||||
Ok(Expr::Value(self.parse_value()?))
|
||||
}
|
||||
Token::Number(_, _)
|
||||
| Token::SingleQuotedString(_)
|
||||
| Token::NationalStringLiteral(_)
|
||||
|
@ -902,6 +907,7 @@ impl<'a> Parser<'a> {
|
|||
None
|
||||
}
|
||||
Token::SingleQuotedString(_)
|
||||
| Token::EscapedStringLiteral(_)
|
||||
| Token::NationalStringLiteral(_)
|
||||
| Token::HexStringLiteral(_) => Some(Box::new(self.parse_expr()?)),
|
||||
unexpected => {
|
||||
|
@ -2576,6 +2582,7 @@ impl<'a> Parser<'a> {
|
|||
},
|
||||
Token::SingleQuotedString(ref s) => Ok(Value::SingleQuotedString(s.to_string())),
|
||||
Token::NationalStringLiteral(ref s) => Ok(Value::NationalStringLiteral(s.to_string())),
|
||||
Token::EscapedStringLiteral(ref s) => Ok(Value::EscapedStringLiteral(s.to_string())),
|
||||
Token::HexStringLiteral(ref s) => Ok(Value::HexStringLiteral(s.to_string())),
|
||||
Token::Placeholder(ref s) => Ok(Value::Placeholder(s.to_string())),
|
||||
unexpected => self.expected("a value", unexpected),
|
||||
|
@ -2607,6 +2614,9 @@ impl<'a> Parser<'a> {
|
|||
match self.next_token() {
|
||||
Token::Word(Word { value, keyword, .. }) if keyword == Keyword::NoKeyword => Ok(value),
|
||||
Token::SingleQuotedString(s) => Ok(s),
|
||||
Token::EscapedStringLiteral(s) if dialect_of!(self is PostgreSqlDialect | GenericDialect) => {
|
||||
Ok(s)
|
||||
}
|
||||
unexpected => self.expected("literal string", unexpected),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue