OpenMS
Loading...
Searching...
No Matches
ProForma::ParseError Class Reference

Structured parse error with context for ProForma parsing. More...

#include <OpenMS/CHEMISTRY/ProForma.h>

Inheritance diagram for ProForma::ParseError:
[legend]
Collaboration diagram for ProForma::ParseError:
[legend]

Public Member Functions

 ParseError (const char *file, int line, const char *function, ErrorCode error_code, size_t error_position, const String &input, const String &message) noexcept
 Constructs a ParseError with full context information.
 
ErrorCode getErrorCode () const noexcept
 Get the error code for programmatic handling.
 
size_t getPosition () const noexcept
 Get byte position of error (0-indexed)
 
const StringgetContextBefore () const noexcept
 Get context before error (~20 chars)
 
const StringgetContextAfter () const noexcept
 Get context after error (~20 chars)
 
const StringgetExpected () const noexcept
 Get what was expected (if set)
 
const StringgetFound () const noexcept
 Get what was found (if set)
 
String getFormattedMessage () const
 Get formatted error message with context visualization.
 
void setExpectedFound (const String &expected, const String &found)
 Set expected/found information for more detailed error messages.
 
- Public Member Functions inherited from ParseError
 ParseError (const char *file, int line, const char *function, const std::string &expression, const std::string &message) noexcept
 
- Public Member Functions inherited from BaseException
 BaseException () noexcept
 Default constructor.
 
 BaseException (const char *file, int line, const char *function) noexcept
 Constructor.
 
 BaseException (const char *file, int line, const char *function, const std::string &name, const std::string &message) noexcept
 Constructor.
 
 BaseException (const BaseException &exception) noexcept
 Copy constructor.
 
 ~BaseException () noexcept override
 Destructor.
 
const char * getName () const noexcept
 Returns the name of the exception.
 
int getLine () const noexcept
 Returns the line number where it occurred.
 
const char * getFile () const noexcept
 Returns the file where it occurred.
 
const char * getFunction () const noexcept
 Returns the function where it occurred.
 
const char * getMessage () const noexcept
 Returns the message.
 

Private Member Functions

void extractContext_ (const String &input, size_t pos)
 Extract context snippets from input around the error position.
 

Private Attributes

ErrorCode code_
 Machine-readable error code.
 
size_t position_
 Position in input where error occurred.
 
String context_before_
 Text before the error position.
 
String context_after_
 Text after the error position.
 
String expected_
 What was expected (optional)
 
String found_
 What was found (optional)
 

Additional Inherited Members

- Protected Attributes inherited from BaseException
const char * file_
 The source file the exception was thrown in.
 
int line_
 The line number the exception was thrown in.
 
const char * function_
 The source file the exception was thrown in.
 
std::string name_
 The name of the exception.
 

Detailed Description

Structured parse error with context for ProForma parsing.

This exception extends Exception::ParseError to provide more detailed information about ProForma parsing failures, including:

  • Machine-readable error code for programmatic handling
  • Position of the error in the input string
  • Context snippets showing surrounding text
  • Expected vs. found information for clearer diagnostics

Usage example:

try {
ProForma::parse("PEPTIDE[Oxidation");
} catch (const ProForma::ParseError& e) {
std::cerr << e.getFormattedMessage() << std::endl;
// Output:
// ProForma parse error at position 7: Unclosed bracket
// Context: PEPTIDE>>>[<<<Oxidation
// Expected: ']'
// Found: end of input
}
Structured parse error with context for ProForma parsing.
Definition ProForma.h:590
String getFormattedMessage() const
Get formatted error message with context visualization.
static Peptidoform parse(const String &input)
Parse a ProForma string into a Peptidoform AST.

Constructor & Destructor Documentation

◆ ParseError()

ParseError ( const char *  file,
int  line,
const char *  function,
ErrorCode  error_code,
size_t  error_position,
const String input,
const String message 
)
noexcept

Constructs a ParseError with full context information.

Parameters
[in]fileSource file where the exception was thrown (use FILE).
[in]lineSource line where the exception was thrown (use LINE).
[in]functionFunction name where the exception was thrown (use OPENMS_PRETTY_FUNCTION).
[in]error_codeMachine-readable error code categorizing the error.
[in]error_positionByte position (0-indexed) in the input where the error occurred. Will be clamped to input.size() if out of bounds.
[in]inputThe complete input string that was being parsed.
[in]messageHuman-readable description of the error.

Member Function Documentation

◆ extractContext_()

void extractContext_ ( const String input,
size_t  pos 
)
private

Extract context snippets from input around the error position.

Extracts approximately 20 characters before and after the error position for display in error messages. The position is assumed to be already clamped to input.size().

Parameters
[in]inputThe complete input string.
[in]posThe error position in the input (clamped to input.size()).

◆ getContextAfter()

const String & getContextAfter ( ) const
inlinenoexcept

Get context after error (~20 chars)

◆ getContextBefore()

const String & getContextBefore ( ) const
inlinenoexcept

Get context before error (~20 chars)

◆ getErrorCode()

ErrorCode getErrorCode ( ) const
inlinenoexcept

Get the error code for programmatic handling.

◆ getExpected()

const String & getExpected ( ) const
inlinenoexcept

Get what was expected (if set)

◆ getFormattedMessage()

String getFormattedMessage ( ) const

Get formatted error message with context visualization.

Returns a multi-line string formatted for human reading, showing:

  • Error description with position
  • Context snippet with caret pointing to error location
  • Expected vs. found information (if available)
Returns
Formatted error message.

◆ getFound()

const String & getFound ( ) const
inlinenoexcept

Get what was found (if set)

◆ getPosition()

size_t getPosition ( ) const
inlinenoexcept

Get byte position of error (0-indexed)

◆ setExpectedFound()

void setExpectedFound ( const String expected,
const String found 
)

Set expected/found information for more detailed error messages.

Parameters
[in]expectedDescription of what was expected at the error position.
[in]foundDescription of what was actually found.

Member Data Documentation

◆ code_

ErrorCode code_
private

Machine-readable error code.

◆ context_after_

String context_after_
private

Text after the error position.

◆ context_before_

String context_before_
private

Text before the error position.

◆ expected_

String expected_
private

What was expected (optional)

◆ found_

String found_
private

What was found (optional)

◆ position_

size_t position_
private

Position in input where error occurred.