mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 03:57:43 +00:00
Shell: Include some metadata in parsed tokens and ask for continuation
This patchset adds some metadata to Parser::parse() which allows the Shell to ask for the rest of a command, if it is not complete. A command is considered complete if it has no trailing pipe, or unterminated string.
This commit is contained in:
parent
2ac3d33c63
commit
a862c230b1
3 changed files with 214 additions and 81 deletions
|
@ -29,6 +29,21 @@
|
|||
#include <AK/String.h>
|
||||
#include <AK/Vector.h>
|
||||
|
||||
struct Token {
|
||||
enum Type {
|
||||
Bare,
|
||||
SingleQuoted,
|
||||
DoubleQuoted,
|
||||
UnterminatedSingleQuoted,
|
||||
UnterminatedDoubleQuoted,
|
||||
Special,
|
||||
};
|
||||
String text;
|
||||
size_t end;
|
||||
size_t length;
|
||||
Type type;
|
||||
};
|
||||
|
||||
struct Redirection {
|
||||
enum Type {
|
||||
Pipe,
|
||||
|
@ -48,7 +63,7 @@ struct Rewiring {
|
|||
};
|
||||
|
||||
struct Subcommand {
|
||||
Vector<String> args;
|
||||
Vector<Token> args;
|
||||
Vector<Redirection> redirections;
|
||||
Vector<Rewiring> rewirings;
|
||||
};
|
||||
|
@ -71,7 +86,7 @@ private:
|
|||
No,
|
||||
Yes,
|
||||
};
|
||||
void commit_token(AllowEmptyToken = AllowEmptyToken::No);
|
||||
void commit_token(Token::Type, AllowEmptyToken = AllowEmptyToken::No);
|
||||
void commit_subcommand();
|
||||
void commit_command();
|
||||
void do_pipe();
|
||||
|
@ -105,7 +120,8 @@ private:
|
|||
|
||||
Vector<Command> m_commands;
|
||||
Vector<Subcommand> m_subcommands;
|
||||
Vector<String> m_tokens;
|
||||
Vector<Token> m_tokens;
|
||||
Vector<Redirection> m_redirections;
|
||||
Vector<char> m_token;
|
||||
size_t m_position { 0 };
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue