mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-09-03 20:50:33 +00:00
Enable dialect specific behaviours in the parser (#254)
* Change `Parser { ... }` to store the dialect used: `Parser<'a> { ... dialect: &'a dyn Dialect }` Thanks to @c7hm4r for the initial version of this submitted as part of https://github.com/ballista-compute/sqlparser-rs/pull/170 * Introduce `dialect_of!(parser is SQLiteDialect | GenericDialect)` helper to branch on the dialect's type * Use the new functionality to make `AUTO_INCREMENT` and `AUTOINCREMENT` parsing dialect-dependent. Co-authored-by: Christoph Müller <pmzqxfmn@runbox.com> Co-authored-by: Nickolay Ponomarev <asqueella@gmail.com>
This commit is contained in:
parent
3871bbc5ee
commit
1b46e82eec
5 changed files with 85 additions and 17 deletions
|
@ -53,7 +53,7 @@ impl TestedDialects {
|
|||
self.one_of_identical_results(|dialect| {
|
||||
let mut tokenizer = Tokenizer::new(dialect, sql);
|
||||
let tokens = tokenizer.tokenize().unwrap();
|
||||
f(&mut Parser::new(tokens))
|
||||
f(&mut Parser::new(tokens, dialect))
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -104,7 +104,9 @@ impl TestedDialects {
|
|||
/// Ensures that `sql` parses as an expression, and is not modified
|
||||
/// after a serialization round-trip.
|
||||
pub fn verified_expr(&self, sql: &str) -> Expr {
|
||||
let ast = self.run_parser_method(sql, Parser::parse_expr).unwrap();
|
||||
let ast = self
|
||||
.run_parser_method(sql, |parser| parser.parse_expr())
|
||||
.unwrap();
|
||||
assert_eq!(sql, &ast.to_string(), "round-tripping without changes");
|
||||
ast
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue