diff options
author | Conrad Pankoff <deoxxa@fknsrs.biz> | 2019-08-30 14:54:05 +1000 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-01 12:44:33 +0200 |
commit | 6bb6176762d6791e1e8355c7688d813c93fe5d74 (patch) | |
tree | 51357095d545e9d36c87e0ef422ea999fbb1a822 /Shell/Parser.cpp | |
parent | 3e6a0a05338f1bd05276140528a3e15349cbbc2e (diff) | |
download | serenity-6bb6176762d6791e1e8355c7688d813c93fe5d74.zip |
Shell: Support semicolons for separating commands
Diffstat (limited to 'Shell/Parser.cpp')
-rw-r--r-- | Shell/Parser.cpp | 18 |
1 files changed, 16 insertions, 2 deletions
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<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); } |