Skip to content

Commit 7b03113

Browse files
committed
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.
1 parent 93413f8 commit 7b03113

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

Userland/Shell/PosixLexer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,9 +581,13 @@ ErrorOr<Lexer::ReductionResult> Lexer::reduce_start()
581581
m_state.on_new_line = true;
582582

583583
m_state.buffer.clear();
584+
m_state.position.start_offset = m_state.position.end_offset;
585+
m_state.position.start_line = m_state.position.end_line;
586+
587+
Vector<Token> tokens { move(token), Token::newline() };
584588

585589
return ReductionResult {
586-
.tokens = { move(token) },
590+
.tokens = move(tokens),
587591
.next_reduction = Reduction::Start,
588592
};
589593
}

Userland/Shell/PosixLexer.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ struct Token {
321321
return Token::Type::Great;
322322
if (name == "<"sv)
323323
return Token::Type::Less;
324+
if (name == "\n"sv)
325+
return Token::Type::Newline;
324326

325327
return {};
326328
}

Userland/Shell/PosixParser.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,9 @@ ErrorOr<RefPtr<AST::Node>> Parser::parse_list()
698698

699699
ErrorOr<RefPtr<AST::Node>> Parser::parse_and_or()
700700
{
701+
while (peek().type == Token::Type::Newline)
702+
skip();
703+
701704
auto node = TRY(parse_pipeline());
702705
if (!node)
703706
return RefPtr<AST::Node> {};

Userland/Shell/PosixParser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Parser {
5454
{
5555
if (eof())
5656
return;
57+
handle_heredoc_contents();
5758
m_token_index++;
5859
}
5960
bool eof() const

0 commit comments

Comments
 (0)