mupp 1.1.0
Loading...
Searching...
No Matches
mupp::PErrorHandler< Iterator > Struct Template Reference

The PErrorHandler struct handles parsing and semantic errors. More...

#include <PErrorHandler.hpp>

Public Member Functions

 PErrorHandler (Iterator first, Iterator last)
 Constructor that stores the source code range.
 
template<typename Message, typename What>
void operator() (Message const &message, What const &what, Iterator err_pos) const
 Function call operator that logs an error to file.
 
Iterator get_pos (Iterator err_pos, int &line) const
 Finds the start of the line containing an error and computes line number.
 
std::string get_line (Iterator err_pos) const
 Extracts the complete line containing an error.
 

Public Attributes

Iterator first
 Iterator to the beginning of the source code.
 
Iterator last
 Iterator to the end of the source code.
 
std::vector< Iterator > iters
 Vector mapping AST node IDs to source positions (used by PAnnotation)
 

Detailed Description

template<typename Iterator>
struct mupp::PErrorHandler< Iterator >

The PErrorHandler struct handles parsing and semantic errors.

This error handler logs detailed error information to a file, including the error message, line number, source line, and a visual pointer to the error position. It integrates with the Boost.Spirit X3 parser error handling mechanism and works in conjunction with the PAnnotation handler to map AST node IDs back to source positions.

Errors are appended to: ~/.musrfit/mupp/mupp_err.log

Template Parameters
Iteratorthe iterator type for the source code (typically std::string::const_iterator)

Definition at line 59 of file PErrorHandler.hpp.

Constructor & Destructor Documentation

◆ PErrorHandler()

template<typename Iterator>
mupp::PErrorHandler< Iterator >::PErrorHandler ( Iterator first,
Iterator last )
inline

Constructor that stores the source code range.

Parameters
firstiterator pointing to the beginning of the source code
lastiterator pointing to the end of the source code

Definition at line 67 of file PErrorHandler.hpp.

Member Function Documentation

◆ get_line()

template<typename Iterator>
std::string mupp::PErrorHandler< Iterator >::get_line ( Iterator err_pos) const
inline

Extracts the complete line containing an error.

Returns the substring from the start of the line to the next line break.

Parameters
err_positerator pointing to the start of the line
Returns
string containing the complete line (without line break characters)

Definition at line 149 of file PErrorHandler.hpp.

◆ get_pos()

template<typename Iterator>
Iterator mupp::PErrorHandler< Iterator >::get_pos ( Iterator err_pos,
int & line ) const
inline

Finds the start of the line containing an error and computes line number.

Scans from the beginning of the source to the error position, counting line breaks (CR, LF, or CRLF) to determine the line number.

Parameters
err_positerator pointing to the error position
lineoutput parameter that will contain the 1-based line number
Returns
iterator pointing to the start of the line containing the error

Definition at line 118 of file PErrorHandler.hpp.

◆ operator()()

template<typename Iterator>
template<typename Message, typename What>
void mupp::PErrorHandler< Iterator >::operator() ( Message const & message,
What const & what,
Iterator err_pos ) const
inline

Function call operator that logs an error to file.

Determines the line number and position of the error, formats a user-friendly error message with a visual indicator (^~~), and appends it to the error log file. Handles both mid-file errors and unexpected end-of-file errors.

Template Parameters
Messagethe message type (typically std::string)
Whatthe expected element type (typically std::string)
Parameters
messagethe error message prefix (e.g., "**ERROR** Expecting ")
whatdescription of what was expected at the error position
err_positerator pointing to the position where the error occurred

Definition at line 85 of file PErrorHandler.hpp.

Member Data Documentation

◆ first

template<typename Iterator>
Iterator mupp::PErrorHandler< Iterator >::first

Iterator to the beginning of the source code.

Definition at line 158 of file PErrorHandler.hpp.

◆ iters

template<typename Iterator>
std::vector<Iterator> mupp::PErrorHandler< Iterator >::iters

Vector mapping AST node IDs to source positions (used by PAnnotation)

Definition at line 160 of file PErrorHandler.hpp.

◆ last

template<typename Iterator>
Iterator mupp::PErrorHandler< Iterator >::last

Iterator to the end of the source code.

Definition at line 159 of file PErrorHandler.hpp.


The documentation for this struct was generated from the following file: