17namespace ErrorHandling {
30 const std::string& source_file,
34 const std::string& msg,
35 const std::vector<std::string>& include_chain,
36 std::shared_ptr<bpp::bpp_program> program,
38 bool is_warning =
false);
41 const std::string& source_file,
43 uint32_t start_column,
45 const std::string& msg,
46 const std::vector<std::string>& include_chain
56 std::shared_ptr<bpp::bpp_program>
program;
60 template <bpp::detail::ErrorReportableListener Listener, bpp::detail::ASTNodePtrORToken T>
64 program = listener->get_program();
69 line = error_ctx->getPosition().line;
70 column = error_ctx->getPosition().column;
71 if (error_ctx->getEndPosition().line == error_ctx->getPosition().line) {
72 text_length = error_ctx->getEndPosition().column - error_ctx->getPosition().column;
75 line = error_ctx.getLine();
76 column = error_ctx.getCharPositionInLine();
77 text_length =
static_cast<uint32_t
>(error_ctx.getValue().length());
81 line = error_ctx.getLine();
82 column = error_ctx.getCharPositionInLine();
83 auto param = error_ctx.getValue();
85 if (param.type.has_value()) {
86 text_length += 1 +
static_cast<uint32_t
>(param.type.value().getValue().length());
88 text_length += 1 +
static_cast<uint32_t
>(param.name.getValue().length());
90 text_length =
static_cast<uint32_t
>(param.name.getValue().length());
98 template <bpp::detail::ErrorReportableListener Listener, bpp::detail::ASTNodePtrORToken T>
99 inline ErrorOrWarning(Listener* listener,
const T& error_ctx,
const std::string& msg) : std::runtime_error(msg) {
131 template <bpp::detail::ErrorReportableListener Listener, bpp::detail::ASTNodePtrORToken T>
149 explicit Warning(
const std::string& msg) =
delete;
151 template <bpp::detail::ErrorReportableListener Listener, bpp::detail::ASTNodePtrORToken T>
152 inline Warning(Listener* listener,
const T& error_ctx,
const std::string& msg) :
ErrorOrWarning(listener, error_ctx, msg) {
159std::string
utf8_substr(
const std::string& str, uint32_t start, uint32_t length);
Definition SyntaxError.h:49
uint32_t text_length
Definition SyntaxError.h:54
uint32_t line
Definition SyntaxError.h:52
bool lsp_mode
Definition SyntaxError.h:57
ErrorOrWarning(const std::string &msg)=delete
void set_from_listener(Listener *listener, T error_ctx)
Definition SyntaxError.h:61
std::shared_ptr< bpp::bpp_program > program
Definition SyntaxError.h:56
ErrorOrWarning(Listener *listener, const T &error_ctx, const std::string &msg)
Definition SyntaxError.h:99
uint32_t column
Definition SyntaxError.h:53
bool is_warning
Definition SyntaxError.h:58
void print() const
Definition SyntaxError.h:103
std::vector< std::string > include_chain
Definition SyntaxError.h:55
std::string source_file
Definition SyntaxError.h:51
An exception thrown when a syntax error is encountered This exception can be constructed from any lis...
Definition SyntaxError.h:126
SyntaxError(Listener *listener, const T &error_ctx, const std::string &msg)
Definition SyntaxError.h:132
SyntaxError(const std::string &msg)=delete
A compiler warning that is not fatal to compilation This type should never be thrown....
Definition SyntaxError.h:146
Warning(const std::string &msg)=delete
Warning(Listener *listener, const T &error_ctx, const std::string &msg)
Definition SyntaxError.h:152
uint32_t utf8_length(const std::string &str)
Definition SyntaxError.cpp:166
std::string equal_width_padding(const std::string &str, char padding_char)
Definition SyntaxError.cpp:180
void print_syntax_error_from_parser(const std::string &source_file, uint32_t line, uint32_t start_column, uint32_t end_column, const std::string &msg, const std::vector< std::string > &include_chain)
Definition SyntaxError.cpp:117
void print_syntax_error_or_warning(const std::string &source_file, uint32_t line, uint32_t column, uint32_t text_length, const std::string &msg, const std::vector< std::string > &include_chain, std::shared_ptr< bpp::bpp_program > program, bool lsp_mode, bool is_warning)
Print a syntax error or warning message to stderr.
Definition SyntaxError.cpp:22
std::string utf8_substr(const std::string &str, uint32_t start, uint32_t length)
Definition SyntaxError.cpp:137
Definition bash_case.cpp:8