cpp-lexer.cpp 788 B

1234567891011121314151617181920212223242526272829303132
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibCore/ArgsParser.h>
  7. #include <LibCore/File.h>
  8. #include <LibCpp/Lexer.h>
  9. int main(int argc, char** argv)
  10. {
  11. Core::ArgsParser args_parser;
  12. const char* path = nullptr;
  13. args_parser.add_positional_argument(path, "Cpp File", "cpp-file", Core::ArgsParser::Required::Yes);
  14. args_parser.parse(argc, argv);
  15. auto file = Core::File::construct(path);
  16. if (!file->open(Core::OpenMode::ReadOnly)) {
  17. perror("open");
  18. exit(1);
  19. }
  20. auto content = file->read_all();
  21. StringView content_view(content);
  22. Cpp::Lexer lexer(content);
  23. auto tokens = lexer.lex();
  24. for (auto& token : tokens) {
  25. outln("{}", token.to_string());
  26. }
  27. }