cpp-lexer.cpp 790 B

123456789101112131415161718192021222324252627282930
  1. /*
  2. * Copyright (c) 2021-2022, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <AK/Try.h>
  7. #include <LibCore/ArgsParser.h>
  8. #include <LibCore/Stream.h>
  9. #include <LibCpp/Lexer.h>
  10. #include <LibMain/Main.h>
  11. ErrorOr<int> serenity_main(Main::Arguments arguments)
  12. {
  13. Core::ArgsParser args_parser;
  14. StringView path;
  15. args_parser.add_positional_argument(path, "Cpp File", "cpp-file", Core::ArgsParser::Required::Yes);
  16. args_parser.parse(arguments);
  17. auto file = TRY(Core::Stream::File::open(path, Core::Stream::OpenMode::Read));
  18. auto content = TRY(file->read_all());
  19. StringView content_view(content);
  20. Cpp::Lexer lexer(content);
  21. lexer.lex_iterable([](auto token) {
  22. outln("{}", token.to_string());
  23. });
  24. return 0;
  25. }