// rpimpl_ex.h
// Copyright (c) Menno Rubingh 2016.  Web: [http://rubinghsoftware.de]
// 
// MR Mar 2016.
//
// Exception and scanning context (character number in input string)
// used internally by the RPInterpreter implementation.
//
// The purpose of the scanning context is to print error messages that
// specify the position in the input string (1) where the scanning error
// occured, or (2) of the lexical element where the evaluation error
// occurred.
//

#ifndef _RPIMPL_EX_H_
#define _RPIMPL_EX_H_


class SContext
{
	int m_n;  //Character number in input string, 0-based.

public:
	SContext( void ) : m_n(0) { }  //Initialize to zero.

	void advance( int iN ) { m_n += iN; }
	int  getN( void ) const { return m_n; }
};


class Ex
{
	SContext        m_cxt;  
        char const *    m_msg;

public:
        Ex( SContext const * iCxt, char const * iMsg ) : 
		m_cxt( *iCxt ),  //(Note)
		m_msg( iMsg )    
		{ }
	//Note: Copy whole struct, since caller's SContext instance is in general 
	// a local variable going out of scope when throwing exception.

	char const * getMsg( void ) const { return m_msg; }
	int          getCol( void ) const { return m_cxt.getN(); }
};


#endif //_RPIMPL_EX_H_