Skip to content

Commit

Permalink
refactor: Extract pipe from parser (#4732)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored Jul 14, 2024
1 parent 26fa0ad commit e984c0f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 3 additions & 6 deletions prqlc/prqlc-parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ use crate::parser::types::type_expr;
use crate::parser::{ctrl, ident_part, keyword, new_line, sequence, with_doc_comment};
use crate::span::Span;

use super::pipe;

pub(crate) fn expr_call() -> impl Parser<TokenKind, Expr, Error = PError> + Clone {
let expr = expr();

Expand Down Expand Up @@ -262,11 +264,6 @@ where
// expr has to be a param, because it can be either a normal expr() or a
// recursive expr called from within expr(), which causes a stack overflow

let pipe = choice((
ctrl('|').ignored(),
new_line().repeated().at_least(1).ignored(),
));

with_doc_comment(
new_line().repeated().ignore_then(
ident_part()
Expand All @@ -276,7 +273,7 @@ where
.map(|(alias, expr)| Expr { alias, ..expr }),
),
)
.separated_by(pipe)
.separated_by(pipe())
.at_least(1)
.map_with_span(|exprs, span| {
// If there's only one expr, then we don't need to wrap it
Expand Down
6 changes: 6 additions & 0 deletions prqlc/prqlc-parser/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ where
.padded_by(new_line().repeated())
}

fn pipe() -> impl Parser<TokenKind, (), Error = PError> + Clone {
ctrl('|')
.ignored()
.or(new_line().repeated().at_least(1).ignored())
}

#[cfg(test)]
mod tests {
use insta::assert_debug_snapshot;
Expand Down

0 comments on commit e984c0f

Please sign in to comment.