#pragma once #include #include struct Redirection { enum Type { Pipe, FileWrite, FileWriteAppend, FileRead, }; Type type; int fd { -1 }; int rewire_fd { -1 }; String path {}; }; struct Rewiring { int fd { -1 }; int rewire_fd { -1 }; }; struct Subcommand { Vector args; Vector redirections; Vector rewirings; }; struct Command { Vector subcommands; }; class Parser { public: explicit Parser(const String& input) : m_input(input) { } Vector parse(); private: void commit_token(); void commit_subcommand(); void commit_command(); void do_pipe(); void begin_redirect_read(int fd); void begin_redirect_write(int fd); enum State { Free, InSingleQuotes, InDoubleQuotes, InWriteAppendOrRedirectionPath, InRedirectionPath, }; State m_state { Free }; String m_input; Vector m_commands; Vector m_subcommands; Vector m_tokens; Vector m_redirections; Vector m_token; };