diff options
author | AnotherTest <ali.mpfard@gmail.com> | 2020-05-10 11:47:12 +0430 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-05-10 10:23:05 +0200 |
commit | 1d0d0e9d0015a18b5c6538a87ba41dcb19d04b03 (patch) | |
tree | a0a9e8c614f8358bcf75b19c97e6ce79dcbfff67 | |
parent | a862c230b16a05ca661c71c47f07df4bb1f9276d (diff) | |
download | serenity-1d0d0e9d0015a18b5c6538a87ba41dcb19d04b03.zip |
Shell: Parse comments
-rw-r--r-- | Shell/Parser.cpp | 13 | ||||
-rw-r--r-- | Shell/Parser.h | 1 | ||||
-rw-r--r-- | Shell/main.cpp | 6 |
3 files changed, 20 insertions, 0 deletions
diff --git a/Shell/Parser.cpp b/Shell/Parser.cpp index e7be78647d..0c1d17eebb 100644 --- a/Shell/Parser.cpp +++ b/Shell/Parser.cpp @@ -86,6 +86,19 @@ Vector<Command> Parser::parse() char ch = m_input.characters()[i]; switch (state()) { 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 == ' ') { commit_token(Token::Bare); break; diff --git a/Shell/Parser.h b/Shell/Parser.h index b284dd33a2..65f3ef44f7 100644 --- a/Shell/Parser.h +++ b/Shell/Parser.h @@ -36,6 +36,7 @@ struct Token { DoubleQuoted, UnterminatedSingleQuoted, UnterminatedDoubleQuoted, + Comment, Special, }; String text; diff --git a/Shell/main.cpp b/Shell/main.cpp index c4edf60e7b..03077cf64e 100644 --- a/Shell/main.cpp +++ b/Shell/main.cpp @@ -782,6 +782,9 @@ static Vector<String> process_arguments(const Vector<Token>& args) { Vector<String> argv_string; for (auto& arg : args) { + if (arg.type == Token::Comment) + continue; + // This will return the text passed in if it wasn't a variable // This lets us just loop over its values auto expanded_parameters = expand_parameters(arg.text); @@ -863,6 +866,9 @@ static ExitCodeOrContinuationRequest run_command(const StringView& cmd) case Token::Special: dbgprintf("<%s> ", arg.text.characters()); break; + case Token::Comment: + dbgprintf("<%s> ", arg.text.characters()); + break; } } dbgprintf("\n"); |