parse.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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_PARSE_PARSE_H_
  5. #define CARBON_TOOLCHAIN_PARSE_PARSE_H_
  6. #include "common/ostream.h"
  7. #include "toolchain/diagnostics/diagnostic_emitter.h"
  8. #include "toolchain/lex/tokenized_buffer.h"
  9. #include "toolchain/parse/tree.h"
  10. namespace Carbon::Parse {
  11. struct ParseOptions {
  12. // Options must be set individually, not through initialization.
  13. explicit ParseOptions() = 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, the parse tree will be dumped to this.
  19. llvm::raw_ostream* dump_stream = nullptr;
  20. // When dumping, whether to dump in preorder; otherwise, postorder is used.
  21. bool dump_preorder_parse_tree = false;
  22. };
  23. // Parses the token buffer into a `Tree`.
  24. //
  25. // This is the factory function which is used to build parse trees.
  26. auto Parse(Lex::TokenizedBuffer& tokens, ParseOptions options) -> Tree;
  27. } // namespace Carbon::Parse
  28. #endif // CARBON_TOOLCHAIN_PARSE_PARSE_H_