5#include <unordered_map>
66 Parser(gsl::not_null<const TextFormatter *> format, std::vector<Token> tokens)
67 : format_{format}, tokens_{std::move(tokens)}
82 Parser(gsl::not_null<const TextFormatter *> format, std::vector<Token> tokens,
const CParserContext *context)
83 : format_{format}, tokens_{std::move(tokens)}, context_{context}
261 [[nodiscard]]
const Token &peek()
const;
262 [[nodiscard]]
const Token &peek_next()
const;
263 const Token &advance();
264 [[nodiscard]]
bool is_at_end()
const;
265 [[nodiscard]]
bool check(
TokenType type)
const;
268 void skip_to_next_line();
269 [[nodiscard]]
bool is_at_line_end()
const;
273 [[nodiscard]] std::vector<Token> collect_expression_tokens();
274 [[nodiscard]] std::vector<Token> collect_enum_value_tokens();
278 [[nodiscard]] std::vector<Token> to_postfix(
const std::vector<Token> &expr_tokens);
280 [[nodiscard]]
int operator_precedence(
TokenType type)
const;
281 [[nodiscard]]
bool is_left_associative(
TokenType type)
const;
282 [[nodiscard]]
bool is_operator(
TokenType type)
const;
283 [[nodiscard]]
bool is_unary_operator(
TokenType type)
const;
288 std::vector<Token> tokens_;
289 std::size_t current_{0};
290 std::unordered_map<std::string, std::int64_t> defined_values_{{
"UCHAR_MAX", 255}};
291 const CParserContext *context_{
nullptr};
Context object providing rich error formatting for C/C++ parsing.
A result type that maintains a chainable sequence of errors for debugging and error reporting.
Parser for C preprocessor constructs.
Parser(gsl::not_null< const TextFormatter * > format, std::vector< Token > tokens, const CParserContext *context)
Constructs a parser with a context for rich error formatting.
ChainableResult< std::vector< ArrayDeclaration > > parse_pointer_arrays()
Parses all pointer array declarations from the token stream.
ChainableResult< std::vector< EnumDeclaration > > parse_enums()
Parses all enum declarations from the token stream.
ChainableResult< std::vector< DefineStatement > > parse_defines()
Parses all #define statements from the token stream.
ChainableResult< std::vector< IncbinDeclaration > > parse_incbin_arrays()
Parses INCBIN array declarations from the token stream.
ChainableResult< std::vector< StructVariableDeclaration > > parse_struct_variables()
Parses struct variable declarations from the token stream.
ChainableResult< std::vector< StructInitializerDeclaration > > parse_struct_initializers()
Parses struct variable declarations with their designated initializer fields.
Parser(gsl::not_null< const TextFormatter * > format, std::vector< Token > tokens)
Constructs a parser for the given token stream.
ChainableResult< std::vector< FunctionDefinition > > parse_functions()
Parses function definitions from the token stream.
Abstract base class for applying text styling with context-aware formatting.
Represents a lexical token from C source code.
TokenType
Enumeration of token types recognized by the C parser lexer.
Represents a position within source content.