|
Porytiles
|
Context object providing rich error formatting for C/C++ parsing. More...
#include <c_parser_context.hpp>
Public Member Functions | |
| CParserContext (gsl::not_null< const std::vector< std::string > * > file_lines, gsl::not_null< const TextFormatter * > format, std::string file_path="") | |
| Constructs a parser context with formatting dependencies. | |
| FormattableError | make_error (SourcePosition pos, const std::string &message) const |
| Creates a FormattableError with source context. | |
| const std::vector< std::string > * | file_lines () const |
| Returns the file lines held by this context. | |
| const TextFormatter * | formatter () const |
| Returns the text formatter used by this context. | |
| const std::string & | file_path () const |
| Returns the file path associated with this context. | |
Context object providing rich error formatting for C/C++ parsing.
CParserContext holds the dependencies needed to create FormattableError messages with source file context. It provides a make_error() factory method that creates multi-line error messages including the relevant source code snippet with highlighted error location via FileHighlightPrinter.
The context does not own the file_lines - callers must ensure the file_lines outlive the context. This design allows CParserFacade to own the file content while passing non-owning access to Lexer and Parser.
Example usage:
Definition at line 41 of file c_parser_context.hpp.
| porytiles::CParserContext::CParserContext | ( | gsl::not_null< const std::vector< std::string > * > | file_lines, |
| gsl::not_null< const TextFormatter * > | format, | ||
| std::string | file_path = "" |
||
| ) |
Constructs a parser context with formatting dependencies.
| file_lines | Pointer to cached file lines (non-owning, must outlive context) |
| format | Text formatter for styled output |
| file_path | Optional file path for error message headers (empty if unknown) |
Definition at line 21 of file c_parser_context.cpp.
| const std::vector< std::string > * porytiles::CParserContext::file_lines | ( | ) | const |
Returns the file lines held by this context.
Definition at line 72 of file c_parser_context.cpp.
| const std::string & porytiles::CParserContext::file_path | ( | ) | const |
Returns the file path associated with this context.
Definition at line 82 of file c_parser_context.cpp.
| const TextFormatter * porytiles::CParserContext::formatter | ( | ) | const |
Returns the text formatter used by this context.
Definition at line 77 of file c_parser_context.cpp.
| FormattableError porytiles::CParserContext::make_error | ( | SourcePosition | pos, |
| const std::string & | message | ||
| ) | const |
Creates a FormattableError with source context.
Creates a multi-line FormattableError including:
If the position is out of bounds (line beyond file, column beyond line), the error is created without source context, showing only the header line with position information.
| pos | Source position (1-based line and column) |
| message | Error message describing the problem |
Definition at line 29 of file c_parser_context.cpp.