lex.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. #ifndef CARBON_TOOLCHAIN_LEX_LEX_H_
  5. #define CARBON_TOOLCHAIN_LEX_LEX_H_
  6. #include "toolchain/base/shared_value_stores.h"
  7. #include "toolchain/diagnostics/emitter.h"
  8. #include "toolchain/lex/tokenized_buffer.h"
  9. #include "toolchain/source/source_buffer.h"
  10. namespace Carbon::Lex {
  11. struct LexOptions {
  12. // Options must be set individually, not through initialization.
  13. explicit LexOptions() = default;
  14. // If set, a consumer for diagnostics. Otherwise, diagnostics go to stderr.
  15. Diagnostics::Consumer* consumer = nullptr;
  16. // If set, enables verbose output.
  17. llvm::raw_ostream* vlog_stream = nullptr;
  18. // If set, tokens will be dumped to this.
  19. llvm::raw_ostream* dump_stream = nullptr;
  20. // When dumping, whether to omit `FileStart` and `FileEnd` in output.
  21. bool omit_file_boundary_tokens = false;
  22. };
  23. // Lexes a buffer of source code into a tokenized buffer.
  24. //
  25. // The provided source buffer must outlive any returned `TokenizedBuffer`
  26. // which will refer into the source.
  27. auto Lex(SharedValueStores& value_stores,
  28. SourceBuffer& source [[clang::lifetimebound]], LexOptions options)
  29. -> TokenizedBuffer;
  30. } // namespace Carbon::Lex
  31. #endif // CARBON_TOOLCHAIN_LEX_LEX_H_