Support parsing Carbon files from strings. (#954)

Also, pass file names as string_view for greater convenience.
This commit is contained in:
Geoff Romer authored and GitHub committed 2021-11-23 10:44:39 -08:00
1 parent 9642d7ad05
commit ec2f8e64e2
4 files changed
+99 -19

No files matched your search

+9 -2
View File
@@ -18,8 +18,15 @@ using SyntaxErrorCode = int;
// Returns the AST representing the contents of the named file, or an error code
// if parsing fails. Allocations go into the provided arena.
auto Parse(Nonnull<Arena*> arena, const std::string& input_file_name,
bool trace) -> std::variant<Carbon::AST, SyntaxErrorCode>;
auto Parse(Nonnull<Arena*> arena, std::string_view input_file_name, bool trace)
-> std::variant<Carbon::AST, SyntaxErrorCode>;
// Equivalent to `Parse`, but parses the contents of `file_contents`.
// `input_file_name` is used only for reporting source locations, and does
// not need to name a real file.
auto ParseFromString(Nonnull<Arena*> arena, std::string_view input_file_name,
std::string_view file_contents, bool trace)
-> std::variant<Carbon::AST, SyntaxErrorCode>;
} // namespace Carbon