1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-30 21:58:10 +00:00

Shell: Parse comments

This commit is contained in:
AnotherTest 2020-05-10 11:47:12 +04:30 committed by Andreas Kling
parent a862c230b1
commit 1d0d0e9d00
3 changed files with 20 additions and 0 deletions

View file

@ -86,6 +86,19 @@ Vector<Command> Parser::parse()
char ch = m_input.characters()[i]; char ch = m_input.characters()[i];
switch (state()) { switch (state()) {
case State::Free: case State::Free:
if (ch == '#') {
commit_token(Token::Bare);
while (i < m_input.length()) {
ch = m_input.characters()[++i];
++m_position;
if (ch == '\n')
break;
m_token.append(ch);
}
commit_token(Token::Comment);
break;
}
if (ch == ' ') { if (ch == ' ') {
commit_token(Token::Bare); commit_token(Token::Bare);
break; break;

View file

@ -36,6 +36,7 @@ struct Token {
DoubleQuoted, DoubleQuoted,
UnterminatedSingleQuoted, UnterminatedSingleQuoted,
UnterminatedDoubleQuoted, UnterminatedDoubleQuoted,
Comment,
Special, Special,
}; };
String text; String text;

View file

@ -782,6 +782,9 @@ static Vector<String> process_arguments(const Vector<Token>& args)
{ {
Vector<String> argv_string; Vector<String> argv_string;
for (auto& arg : args) { for (auto& arg : args) {
if (arg.type == Token::Comment)
continue;
// This will return the text passed in if it wasn't a variable // This will return the text passed in if it wasn't a variable
// This lets us just loop over its values // This lets us just loop over its values
auto expanded_parameters = expand_parameters(arg.text); auto expanded_parameters = expand_parameters(arg.text);
@ -863,6 +866,9 @@ static ExitCodeOrContinuationRequest run_command(const StringView& cmd)
case Token::Special: case Token::Special:
dbgprintf("<%s> ", arg.text.characters()); dbgprintf("<%s> ", arg.text.characters());
break; break;
case Token::Comment:
dbgprintf("<%s> ", arg.text.characters());
break;
} }
} }
dbgprintf("\n"); dbgprintf("\n");