mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:38:11 +00:00
Shell: Move the Shell to a separate directory and let's call it "Shell" :^)
This commit is contained in:
parent
e63cc38861
commit
fe73543d41
7 changed files with 217 additions and 180 deletions
46
Shell/Parser.h
Normal file
46
Shell/Parser.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/AKString.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
struct Redirection {
|
||||
enum Type { Pipe, FileWrite, 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,
|
||||
InRedirectionPath,
|
||||
};
|
||||
State m_state { Free };
|
||||
String m_input;
|
||||
|
||||
Vector<Subcommand> m_subcommands;
|
||||
Vector<String> m_tokens;
|
||||
Vector<Redirection> m_redirections;
|
||||
Vector<char> m_token;
|
||||
};
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue