mirror of
https://github.com/danog/parser.git
synced 2025-01-22 04:51:13 +01:00
parser: support basic heredocs
This commit is contained in:
parent
79a9b07b3c
commit
63446c2b45
@ -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) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user