summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibCpp/Lexer.cpp
diff options
context:
space:
mode:
authorItamar <itamar8910@gmail.com>2021-08-20 17:00:49 +0300
committerAndreas Kling <kling@serenityos.org>2021-08-21 22:09:56 +0200
commit165a0082c44d304e32bbc47874730afa34e0a4a9 (patch)
treec3d5a068cf43f4cb7c17cd58c85e5c689254f27e /Userland/Libraries/LibCpp/Lexer.cpp
parentfeab5e8a3ebbe3353432927ea6bf151aa6b7d882 (diff)
downloadserenity-165a0082c44d304e32bbc47874730afa34e0a4a9.zip
LibCpp: Allow whitespace between # and preprocessor directive
For example, '# include <stdio.h>' is now supported by the Lexer.
Diffstat (limited to 'Userland/Libraries/LibCpp/Lexer.cpp')
-rw-r--r--Userland/Libraries/LibCpp/Lexer.cpp7
1 files changed, 5 insertions, 2 deletions
diff --git a/Userland/Libraries/LibCpp/Lexer.cpp b/Userland/Libraries/LibCpp/Lexer.cpp
index 2edb5b4863..ea8367d0dc 100644
--- a/Userland/Libraries/LibCpp/Lexer.cpp
+++ b/Userland/Libraries/LibCpp/Lexer.cpp
@@ -528,13 +528,16 @@ Vector<Token> Lexer::lex()
if (ch == '#') {
begin_token();
consume();
+ while (AK::is_ascii_space(peek()))
+ consume();
+ size_t directive_start = m_index;
if (is_valid_first_character_of_identifier(peek()))
while (peek() && is_valid_nonfirst_character_of_identifier(peek()))
consume();
- auto directive = StringView(m_input.characters_without_null_termination() + token_start_index, m_index - token_start_index);
- if (directive == "#include") {
+ auto directive = StringView(m_input.characters_without_null_termination() + directive_start, m_index - directive_start);
+ if (directive == "include"sv) {
commit_token(Token::Type::IncludeStatement);
if (is_ascii_space(peek())) {