mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 18:02:05 -05:00
0dc9af5f7e
Also run it across the whole tree to get everything using the One True Style. We don't yet run this in an automated fashion as it's a little slow, but there is a snippet to do so in makeall.sh.
57 lines
1,012 B
C++
57 lines
1,012 B
C++
#pragma once
|
|
|
|
#include <AK/AKString.h>
|
|
#include <AK/Vector.h>
|
|
|
|
struct Redirection {
|
|
enum Type
|
|
{
|
|
Pipe,
|
|
FileWrite,
|
|
FileWriteAppend,
|
|
FileRead,
|
|
Rewire
|
|
};
|
|
Type type;
|
|
int fd { -1 };
|
|
int rewire_fd { -1 };
|
|
String path {};
|
|
};
|
|
|
|
struct Subcommand {
|
|
Vector<String> args;
|
|
Vector<Redirection> redirections;
|
|
};
|
|
|
|
class Parser {
|
|
public:
|
|
explicit Parser(const String& input)
|
|
: m_input(input)
|
|
{
|
|
}
|
|
|
|
Vector<Subcommand> parse();
|
|
|
|
private:
|
|
void commit_token();
|
|
void commit_subcommand();
|
|
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<Subcommand> m_subcommands;
|
|
Vector<String> m_tokens;
|
|
Vector<Redirection> m_redirections;
|
|
Vector<char> m_token;
|
|
};
|