ladybird/Userland/Utilities/cpp-lexer.cpp

31 lines
795 B
C++
Raw Normal View History

2021-08-20 15:05:11 +03:00
/*
* Copyright (c) 2021-2022, the SerenityOS developers.
2021-08-20 15:05:11 +03:00
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Try.h>
2021-08-20 15:05:11 +03:00
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
2021-08-20 15:05:11 +03:00
#include <LibCpp/Lexer.h>
2021-11-27 23:11:59 +03:00
#include <LibMain/Main.h>
2021-08-20 15:05:11 +03:00
2021-11-27 23:11:59 +03:00
ErrorOr<int> serenity_main(Main::Arguments arguments)
2021-08-20 15:05:11 +03:00
{
Core::ArgsParser args_parser;
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 23:11:59 +03:00
args_parser.parse(arguments);
2021-08-20 15:05:11 +03:00
auto file = TRY(Core::File::open(path, Core::File::OpenMode::Read));
auto content = TRY(file->read_until_eof());
2021-08-20 15:05:11 +03:00
StringView content_view(content);
Cpp::Lexer lexer(content);
lexer.lex_iterable([](auto token) {
outln("{}", token.to_deprecated_string());
});
2021-11-27 23:11:59 +03:00
return 0;
2021-08-20 15:05:11 +03:00
}