Porytiles
Loading...
Searching...
No Matches
c_parser_facade.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstdint>
4#include <filesystem>
5#include <memory>
6#include <optional>
7#include <string>
8#include <unordered_map>
9#include <vector>
10
11#include "gsl/pointers"
12
27
28namespace porytiles {
29
59 public:
68 CParserFacade(std::filesystem::path file_path, gsl::not_null<const TextFormatter *> format);
69
81 std::filesystem::path file_path,
82 gsl::not_null<const TextFormatter *> format,
83 std::unordered_map<std::string, std::int64_t> seed_symbols);
84
96
108
118
127
131 [[nodiscard]] const std::vector<std::string> &scan_warnings() const
132 {
133 return scan_warnings_;
134 }
135
157 parse_pointer_arrays(const std::optional<std::string> &name_prefix = std::nullopt);
158
179 parse_functions(const std::optional<std::string> &name_prefix = std::nullopt);
180
204 parse_struct_variables(const std::optional<std::string> &name_prefix = std::nullopt);
205
236 parse_struct_initializers(const std::optional<std::string> &name_prefix = std::nullopt);
237
263 parse_struct_definitions(const std::optional<std::string> &name_filter = std::nullopt);
264
291 parse_incbin_arrays(const std::optional<std::string> &name_prefix = std::nullopt);
292
305 parse_indexed_arrays(const std::optional<std::string> &name_prefix = std::nullopt);
306
315 [[nodiscard]] ChainableResult<std::optional<DefineStatement>> find_define(const std::string &define_name);
316
324 [[nodiscard]] const std::vector<std::string> &file_lines() const;
325
326 private:
327 [[nodiscard]] ChainableResult<void> ensure_loaded();
328 [[nodiscard]] Parser make_seeded_parser(std::vector<Token> tokens);
329
330 std::filesystem::path file_path_;
331 const TextFormatter *format_;
332 std::unordered_map<std::string, std::int64_t> seed_symbols_;
333 std::vector<std::string> file_lines_;
334 std::string content_;
335 std::unique_ptr<CParserContext> context_;
336 bool loaded_{false};
337 bool load_failed_{false};
338 FormattableError load_error_;
339 std::optional<std::vector<DefineStatement>> cached_defines_;
340 std::vector<std::string> scan_warnings_;
341};
342
343} // namespace porytiles
High-level facade for parsing C/C++ source files.
const std::vector< std::string > & file_lines() const
Returns the cached file lines.
ChainableResult< std::vector< IncbinDeclaration > > parse_incbin_arrays(const std::optional< std::string > &name_prefix=std::nullopt)
Parses INCBIN array declarations from the file.
ChainableResult< std::vector< EnumDeclaration > > parse_enums()
Parses all enum declarations from the file.
ChainableResult< std::vector< StructVariableDeclaration > > parse_struct_variables(const std::optional< std::string > &name_prefix=std::nullopt)
Parses struct variable declarations from the file.
ChainableResult< std::vector< DefineStatement > > parse_defines()
Parses all #define statements from the file.
ChainableResult< std::optional< DefineStatement > > find_define(const std::string &define_name)
Finds a specific #define statement by name.
ChainableResult< std::vector< StructDefinition > > parse_struct_definitions(const std::optional< std::string > &name_filter=std::nullopt)
Parses struct type definitions from the file.
const std::vector< std::string > & scan_warnings() const
Returns recoverable warnings accumulated across tolerant parse calls.
ChainableResult< TolerantDefineScan > parse_defines_tolerant()
Parses all #define statements, tolerating individual evaluation failures.
ChainableResult< std::vector< FunctionDefinition > > parse_functions(const std::optional< std::string > &name_prefix=std::nullopt)
Parses function definitions from the file.
ChainableResult< std::vector< IndexedArrayDeclaration > > parse_indexed_arrays(const std::optional< std::string > &name_prefix=std::nullopt)
Parses designated (indexed) array declarations from the file.
ChainableResult< std::vector< StructInitializerDeclaration > > parse_struct_initializers(const std::optional< std::string > &name_prefix=std::nullopt)
Parses struct variable declarations with their designated initializer fields.
ChainableResult< std::vector< ArrayDeclaration > > parse_pointer_arrays(const std::optional< std::string > &name_prefix=std::nullopt)
Parses all pointer array declarations from the file.
ChainableResult< TolerantEnumScan > parse_enums_tolerant()
Parses all enum declarations, tolerating individual member evaluation failures.
A result type that maintains a chainable sequence of errors for debugging and error reporting.
Parser for C preprocessor constructs.
Definition parser.hpp:58
Abstract base class for applying text styling with context-aware formatting.