Skip to content

Commit c345830

Browse files
no space is required after #include
1 parent bb7e32f commit c345830

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

cppparser/src/parser.l

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ This context starts after #if, #elif, and #pragma to capture everyting till a ne
846846
RETURN(tknUndef);
847847
}
848848

849-
<ctxPreprocessor>include/{WS} {
849+
<ctxPreprocessor>include/{TS} {
850850
LOG();
851851
ENDCONTEXT();
852852
setupToken();

cppparser/test/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ set(TEST_SNIPPET_EMBEDDED_TESTS
3737
${CMAKE_CURRENT_LIST_DIR}/unit/expr-test.cpp
3838
${CMAKE_CURRENT_LIST_DIR}/unit/initializer-list-test.cpp
3939
${CMAKE_CURRENT_LIST_DIR}/unit/namespace-test.cpp
40+
${CMAKE_CURRENT_LIST_DIR}/unit/preprocessor-test.cpp
4041
${CMAKE_CURRENT_LIST_DIR}/unit/template-test.cpp
4142
${CMAKE_CURRENT_LIST_DIR}/unit/uniform-init-test.cpp
4243
${CMAKE_CURRENT_LIST_DIR}/unit/vardecl-test.cpp
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (C) 2022 Satya Das and CppParser contributors
2+
// SPDX-License-Identifier: MIT
3+
4+
#include <catch/catch.hpp>
5+
6+
#include "cppparser/cppparser.h"
7+
8+
#include "embedded-snippet-test-base.h"
9+
10+
#include <string>
11+
12+
class ProprocessorTest : public EmbeddedSnippetTestBase
13+
{
14+
protected:
15+
ProprocessorTest()
16+
: EmbeddedSnippetTestBase(__FILE__)
17+
{
18+
}
19+
};
20+
21+
TEST_CASE_METHOD(ProprocessorTest, "include<iostream>", "[preprocessor]")
22+
{
23+
// clang-format off
24+
#if TEST_CASE_SNIPPET_STARTS_FROM_NEXT_LINE
25+
# if EVADE_COMPILER
26+
# include<iostream>
27+
# endif
28+
#endif
29+
// clang-format on
30+
auto testSnippet = getTestSnippetParseStream(__LINE__ - 3);
31+
32+
cppparser::CppParser parser;
33+
const auto ast = parser.parseStream(testSnippet.data(), testSnippet.size());
34+
REQUIRE(ast != nullptr);
35+
36+
const auto members = GetAllOwnedEntities(*ast);
37+
const auto hashInclude = cppast::CppConstPreprocessorIncludeEPtr(members[1]);
38+
REQUIRE(hashInclude);
39+
CHECK(hashInclude->name() == "<iostream>");
40+
}

0 commit comments

Comments
 (0)