parse.h 1.2 KB

123456789101112131415161718192021222324252627282930313233
  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_EXPLORER_SYNTAX_PARSE_H_
  5. #define CARBON_EXPLORER_SYNTAX_PARSE_H_
  6. #include <string>
  7. #include <variant>
  8. #include "explorer/ast/ast.h"
  9. #include "explorer/base/arena.h"
  10. #include "explorer/base/source_location.h"
  11. #include "llvm/Support/VirtualFileSystem.h"
  12. namespace Carbon {
  13. // Returns the AST representing the contents of the named file, or an error code
  14. // if parsing fails. Allocations go into the provided arena.
  15. auto Parse(llvm::vfs::FileSystem& fs, Nonnull<Arena*> arena,
  16. std::string_view input_file_name, FileKind file_kind,
  17. bool parser_debug) -> ErrorOr<Carbon::AST>;
  18. // Equivalent to `Parse`, but parses the contents of `file_contents`.
  19. // `input_file_name` is used only for reporting source locations, and does
  20. // not need to name a real file.
  21. auto ParseFromString(Nonnull<Arena*> arena, std::string_view input_file_name,
  22. FileKind file_kind, std::string_view file_contents,
  23. bool parser_debug) -> ErrorOr<Carbon::AST>;
  24. } // namespace Carbon
  25. #endif // CARBON_EXPLORER_SYNTAX_PARSE_H_