mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Refactor parser logic into separate files. (#2818)
The goal of this change is to start refactoring the monolithic file into separate files that will hopefully pose fewer conflicts for developers, and make it easier to skip to handling of specific functionality. It additionally addresses a scaling issue with parser.cpp where the file would continue to get larger as more features are added. Switches Parser to a ParserContext, moves handlers to be free functions, and moves the controller logic into ParseTree. parser_handle_states.h does the declarations for handlers and little else; handlers are split out to individual files based on prefix (which is deliberately authored to cluster). A couple things I'm avoiding based on historical discussion are: - Having a subdirectory for all the handlers, such as `toolchain/parser/handlers/call_expression.cpp` - Putting handlers in a namespace, such as `Carbon::ParserHandler::CallExpression`. - The name of `Carbon::ParserHandlerCallExpression` is then necessary to minimize the chance of conflicts with semantics and lowering, where everything can be expected to be named similarly. I'm globbing handlers because it seems hard to see missed ones under this approach -- names are too boilerplate. I think this current setup could be split into target-per-file, but I'm not sure that's needed, so I'd delay until it becomes a build-time issue.
This commit is contained in:
@@ -149,7 +149,7 @@ class ParseTree {
|
||||
[[nodiscard]] auto Verify() const -> ErrorOr<Success>;
|
||||
|
||||
private:
|
||||
friend class Parser;
|
||||
friend class ParserContext;
|
||||
|
||||
// The in-memory representation of data used for a particular node in the
|
||||
// tree.
|
||||
@@ -205,8 +205,8 @@ class ParseTree {
|
||||
static_assert(sizeof(NodeImpl) == 12,
|
||||
"Unexpected size of node implementation!");
|
||||
|
||||
// Wires up the reference to the tokenized buffer. The global `parse` routine
|
||||
// should be used to actually parse the tokens into a tree.
|
||||
// Wires up the reference to the tokenized buffer. The `Parse` function should
|
||||
// be used to actually parse the tokens into a tree.
|
||||
explicit ParseTree(TokenizedBuffer& tokens_arg) : tokens_(&tokens_arg) {
|
||||
// If the tree is valid, there will be one node per token, so reserve once.
|
||||
node_impls_.reserve(tokens_->size());
|
||||
|
||||
Reference in New Issue
Block a user