parser: support basic heredocs

This commit is contained in:
Ryan Chandler 2022-12-04 09:26:37 +00:00
parent 79a9b07b3c
commit 63446c2b45
No known key found for this signature in database
GPG Key ID: F113BCADDB3B0CCA

View File

@ -967,7 +967,7 @@ impl Parser {
e
}
TokenKind::StringPart(_) => self.interpolated_string(state)?,
TokenKind::StartHeredoc(_) => self.interpolated_string(state)?,
TokenKind::StartHeredoc(_) => self.heredoc_string(state)?,
TokenKind::True => {
let e = Expression::Bool { value: true };
state.next();
@ -1488,6 +1488,22 @@ impl Parser {
Ok(Expression::InterpolatedString { parts })
}
fn heredoc_string(&self, state: &mut State) -> ParseResult<Expression> {
state.next();
let mut parts = Vec::new();
while ! matches!(state.current.kind, TokenKind::EndHeredoc(_)) {
if let Some(part) = self.interpolated_string_part(state)? {
parts.push(part);
}
}
state.next();
Ok(Expression::InterpolatedString { parts })
}
fn interpolated_string_part(&self, state: &mut State) -> ParseResult<Option<StringPart>> {
Ok(match &state.current.kind {
TokenKind::StringPart(s) => {