summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-09-16 05:11:09 +0430
committerAndreas Kling <kling@serenityos.org>2020-09-26 21:28:35 +0200
commit6e6be8e56e76a1f7ce6245a4fc62b30fc35ad1ab (patch)
tree8f217957db1ee99df4a29d78440ad65b675340e5
parentd64e00a5f658d6b4798c1522907c5ec61e4a6b09 (diff)
downloadserenity-6e6be8e56e76a1f7ce6245a4fc62b30fc35ad1ab.zip
Shell: Ignore '\\\n' in input
This allows the user to break a line: ```sh $ echo \ foo ``` is the same as ```sh $ echo foo ```
-rw-r--r--Shell/Parser.cpp10
1 files changed, 9 insertions, 1 deletions
diff --git a/Shell/Parser.cpp b/Shell/Parser.cpp
index 1cdb69144e..a38d4a67d7 100644
--- a/Shell/Parser.cpp
+++ b/Shell/Parser.cpp
@@ -35,13 +35,21 @@ char Parser::peek()
return 0;
ASSERT(m_offset < m_input.length());
- return m_input[m_offset];
+
+ auto ch = m_input[m_offset];
+ if (ch == '\\' && m_input.length() > m_offset + 1 && m_input[m_offset + 1] == '\n') {
+ m_offset += 2;
+ return peek();
+ }
+
+ return ch;
}
char Parser::consume()
{
auto ch = peek();
++m_offset;
+
return ch;
}