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