Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow nested interpolated strings in lexer #4055

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion prqlc/prqlc-parser/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::collections::HashMap;

use chumsky::prelude::*;

use itertools::Itertools;
use prqlc_ast::expr::*;
use prqlc_ast::Span;

Expand Down Expand Up @@ -85,12 +86,15 @@ pub fn expr() -> impl Parser<TokenKind, Expr, Error = PError> + Clone {
|_| Expr::new(ExprKind::Literal(Literal::Null)),
));

// TODO: temporary implementation to keep it working on the new
// interpolation lexer with the old interpolation parser
let interpolation = select! {
TokenKind::Interpolation('s', string) => (ExprKind::SString as fn(_) -> _, string),
TokenKind::Interpolation('f', string) => (ExprKind::FString as fn(_) -> _, string),
}
.validate(|(finish, string), span: ParserSpan, emit| {
match interpolation::parse(string, span + 2) {
match interpolation::parse(string.into_iter().map(|x| x.to_string()).join(""), span + 2)
{
Ok(items) => finish(items),
Err(errors) => {
for err in errors {
Expand Down
4 changes: 3 additions & 1 deletion prqlc/prqlc-parser/src/interpolation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use super::common::{into_expr, PError};
use super::lexer::*;
use super::span::ParserSpan;

use prqlc_ast::expr::InterpolateItem;

/// Parses interpolated strings
pub fn parse(string: String, span_base: ParserSpan) -> Result<Vec<InterpolateItem>, Vec<PError>> {
let res = parser(span_base).parse(string);
let res = parser(span_base).parse(dbg!(string));

match res {
Ok(items) => Ok(items),
Expand Down
Loading
Loading