Skip to content

Commit 1402d94

Browse files
committed
Add non-reserved keyword handling to function preprocessing
1 parent 4a69132 commit 1402d94

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

partiql-parser/src/lexer/partiql.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,18 @@ pub enum Token<'input> {
411411
}
412412

413413
impl Token<'_> {
414+
pub fn is_var_non_reserved(&self) -> bool {
415+
matches!(
416+
self,
417+
Token::Acyclic | Token::Any | Token::Simple | Token::Shortest | Token::Trail
418+
)
419+
}
420+
pub fn is_fn_non_reserved(&self) -> bool {
421+
matches!(
422+
self,
423+
Token::Acyclic | Token::Any | Token::Simple | Token::Shortest | Token::Trail
424+
)
425+
}
414426
pub fn is_keyword(&self) -> bool {
415427
matches!(
416428
self,

partiql-parser/src/preprocessor.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ mod built_ins {
131131

132132
pub(crate) fn built_in_aggs() -> FnExpr<'static> {
133133
FnExpr {
134-
// TODO: currently needs to be manually kept in-sync with parsers's `KNOWN_AGGREGATES`
134+
// TODO: currently needs to be manually kept in-sync with parser's `KNOWN_AGGREGATES`
135135
fn_names: vec!["count", "avg", "min", "max", "sum", "any", "some", "every"],
136136
#[rustfmt::skip]
137137
patterns: vec![
@@ -320,10 +320,15 @@ where
320320
#[inline]
321321
fn parse_fn_expr(
322322
&mut self,
323-
(tok, _): BufferedToken<'input>,
323+
(tok, tok_txt): BufferedToken<'input>,
324324
next_idx: usize,
325325
) -> (SpannedToken<'input>, Option<SpannedTokenVec<'input>>) {
326-
if let (_, Token::UnquotedIdent(id) | Token::QuotedIdent(id), _) = tok {
326+
let fn_candidate = match &tok {
327+
(_, Token::UnquotedIdent(id) | Token::QuotedIdent(id), _) => Some(*id),
328+
(_, tok, _) => tok.is_fn_non_reserved().then_some(tok_txt),
329+
};
330+
331+
if let Some(id) = fn_candidate {
327332
if let Some(((_, Token::OpenParen, _), _)) = self.parser.peek_n(next_idx) {
328333
if let Some(fn_expr) = self.fn_exprs.find(id) {
329334
let replacement = match self.rewrite_fn_expr(fn_expr) {

0 commit comments

Comments
 (0)