Loading common/dsnlexer.cpp +16 −22 Original line number Diff line number Diff line Loading @@ -231,7 +231,7 @@ wxString DSNLEXER::GetTokenString( int aTok ) { wxString ret; ret << wxT("'") << wxConvertMB2WX( GetTokenText(aTok) ) << wxT("'"); ret << wxT("'") << wxString::FromUTF8( GetTokenText(aTok) ) << wxT("'"); return ret; } Loading @@ -249,24 +249,11 @@ bool DSNLEXER::IsSymbol( int aTok ) } void DSNLEXER::ThrowIOError( wxString aText, int charOffset ) throw( IO_ERROR ) { // @todo convert this to THROW_PARSE_ERROR() // append to aText, do not overwrite aText << wxT(" ") << _("in") << wxT(" \"") << CurSource() << wxT("\" ") << _("on line") << wxT(" ") << reader->LineNumber() << wxT(" ") << _("at offset") << wxT(" ") << charOffset; THROW_IO_ERROR( aText ); } void DSNLEXER::Expecting( int aTok ) throw( IO_ERROR ) { wxString errText( _("Expecting") ); errText << wxT(" ") << GetTokenString( aTok ); ThrowIOError( errText, CurOffset() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } Loading @@ -274,7 +261,7 @@ void DSNLEXER::Expecting( const wxString& text ) throw( IO_ERROR ) { wxString errText( _("Expecting") ); errText << wxT(" '") << text << wxT("'"); ThrowIOError( errText, CurOffset() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } Loading @@ -282,15 +269,22 @@ void DSNLEXER::Unexpected( int aTok ) throw( IO_ERROR ) { wxString errText( _("Unexpected") ); errText << wxT(" ") << GetTokenString( aTok ); ThrowIOError( errText, CurOffset() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } void DSNLEXER::Duplicate( int aTok ) throw( IO_ERROR ) { wxString errText; errText.Printf( _("%s is a duplicate"), GetTokenString( aTok ).GetData() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } void DSNLEXER::Unexpected( const wxString& text ) throw( IO_ERROR ) { wxString errText( _("Unexpected") ); errText << wxT(" '") << text << wxT("'"); ThrowIOError( errText, CurOffset() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } Loading Loading @@ -408,7 +402,7 @@ L_read: case '"': break; default: ThrowIOError( errtxt, CurOffset() ); THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } curText = cc; Loading @@ -417,7 +411,7 @@ L_read: if( head<limit && *head!=')' && *head!='(' && !isSpace(*head) ) { ThrowIOError( errtxt, CurOffset() ); THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } curTok = DSN_QUOTE_DEF; Loading Loading @@ -514,7 +508,7 @@ L_read: } wxString errtxt(_("Un-terminated delimited string") ); ThrowIOError( errtxt, CurOffset() ); THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); #else // old code, did not understand nested quotes ++cur; // skip over the leading delimiter: ",', or $ Loading @@ -527,7 +521,7 @@ L_read: if( head >= limit ) { wxString errtxt(_("Un-terminated delimited string") ); ThrowIOError( errtxt, CurOffset() ); THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } curText.clear(); Loading include/dsnlexer.h +31 −8 Original line number Diff line number Diff line Loading @@ -330,13 +330,6 @@ public: */ static bool IsSymbol( int aTok ); /** * Function ThrowIOError * encapsulates the formatting of an error message which contains the exact * location within the input file of something the caller is rejecting. */ void ThrowIOError( wxString aText, int charOffset ) throw( IO_ERROR ); /** * Function Expecting * throws an IO_ERROR exception with an input file specific error message. Loading @@ -363,6 +356,16 @@ public: */ void Unexpected( int aTok ) throw( IO_ERROR ); /** * Function Duplicate * throws an IO_ERROR exception with a message saying specifically that aTok * is a duplicate of one already seen in current context. * @param aTok is the token/keyword type which was not expected at the * current input location. * @throw IO_ERROR with the location within the input file of the problem. */ void Duplicate( int aTok ) throw( IO_ERROR ); /** * Function Unexpected * throws an IO_ERROR exception with an input file specific error message. Loading Loading @@ -411,6 +414,16 @@ public: return curText.c_str(); } /** * Function FromUTF8 * returns the current token text as a wxString, assuming that the input * byte stream is UTF8 encoded. */ wxString FromUTF8() { return wxString::FromUTF8( curText.c_str() ); } /** * Function CurLineNumber * returns the current line number within my LINE_READER Loading @@ -420,6 +433,16 @@ public: return reader->LineNumber(); } /** * Function CurLine * returns the current line of text, from which the CurText() would return * its token. */ const char* CurLine() { return (const char*)(*reader); } /** * Function CurFilename * returns the current LINE_READER source. Loading @@ -433,7 +456,7 @@ public: /** * Function CurOffset * returns the char offset within the current line, using a 1 based index. * returns the byte offset within the current line, using a 1 based index. * @return int - a one based index into the current line. */ int CurOffset() Loading include/richio.h +28 −12 Original line number Diff line number Diff line Loading @@ -46,8 +46,8 @@ */ #define IO_FORMAT _( "IO_ERROR: '%s'\n from %s : %s" ) #define PARSE_FORMAT _( "PARSE_ERROR: '%s' in input/source '%s', line %d, offset %d\n from %s : %s" ) #define IO_FORMAT _( "IO_ERROR: %s\n from %s : %s" ) #define PARSE_FORMAT _( "PARSE_ERROR: %s in input/source \"%s\", line %d, offset %d\n from %s : %s" ) // references: // http://stackoverflow.com/questions/2670816/how-can-i-use-the-compile-time-constant-line-in-a-string Loading Loading @@ -123,12 +123,11 @@ struct IO_ERROR // : std::exception }; #define THROW_PARSE_ERROR( msg, input, line, offset ) throw PARSE_ERROR( __FILE__, __LOC__, msg, input, line, offset ) /** * Class PARSE_ERROR * contains a filename or source description, a line number, a character offset, * and an error message. * contains a filename or source description, a problem input line, a line number, * a byte offset, and an error message which contains the the caller's report and his * call site information: CPP source file, function, and line number. * @author Dick Hollenbeck */ struct PARSE_ERROR : public IO_ERROR Loading @@ -138,24 +137,36 @@ struct PARSE_ERROR : public IO_ERROR int lineNumber; ///< at which line number, 1 based index. int byteIndex; ///< at which character position within the line, 1 based index /// problem line of input [say, from a LINE_READER]. /// this is brought up in original byte format rather than wxString form, incase /// there was a problem with the encoding, in which case converting to wxString is /// not reliable in this context. std::string inputLine; /** * Constructor * which is normally called via the macro THROW_PARSE_ERROR so that * __FILE__ and __LOC__ can be captured from the call site. */ PARSE_ERROR( const char* aThrowersFile, const char* aThrowersLoc, const wxString& aMsg, const wxString& aSource, const char* aInputLine, int aLineNumber, int aByteIndex ) : IO_ERROR() { init( aThrowersFile, aThrowersLoc, aMsg, aSource, aLineNumber, aByteIndex ); init( aThrowersFile, aThrowersLoc, aMsg, aSource, aInputLine, aLineNumber, aByteIndex ); } void init( const char* aThrowersFile, const char* aThrowersLoc, const wxString& aMsg, const wxString& aSource, const char* aInputLine, int aLineNumber, int aByteIndex ) { // save line and offset in binary for Sweet text editor, which will catch exceptions // save inpuLine, lineNumber, and offset for UI (.e.g. Sweet text editor) inputLine = aInputLine; lineNumber = aLineNumber; byteIndex = aByteIndex; // #define PARSE_FORMAT _( "PARSE_ERROR: %s in source %s, line %d, offset %d\nfrom cpp:%s func:%s" ) errorText.Printf( PARSE_FORMAT, aMsg.GetData(), aSource.GetData(), aLineNumber, aByteIndex, wxString::FromUTF8( aThrowersFile ).GetData(), Loading @@ -165,6 +176,11 @@ struct PARSE_ERROR : public IO_ERROR ~PARSE_ERROR() throw ( /*none*/ ){} }; #define THROW_PARSE_ERROR( aMsg, aSource, aInputLine, aLineNumber, aByteIndex ) \ throw PARSE_ERROR( __FILE__, __LOC__, aMsg, aSource, aInputLine, aLineNumber, aByteIndex ) /** @} exception_types */ Loading new/make-dir-lib-source-test-data.sh +1 −2 Original line number Diff line number Diff line Loading @@ -16,8 +16,7 @@ for C in ${CATEGORIES}; do for P in ${PARTS}; do for R in ${REVS}; do echo "#$R: (part $C/$P)" > $BASEDIR/$C/$P.part.$R (part $C/$P/$R extends $P/$R (value 22)(footprint SM0805)) > $BASEDIR/$C/$P.part.$R done done done new/sch_lib_table.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -413,6 +413,12 @@ int main( int argc, char** argv ) lib_table.Test(); } catch( PARSE_ERROR& ioe ) // most derived class first { printf( "%s\n", (const char*) ioe.errorText.ToUTF8() ); printf( "%s", ioe.inputLine.c_str() ); // rare not to have \n at end printf( "%*s^\n", ioe.byteIndex-1, " " ); } catch( IO_ERROR& ioe ) { printf( "%s\n", (const char*) ioe.errorText.ToUTF8() ); Loading Loading
common/dsnlexer.cpp +16 −22 Original line number Diff line number Diff line Loading @@ -231,7 +231,7 @@ wxString DSNLEXER::GetTokenString( int aTok ) { wxString ret; ret << wxT("'") << wxConvertMB2WX( GetTokenText(aTok) ) << wxT("'"); ret << wxT("'") << wxString::FromUTF8( GetTokenText(aTok) ) << wxT("'"); return ret; } Loading @@ -249,24 +249,11 @@ bool DSNLEXER::IsSymbol( int aTok ) } void DSNLEXER::ThrowIOError( wxString aText, int charOffset ) throw( IO_ERROR ) { // @todo convert this to THROW_PARSE_ERROR() // append to aText, do not overwrite aText << wxT(" ") << _("in") << wxT(" \"") << CurSource() << wxT("\" ") << _("on line") << wxT(" ") << reader->LineNumber() << wxT(" ") << _("at offset") << wxT(" ") << charOffset; THROW_IO_ERROR( aText ); } void DSNLEXER::Expecting( int aTok ) throw( IO_ERROR ) { wxString errText( _("Expecting") ); errText << wxT(" ") << GetTokenString( aTok ); ThrowIOError( errText, CurOffset() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } Loading @@ -274,7 +261,7 @@ void DSNLEXER::Expecting( const wxString& text ) throw( IO_ERROR ) { wxString errText( _("Expecting") ); errText << wxT(" '") << text << wxT("'"); ThrowIOError( errText, CurOffset() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } Loading @@ -282,15 +269,22 @@ void DSNLEXER::Unexpected( int aTok ) throw( IO_ERROR ) { wxString errText( _("Unexpected") ); errText << wxT(" ") << GetTokenString( aTok ); ThrowIOError( errText, CurOffset() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } void DSNLEXER::Duplicate( int aTok ) throw( IO_ERROR ) { wxString errText; errText.Printf( _("%s is a duplicate"), GetTokenString( aTok ).GetData() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } void DSNLEXER::Unexpected( const wxString& text ) throw( IO_ERROR ) { wxString errText( _("Unexpected") ); errText << wxT(" '") << text << wxT("'"); ThrowIOError( errText, CurOffset() ); THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } Loading Loading @@ -408,7 +402,7 @@ L_read: case '"': break; default: ThrowIOError( errtxt, CurOffset() ); THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } curText = cc; Loading @@ -417,7 +411,7 @@ L_read: if( head<limit && *head!=')' && *head!='(' && !isSpace(*head) ) { ThrowIOError( errtxt, CurOffset() ); THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } curTok = DSN_QUOTE_DEF; Loading Loading @@ -514,7 +508,7 @@ L_read: } wxString errtxt(_("Un-terminated delimited string") ); ThrowIOError( errtxt, CurOffset() ); THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); #else // old code, did not understand nested quotes ++cur; // skip over the leading delimiter: ",', or $ Loading @@ -527,7 +521,7 @@ L_read: if( head >= limit ) { wxString errtxt(_("Un-terminated delimited string") ); ThrowIOError( errtxt, CurOffset() ); THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); } curText.clear(); Loading
include/dsnlexer.h +31 −8 Original line number Diff line number Diff line Loading @@ -330,13 +330,6 @@ public: */ static bool IsSymbol( int aTok ); /** * Function ThrowIOError * encapsulates the formatting of an error message which contains the exact * location within the input file of something the caller is rejecting. */ void ThrowIOError( wxString aText, int charOffset ) throw( IO_ERROR ); /** * Function Expecting * throws an IO_ERROR exception with an input file specific error message. Loading @@ -363,6 +356,16 @@ public: */ void Unexpected( int aTok ) throw( IO_ERROR ); /** * Function Duplicate * throws an IO_ERROR exception with a message saying specifically that aTok * is a duplicate of one already seen in current context. * @param aTok is the token/keyword type which was not expected at the * current input location. * @throw IO_ERROR with the location within the input file of the problem. */ void Duplicate( int aTok ) throw( IO_ERROR ); /** * Function Unexpected * throws an IO_ERROR exception with an input file specific error message. Loading Loading @@ -411,6 +414,16 @@ public: return curText.c_str(); } /** * Function FromUTF8 * returns the current token text as a wxString, assuming that the input * byte stream is UTF8 encoded. */ wxString FromUTF8() { return wxString::FromUTF8( curText.c_str() ); } /** * Function CurLineNumber * returns the current line number within my LINE_READER Loading @@ -420,6 +433,16 @@ public: return reader->LineNumber(); } /** * Function CurLine * returns the current line of text, from which the CurText() would return * its token. */ const char* CurLine() { return (const char*)(*reader); } /** * Function CurFilename * returns the current LINE_READER source. Loading @@ -433,7 +456,7 @@ public: /** * Function CurOffset * returns the char offset within the current line, using a 1 based index. * returns the byte offset within the current line, using a 1 based index. * @return int - a one based index into the current line. */ int CurOffset() Loading
include/richio.h +28 −12 Original line number Diff line number Diff line Loading @@ -46,8 +46,8 @@ */ #define IO_FORMAT _( "IO_ERROR: '%s'\n from %s : %s" ) #define PARSE_FORMAT _( "PARSE_ERROR: '%s' in input/source '%s', line %d, offset %d\n from %s : %s" ) #define IO_FORMAT _( "IO_ERROR: %s\n from %s : %s" ) #define PARSE_FORMAT _( "PARSE_ERROR: %s in input/source \"%s\", line %d, offset %d\n from %s : %s" ) // references: // http://stackoverflow.com/questions/2670816/how-can-i-use-the-compile-time-constant-line-in-a-string Loading Loading @@ -123,12 +123,11 @@ struct IO_ERROR // : std::exception }; #define THROW_PARSE_ERROR( msg, input, line, offset ) throw PARSE_ERROR( __FILE__, __LOC__, msg, input, line, offset ) /** * Class PARSE_ERROR * contains a filename or source description, a line number, a character offset, * and an error message. * contains a filename or source description, a problem input line, a line number, * a byte offset, and an error message which contains the the caller's report and his * call site information: CPP source file, function, and line number. * @author Dick Hollenbeck */ struct PARSE_ERROR : public IO_ERROR Loading @@ -138,24 +137,36 @@ struct PARSE_ERROR : public IO_ERROR int lineNumber; ///< at which line number, 1 based index. int byteIndex; ///< at which character position within the line, 1 based index /// problem line of input [say, from a LINE_READER]. /// this is brought up in original byte format rather than wxString form, incase /// there was a problem with the encoding, in which case converting to wxString is /// not reliable in this context. std::string inputLine; /** * Constructor * which is normally called via the macro THROW_PARSE_ERROR so that * __FILE__ and __LOC__ can be captured from the call site. */ PARSE_ERROR( const char* aThrowersFile, const char* aThrowersLoc, const wxString& aMsg, const wxString& aSource, const char* aInputLine, int aLineNumber, int aByteIndex ) : IO_ERROR() { init( aThrowersFile, aThrowersLoc, aMsg, aSource, aLineNumber, aByteIndex ); init( aThrowersFile, aThrowersLoc, aMsg, aSource, aInputLine, aLineNumber, aByteIndex ); } void init( const char* aThrowersFile, const char* aThrowersLoc, const wxString& aMsg, const wxString& aSource, const char* aInputLine, int aLineNumber, int aByteIndex ) { // save line and offset in binary for Sweet text editor, which will catch exceptions // save inpuLine, lineNumber, and offset for UI (.e.g. Sweet text editor) inputLine = aInputLine; lineNumber = aLineNumber; byteIndex = aByteIndex; // #define PARSE_FORMAT _( "PARSE_ERROR: %s in source %s, line %d, offset %d\nfrom cpp:%s func:%s" ) errorText.Printf( PARSE_FORMAT, aMsg.GetData(), aSource.GetData(), aLineNumber, aByteIndex, wxString::FromUTF8( aThrowersFile ).GetData(), Loading @@ -165,6 +176,11 @@ struct PARSE_ERROR : public IO_ERROR ~PARSE_ERROR() throw ( /*none*/ ){} }; #define THROW_PARSE_ERROR( aMsg, aSource, aInputLine, aLineNumber, aByteIndex ) \ throw PARSE_ERROR( __FILE__, __LOC__, aMsg, aSource, aInputLine, aLineNumber, aByteIndex ) /** @} exception_types */ Loading
new/make-dir-lib-source-test-data.sh +1 −2 Original line number Diff line number Diff line Loading @@ -16,8 +16,7 @@ for C in ${CATEGORIES}; do for P in ${PARTS}; do for R in ${REVS}; do echo "#$R: (part $C/$P)" > $BASEDIR/$C/$P.part.$R (part $C/$P/$R extends $P/$R (value 22)(footprint SM0805)) > $BASEDIR/$C/$P.part.$R done done done
new/sch_lib_table.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -413,6 +413,12 @@ int main( int argc, char** argv ) lib_table.Test(); } catch( PARSE_ERROR& ioe ) // most derived class first { printf( "%s\n", (const char*) ioe.errorText.ToUTF8() ); printf( "%s", ioe.inputLine.c_str() ); // rare not to have \n at end printf( "%*s^\n", ioe.byteIndex-1, " " ); } catch( IO_ERROR& ioe ) { printf( "%s\n", (const char*) ioe.errorText.ToUTF8() ); Loading