Skip to content

Commit

Permalink
Fix issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
rturrado committed Mar 8, 2024
1 parent 25fd785 commit 4070fe0
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/v3x/CustomErrorListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,23 @@ void CustomErrorListener::syntaxError(
const std::string &msg, std::exception_ptr /* e */) {

// ANTLR provides a zero-based character position in line
// We change it here to a one-based index, which is the more human-readable, and the common option in text editors
auto token_size = offendingSymbol
// We change it here to a one-based index, which is the more human-readable,
// and the common option in text editors
auto start_column{ charPositionInLine + 1 };

// Special case for EOF token
// EOF token has a "<EOF>" text, so we avoid calculating the size of EOF from its text
// Instead, we just return a zero size
auto token_size = (offendingSymbol && offendingSymbol->getType() != antlr4::Token::EOF)
? offendingSymbol->getText().size()
: 0;
auto end_column = start_column + token_size;

throw error::ParseError{
msg,
file_name_,
{ { static_cast<std::uint32_t>(line), static_cast<std::uint32_t>(charPositionInLine + 1) },
{ static_cast<std::uint32_t>(line), static_cast<std::uint32_t>(charPositionInLine + 1 + token_size) } }
{ { static_cast<std::uint32_t>(line), static_cast<std::uint32_t>(start_column) },
{ static_cast<std::uint32_t>(line), static_cast<std::uint32_t>(end_column) } }
};
}

Expand Down

0 comments on commit 4070fe0

Please sign in to comment.