Skip to content

Commit e9ae6bb

Browse files
committed
bq: handle idents using backticks
1 parent 4b4c31b commit e9ae6bb

1 file changed

Lines changed: 39 additions & 28 deletions

File tree

src/parser.rs

Lines changed: 39 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -271,35 +271,12 @@ impl<'a> Parser<'a> {
271271
}),
272272
// Here `w` is a word, check if it's a part of a multi-part
273273
// identifier, a function call, or a simple identifier:
274-
_ => match self.peek_token() {
275-
Token::LParen | Token::Period => {
276-
let mut id_parts: Vec<Ident> = vec![w.to_ident()];
277-
let mut ends_with_wildcard = false;
278-
while self.consume_token(&Token::Period) {
279-
match self.next_token() {
280-
Token::Word(w) => id_parts.push(w.to_ident()),
281-
Token::Mult => {
282-
ends_with_wildcard = true;
283-
break;
284-
}
285-
unexpected => {
286-
return self
287-
.expected("an identifier or a '*' after '.'", unexpected);
288-
}
289-
}
290-
}
291-
if ends_with_wildcard {
292-
Ok(Expr::QualifiedWildcard(id_parts))
293-
} else if self.consume_token(&Token::LParen) {
294-
self.prev_token();
295-
self.parse_function(ObjectName(id_parts))
296-
} else {
297-
Ok(Expr::CompoundIdentifier(id_parts))
298-
}
299-
}
300-
_ => Ok(Expr::Identifier(w.to_ident())),
301-
},
274+
_ => self.parse_ident(w.to_ident()),
302275
}, // End of Token::Word
276+
Token::BacktickQuotedString(w) => self.parse_ident(Ident {
277+
value: w.clone(),
278+
quote_style: Some('`'),
279+
}),
303280
Token::Mult => Ok(Expr::Wildcard),
304281
tok @ Token::Minus | tok @ Token::Plus => {
305282
let op = if tok == Token::Plus {
@@ -424,6 +401,40 @@ impl<'a> Parser<'a> {
424401
}))
425402
}
426403

404+
pub fn parse_ident(&mut self, ident: Ident) -> Result<Expr, ParserError> {
405+
match self.peek_token() {
406+
Token::LParen | Token::Period => {
407+
let mut id_parts: Vec<Ident> = vec![ident];
408+
let mut ends_with_wildcard = false;
409+
while self.consume_token(&Token::Period) {
410+
match self.next_token() {
411+
Token::Word(w) => id_parts.push(w.to_ident()),
412+
Token::BacktickQuotedString(w) => id_parts.push(Ident {
413+
value: w.clone(),
414+
quote_style: Some('`'),
415+
}),
416+
Token::Mult => {
417+
ends_with_wildcard = true;
418+
break;
419+
}
420+
unexpected => {
421+
return self.expected("an identifier or a '*' after '.'", unexpected);
422+
}
423+
}
424+
}
425+
if ends_with_wildcard {
426+
Ok(Expr::QualifiedWildcard(id_parts))
427+
} else if self.consume_token(&Token::LParen) {
428+
self.prev_token();
429+
self.parse_function(ObjectName(id_parts))
430+
} else {
431+
Ok(Expr::CompoundIdentifier(id_parts))
432+
}
433+
}
434+
_ => Ok(Expr::Identifier(ident)),
435+
}
436+
}
437+
427438
pub fn parse_window_frame_units(&mut self) -> Result<WindowFrameUnits, ParserError> {
428439
match self.next_token() {
429440
Token::Word(w) => match w.keyword {

0 commit comments

Comments
 (0)