Porytiles
Loading...
Searching...
No Matches
c_parser_facade.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <filesystem>
4#include <memory>
5#include <optional>
6#include <string>
7#include <vector>
8
9#include "gsl/pointers"
10
21
22namespace porytiles {
23
55 public:
66 CParserFacade(std::filesystem::path file_path, gsl::not_null<const TextFormatter *> format);
67
81
95
119 parse_pointer_arrays(const std::optional<std::string> &name_prefix = std::nullopt);
120
143 parse_functions(const std::optional<std::string> &name_prefix = std::nullopt);
144
169 parse_struct_variables(const std::optional<std::string> &name_prefix = std::nullopt);
170
202 parse_struct_initializers(const std::optional<std::string> &name_prefix = std::nullopt);
203
232 parse_incbin_arrays(const std::optional<std::string> &name_prefix = std::nullopt);
233
244 [[nodiscard]] ChainableResult<std::optional<DefineStatement>> find_define(const std::string &define_name);
245
255 [[nodiscard]] const std::vector<std::string> &file_lines() const;
256
257 private:
258 [[nodiscard]] ChainableResult<void> ensure_loaded();
259
260 std::filesystem::path file_path_;
261 const TextFormatter *format_;
262 std::vector<std::string> file_lines_;
263 std::string content_;
264 std::unique_ptr<CParserContext> context_;
265 bool loaded_{false};
266 bool load_failed_{false};
267 FormattableError load_error_;
268 std::optional<std::vector<DefineStatement>> cached_defines_;
269};
270
271} // 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< FunctionDefinition > > parse_functions(const std::optional< std::string > &name_prefix=std::nullopt)
Parses function definitions 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.
A result type that maintains a chainable sequence of errors for debugging and error reporting.
General-purpose error implementation with formatted message support.
Definition error.hpp:63
Abstract base class for applying text styling with context-aware formatting.