2021-08-20 15:05:11 +03:00
|
|
|
/*
|
2022-09-14 11:24:13 +01:00
|
|
|
* Copyright (c) 2021-2022, the SerenityOS developers.
|
2021-08-20 15:05:11 +03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
2022-09-14 11:24:13 +01:00
|
|
|
#include <AK/Try.h>
|
2021-08-20 15:05:11 +03:00
|
|
|
#include <LibCore/ArgsParser.h>
|
2022-09-14 11:24:13 +01:00
|
|
|
#include <LibCore/Stream.h>
|
2021-08-20 15:05:11 +03:00
|
|
|
#include <LibCpp/Lexer.h>
|
2021-11-27 21:11:59 +01:00
|
|
|
#include <LibMain/Main.h>
|
2021-08-20 15:05:11 +03:00
|
|
|
|
2021-11-27 21:11:59 +01:00
|
|
|
ErrorOr<int> serenity_main(Main::Arguments arguments)
|
2021-08-20 15:05:11 +03:00
|
|
|
{
|
|
|
|
|
Core::ArgsParser args_parser;
|
2022-09-14 11:24:13 +01:00
|
|
|
StringView path;
|
2021-08-20 15:05:11 +03:00
|
|
|
args_parser.add_positional_argument(path, "Cpp File", "cpp-file", Core::ArgsParser::Required::Yes);
|
2021-11-27 21:11:59 +01:00
|
|
|
args_parser.parse(arguments);
|
2021-08-20 15:05:11 +03:00
|
|
|
|
2022-09-14 11:24:13 +01:00
|
|
|
auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
|
|
|
|
|
auto content = TRY(file->read_all());
|
2021-08-20 15:05:11 +03:00
|
|
|
StringView content_view(content);
|
|
|
|
|
|
|
|
|
|
Cpp::Lexer lexer(content);
|
2021-08-21 16:48:21 +03:00
|
|
|
lexer.lex_iterable([](auto token) {
|
2022-12-06 01:12:49 +00:00
|
|
|
outln("{}", token.to_deprecated_string());
|
2021-08-21 16:48:21 +03:00
|
|
|
});
|
2021-11-27 21:11:59 +01:00
|
|
|
|
|
|
|
|
return 0;
|
2021-08-20 15:05:11 +03:00
|
|
|
}
|