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:
josh11b
2023-10-13 21:44:51 +00:00
committed by GitHub
co-authored by Richard Smith
parent 95a1cc8cba
commit a112f2e802
16 changed files with 312 additions and 113 deletions
+6
View File
@@ -8,6 +8,7 @@
#include <cstdint>
#include "common/enum_base.h"
#include "toolchain/lex/token_kind.h"
namespace Carbon::Parse {
@@ -44,6 +45,11 @@ class NodeKind : public CARBON_ENUM_BASE(NodeKind) {
// We expect the parse node kind to fit compactly into 8 bits.
static_assert(sizeof(NodeKind) == 1, "Kind objects include padding!");
// Validates that a `parse_node_kind` parser node can be generated for a
// `lex_token_kind` lexer token.
void CheckNodeMatchesLexerToken(NodeKind parse_node_kind,
Lex::TokenKind lex_token_kind, bool has_error);
} // namespace Carbon::Parse
#endif // CARBON_TOOLCHAIN_PARSE_NODE_KIND_H_