blob: fd60f3a156d942028202432de6779819d6b88a32 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
/*
* Copyright (c) 2021, the SerenityOS developers.
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibCore/File.h>
#include <LibCpp/Preprocessor.h>
int main(int, char**)
{
auto file = Core::File::construct("/home/anon/Source/little/other.h");
if (!file->open(Core::OpenMode::ReadOnly)) {
perror("open");
exit(1);
}
auto content = file->read_all();
Cpp::Preprocessor cpp("other.h", StringView { content });
auto tokens = cpp.process_and_lex();
outln("Definitions:");
for (auto& definition : cpp.definitions()) {
if (definition.value.parameters.is_empty())
outln("{}: {}", definition.key, definition.value.value);
else
outln("{}({}): {}", definition.key, String::join(",", definition.value.parameters), definition.value.value);
}
outln("");
for (auto& token : tokens) {
dbgln("{}", token.to_string());
}
}
|