1+ #if !defined(PARSER_EMIT_ERROR_HXX)
2+ #define PARSER_EMIT_ERROR_HXX
3+
4+ #include " wheel_parser/config.hxx"
5+ #include " wheel_parser/ast/nodes.hxx"
6+ #include " wheel_parser/error.hxx"
7+ #include " wheel_parser/declaration.hxx"
8+ #include " wheel_parser/parser_utils.hxx"
9+ #include < wheel_lexer/token.hxx>
10+ #include < wheel_lexer/kind.hxx>
11+ #include < wheel_lexer/source_map.hxx>
12+ #include < wheel_memory/allocator.hxx>
13+
14+ using wheel_parser::ast::StatementNode;
15+ using wheel_parser::ast::ErrorStatement;
16+ using wheel_parser::ParseErrorCode;
17+ using wheel_lexer::Token;
18+ using wheel_lexer::TokenKind;
19+ using wheel_lexer::SourceLocation;
20+ using wheel_memory::Arena;
21+
22+ WHEEL_PARSER_FUNCTIONS_BEGIN_NAMESPACE
23+ struct EmitErrorConfig {
24+ ParseErrorCode code;
25+ ParserErrorList &error_list;
26+ const Token *token;
27+ TokenKind actual;
28+ SourceLocation source_location;
29+ Arena &arena;
30+ Token ¤t_token;
31+ Lexer &lexer;
32+ };
33+
34+ inline StatementNode *emit_error (EmitErrorConfig config) noexcept {
35+ const auto *token = copy_token (config.arena , config.current_token );
36+ const auto error = make_parse_error (
37+ config.code ,
38+ token,
39+ token->kind ,
40+ config.lexer .get_source_location (*token)
41+ );
42+ config.error_list .push_back (error);
43+
44+ return config.arena .allocate <ErrorStatement>(token);
45+ }
46+
47+
48+ WHEEL_PARSER_FUNCTIONS_END_NAMESPACE
49+
50+ #endif
0 commit comments