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 EXECUTABLE_SEMANTICS_SYNTAX_PARSE_H_
  5. #define EXECUTABLE_SEMANTICS_SYNTAX_PARSE_H_
  6. #include <string>
  7. #include <variant>
  8. #include "executable_semantics/ast/ast.h"
  9. #include "executable_semantics/common/arena.h"
  10. namespace Carbon {
  11. // This is the code given us by Bison, for now.
  12. using SyntaxErrorCode = int;
  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(Nonnull<Arena*> arena, std::string_view input_file_name, bool trace)
  16. -> std::variant<Carbon::AST, SyntaxErrorCode>;
  17. // Equivalent to `Parse`, but parses the contents of `file_contents`.
  18. // `input_file_name` is used only for reporting source locations, and does
  19. // not need to name a real file.
  20. auto ParseFromString(Nonnull<Arena*> arena, std::string_view input_file_name,
  21. std::string_view file_contents, bool trace)
  22. -> std::variant<Carbon::AST, SyntaxErrorCode>;
  23. } // namespace Carbon
  24. #endif // EXECUTABLE_SEMANTICS_SYNTAX_PARSE_H_