From 1d0d0e9d0015a18b5c6538a87ba41dcb19d04b03 Mon Sep 17 00:00:00 2001 From: AnotherTest Date: Sun, 10 May 2020 11:47:12 +0430 Subject: [PATCH] Shell: Parse comments --- Shell/Parser.cpp | 13 +++++++++++++ Shell/Parser.h | 1 + Shell/main.cpp | 6 ++++++ 3 files changed, 20 insertions(+) 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 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 process_arguments(const Vector& args) { Vector 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");