Skip to content

Commit 7946127

Browse files
committed
rs: allow brackets around idents
1 parent 868ca05 commit 7946127

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

src/ast/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ pub enum Expr {
242242
/// Nested expression e.g. `(foo > bar)` or `(1)`
243243
/// Snowflake allows multiple comma-separated expressions here
244244
Nested(Vec<Expr>),
245+
/// redshift seems to allow brackets around identifiers, e.g.
246+
/// select ["a"] from (select 1 a);
247+
/// We preserve them even though it's not clear that they have any effect
248+
Brackets(Box<Expr>),
245249
/// A literal value, such as string, number, date or NULL
246250
Value(Value),
247251
/// A constant of form `<data_type> 'value'`.
@@ -398,6 +402,7 @@ impl fmt::Display for Expr {
398402
}
399403
write!(f, ")")
400404
}
405+
Expr::Brackets(expr) => write!(f, "[{}]", expr),
401406
Expr::Value(v) => write!(f, "{}", v),
402407
Expr::TypedString { data_type, value } => {
403408
write!(f, "{}", data_type)?;

src/parser.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ impl<'a> Parser<'a> {
339339
self.expect_token(&Token::RParen)?;
340340
Ok(expr)
341341
}
342+
Token::LBracket => {
343+
let ident = self.parse_identifier()?;
344+
self.expect_token(&Token::RBracket)?;
345+
Ok(Expr::Brackets(Box::new(Expr::Identifier(ident))))
346+
}
342347
unexpected => self.expected("an expression", unexpected),
343348
}?;
344349

0 commit comments

Comments
 (0)