1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 10:38:11 +00:00

Shell: Support semicolons for separating commands

This commit is contained in:
Conrad Pankoff 2019-08-30 14:54:05 +10:00 committed by Andreas Kling
parent 3e6a0a0533
commit 6bb6176762
3 changed files with 201 additions and 175 deletions

View file

@ -22,6 +22,13 @@ void Parser::commit_subcommand()
m_subcommands.append({ move(m_tokens), move(m_redirections), {} });
}
void Parser::commit_command()
{
if (m_subcommands.is_empty())
return;
m_commands.append({ move(m_subcommands) });
}
void Parser::do_pipe()
{
m_redirections.append({ Redirection::Pipe, STDOUT_FILENO });
@ -38,7 +45,7 @@ void Parser::begin_redirect_write(int fd)
m_redirections.append({ Redirection::FileWrite, fd });
}
Vector<Subcommand> Parser::parse()
Vector<Command> Parser::parse()
{
for (int i = 0; i < m_input.length(); ++i) {
char ch = m_input.characters()[i];
@ -48,6 +55,12 @@ Vector<Subcommand> Parser::parse()
commit_token();
break;
}
if (ch == ';') {
commit_token();
commit_subcommand();
commit_command();
break;
}
if (ch == '|') {
commit_token();
if (m_tokens.is_empty()) {
@ -140,6 +153,7 @@ Vector<Subcommand> Parser::parse()
}
commit_token();
commit_subcommand();
commit_command();
if (!m_subcommands.is_empty()) {
for (auto& redirection : m_subcommands.last().redirections) {
@ -150,5 +164,5 @@ Vector<Subcommand> Parser::parse()
}
}
return move(m_subcommands);
return move(m_commands);
}