mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:07:35 +00:00
Shell: Correctly handle commands after heredoc contents
Previously we did not emit a newline after the ending heredoc key, which wreaked havoc on the parser logic, leading to parse errors.
This commit is contained in:
parent
93413f8682
commit
7b031138fc
4 changed files with 11 additions and 1 deletions
|
@ -581,9 +581,13 @@ ErrorOr<Lexer::ReductionResult> Lexer::reduce_start()
|
||||||
m_state.on_new_line = true;
|
m_state.on_new_line = true;
|
||||||
|
|
||||||
m_state.buffer.clear();
|
m_state.buffer.clear();
|
||||||
|
m_state.position.start_offset = m_state.position.end_offset;
|
||||||
|
m_state.position.start_line = m_state.position.end_line;
|
||||||
|
|
||||||
|
Vector<Token> tokens { move(token), Token::newline() };
|
||||||
|
|
||||||
return ReductionResult {
|
return ReductionResult {
|
||||||
.tokens = { move(token) },
|
.tokens = move(tokens),
|
||||||
.next_reduction = Reduction::Start,
|
.next_reduction = Reduction::Start,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,6 +321,8 @@ struct Token {
|
||||||
return Token::Type::Great;
|
return Token::Type::Great;
|
||||||
if (name == "<"sv)
|
if (name == "<"sv)
|
||||||
return Token::Type::Less;
|
return Token::Type::Less;
|
||||||
|
if (name == "\n"sv)
|
||||||
|
return Token::Type::Newline;
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -698,6 +698,9 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_list()
|
||||||
|
|
||||||
ErrorOr<RefPtr<AST::Node>> Parser::parse_and_or()
|
ErrorOr<RefPtr<AST::Node>> Parser::parse_and_or()
|
||||||
{
|
{
|
||||||
|
while (peek().type == Token::Type::Newline)
|
||||||
|
skip();
|
||||||
|
|
||||||
auto node = TRY(parse_pipeline());
|
auto node = TRY(parse_pipeline());
|
||||||
if (!node)
|
if (!node)
|
||||||
return RefPtr<AST::Node> {};
|
return RefPtr<AST::Node> {};
|
||||||
|
|
|
@ -54,6 +54,7 @@ private:
|
||||||
{
|
{
|
||||||
if (eof())
|
if (eof())
|
||||||
return;
|
return;
|
||||||
|
handle_heredoc_contents();
|
||||||
m_token_index++;
|
m_token_index++;
|
||||||
}
|
}
|
||||||
bool eof() const
|
bool eof() const
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue