mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-15 11:08:31 +00:00
Validate parse nodes correspond to expected tokens (#3295)
Can specify which tokens are allowed generally, and any additional tokens that only occur when the parse node has an error. --------- Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
1 parent
95a1cc8cba
commit
a112f2e802
16 files changed
+312
-113
No files matched your search
@@ -58,6 +58,7 @@ Context::Context(Tree& tree, Lex::TokenizedBuffer& tokens,
|
||||
|
||||
auto Context::AddLeafNode(NodeKind kind, Lex::Token token, bool has_error)
|
||||
-> void {
|
||||
CheckNodeMatchesLexerToken(kind, tokens_->GetKind(token), has_error);
|
||||
tree_->node_impls_.push_back(
|
||||
Tree::NodeImpl(kind, has_error, token, /*subtree_size=*/1));
|
||||
if (has_error) {
|
||||
@@ -67,6 +68,7 @@ auto Context::AddLeafNode(NodeKind kind, Lex::Token token, bool has_error)
|
||||
|
||||
auto Context::AddNode(NodeKind kind, Lex::Token token, int subtree_start,
|
||||
bool has_error) -> void {
|
||||
CheckNodeMatchesLexerToken(kind, 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));
|
||||
|
||||
Reference in new issue
Block a user