From 834c7bbe0513c854cfb167f2f088a72d40a1eb6d Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Fri, 16 Oct 2020 00:38:33 +0100 Subject: [PATCH] Report lexer issues through error reporter. --- common/dsnlexer.cpp | 3 ++- common/exceptions.cpp | 2 ++ include/ki_exception.h | 11 ++++++++++- pcbnew/dialogs/panel_setup_rules.cpp | 22 +++++++--------------- 4 files changed, 21 insertions(+), 17 deletions(-) diff --git a/common/dsnlexer.cpp b/common/dsnlexer.cpp index 7934f8e91a..f8703d32f0 100644 --- a/common/dsnlexer.cpp +++ b/common/dsnlexer.cpp @@ -671,7 +671,8 @@ L_read: // L_unterminated: wxString errtxt( _( "Un-terminated delimited string" ) ); - THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() ); + THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), + cur - start + curText.length() ); } } diff --git a/common/exceptions.cpp b/common/exceptions.cpp index 0b2cca2dbe..ebcd8e2cee 100644 --- a/common/exceptions.cpp +++ b/common/exceptions.cpp @@ -70,6 +70,8 @@ void PARSE_ERROR::init( const wxString& aProblem, const char* aThrowersFile, const wxString& aSource, const char* aInputLine, int aLineNumber, int aByteIndex ) { + parseProblem = aProblem; + problem.Printf( _( "%s in \"%s\", line %d, offset %d" ), aProblem, aSource, diff --git a/include/ki_exception.h b/include/ki_exception.h index a4f92ecfab..9c9c52ffed 100644 --- a/include/ki_exception.h +++ b/include/ki_exception.h @@ -154,8 +154,17 @@ struct PARSE_ERROR : public IO_ERROR ~PARSE_ERROR() throw () {} + const wxString ParseProblem() { return parseProblem; } + protected: - PARSE_ERROR(): IO_ERROR(), lineNumber( 0 ), byteIndex( 0 ) {} + PARSE_ERROR() : + IO_ERROR(), + lineNumber( 0 ), + byteIndex( 0 ) + {} + +protected: + wxString parseProblem; }; diff --git a/pcbnew/dialogs/panel_setup_rules.cpp b/pcbnew/dialogs/panel_setup_rules.cpp index 3cfb6678d0..6f4f0e2a0d 100644 --- a/pcbnew/dialogs/panel_setup_rules.cpp +++ b/pcbnew/dialogs/panel_setup_rules.cpp @@ -336,7 +336,13 @@ void PANEL_SETUP_RULES::OnCompile( wxCommandEvent& event ) } catch( PARSE_ERROR& pe ) { - m_Parent->SetError( pe.What(), this, m_textEditor, pe.lineNumber, pe.byteIndex ); + wxString msg = wxString::Format( _( "ERROR: %s%s" ), + pe.lineNumber, + pe.byteIndex, + pe.ParseProblem(), + wxEmptyString ); + + m_errorsReport->Report( msg, RPT_SEVERITY_ERROR ); } m_errorsReport->Flush(); @@ -404,20 +410,6 @@ bool PANEL_SETUP_RULES::TransferDataFromWindow() if( m_frame->Prj().IsNullProject() ) return true; - try - { - std::vector dummyRules; - - DRC_RULES_PARSER parser( m_textEditor->GetText(), _( "DRC rules" ) ); - - parser.Parse( dummyRules, m_errorsReport ); - } - catch( PARSE_ERROR& pe ) - { - m_Parent->SetError( pe.What(), this, m_textEditor, pe.lineNumber, pe.byteIndex ); - return false; - } - wxString rulesFilepath = m_frame->GetDesignRulesPath(); try