From 6bb6176762d6791e1e8355c7688d813c93fe5d74 Mon Sep 17 00:00:00 2001 From: Conrad Pankoff Date: Fri, 30 Aug 2019 14:54:05 +1000 Subject: Shell: Support semicolons for separating commands --- Shell/Parser.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'Shell/Parser.cpp') diff --git a/Shell/Parser.cpp b/Shell/Parser.cpp index dd85237fda..31ce752f9b 100644 --- a/Shell/Parser.cpp +++ b/Shell/Parser.cpp @@ -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 Parser::parse() +Vector Parser::parse() { for (int i = 0; i < m_input.length(); ++i) { char ch = m_input.characters()[i]; @@ -48,6 +55,12 @@ Vector 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 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 Parser::parse() } } - return move(m_subcommands); + return move(m_commands); } -- cgit v1.2.3