Refactor NodeKind to take advantage of a parse node only having one token kind. (#3486)

This builds on the series of changes to NodeKinds, aiming to simplify
the NodeKind implementation a little, also making it clearer that
there's a single associated token for each parse node (or, for
placeholders/invalid parses, not validated).

Note that prior to the relevant changes, there were nodes with multiple
tokens. This change is also locking in the approach of one token per
parse node, by refactoring macros to stop supporting multiple.
This commit is contained in:
Jon Ross-Perkins
2023-12-13 21:03:44 +00:00
committed by GitHub
parent 550559e30e
commit add31eb4e3
4 changed files with 190 additions and 262 deletions
+2 -2
View File
@@ -69,7 +69,7 @@ Context::Context(Tree& tree, Lex::TokenizedBuffer& tokens,
auto Context::AddLeafNode(NodeKind kind, Lex::TokenIndex token, bool has_error)
-> void {
CheckNodeMatchesLexerToken(kind, tokens_->GetKind(token), has_error);
kind.CheckMatchesTokenKind(tokens_->GetKind(token), has_error);
tree_->node_impls_.push_back(
Tree::NodeImpl(kind, has_error, token, /*subtree_size=*/1));
if (has_error) {
@@ -79,7 +79,7 @@ auto Context::AddLeafNode(NodeKind kind, Lex::TokenIndex token, bool has_error)
auto Context::AddNode(NodeKind kind, Lex::TokenIndex token, int subtree_start,
bool has_error) -> void {
CheckNodeMatchesLexerToken(kind, tokens_->GetKind(token), has_error);
kind.CheckMatchesTokenKind(tokens_->GetKind(token), has_error);
int subtree_size = tree_->size() - subtree_start + 1;
tree_->node_impls_.push_back(
Tree::NodeImpl(kind, has_error, token, subtree_size));