cpp-preprocessor.cpp 578 B

1234567891011121314151617181920212223
  1. /*
  2. * Copyright (c) 2021, the SerenityOS developers.
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibCore/File.h>
  7. #include <LibCpp/Preprocessor.h>
  8. int main(int, char**)
  9. {
  10. auto file = Core::File::construct("/home/anon/Source/little/other.h");
  11. if (!file->open(Core::OpenMode::ReadOnly)) {
  12. perror("open");
  13. exit(1);
  14. }
  15. auto content = file->read_all();
  16. Cpp::Preprocessor cpp("other.h", StringView { content });
  17. auto tokens = cpp.process_and_lex();
  18. for (auto& token : tokens) {
  19. dbgln("{}", token.to_string());
  20. }
  21. }