diff --git a/common/dsnlexer.cpp b/common/dsnlexer.cpp index a70130a6c7..dc11ba4de2 100644 --- a/common/dsnlexer.cpp +++ b/common/dsnlexer.cpp @@ -146,6 +146,7 @@ DSNLEXER::~DSNLEXER() } } + void DSNLEXER::SetSpecctraMode( bool aMode ) { specctraMode = aMode; @@ -162,6 +163,16 @@ void DSNLEXER::SetSpecctraMode( bool aMode ) } +void DSNLEXER::InitParserState() +{ + curTok = DSN_NONE; + prevTok = DSN_NONE; + commentsAreTokens = false; + + curOffset = 0; +} + + bool DSNLEXER::SyncLineReaderWith( DSNLEXER& aLexer ) { // Synchronize the pointers handling the data read by the LINE_READER diff --git a/include/dsnlexer.h b/include/dsnlexer.h index d9f5a24bf9..26724d9298 100644 --- a/include/dsnlexer.h +++ b/include/dsnlexer.h @@ -131,6 +131,13 @@ public: virtual ~DSNLEXER(); + /** + * Reinit variables used during parsing, to ensure od states are not used in a new parsing + * must be called before parsing a new file after parsing an old file to avoid + * starting with some variables in a non initial state + */ + void InitParserState(); + /** * Usable only for DSN lexers which share the same #LINE_READER. * diff --git a/pcbnew/plugins/kicad/kicad_plugin.cpp b/pcbnew/plugins/kicad/kicad_plugin.cpp index bc77a6f313..1028bddb52 100644 --- a/pcbnew/plugins/kicad/kicad_plugin.cpp +++ b/pcbnew/plugins/kicad/kicad_plugin.cpp @@ -265,6 +265,8 @@ void FP_CACHE::Load() FILE_LINE_READER reader( fn.GetFullPath() ); m_owner->m_parser->SetLineReader( &reader ); + // Ensure a previous parsing does not interacts with the new parsing: + m_owner->m_parser->InitParserState(); FOOTPRINT* footprint = (FOOTPRINT*) m_owner->m_parser->Parse(); wxString fpName = fn.GetName(); diff --git a/pcbnew/plugins/kicad/pcb_parser.cpp b/pcbnew/plugins/kicad/pcb_parser.cpp index cbc6d8e4b6..58ee5bc9a0 100644 --- a/pcbnew/plugins/kicad/pcb_parser.cpp +++ b/pcbnew/plugins/kicad/pcb_parser.cpp @@ -637,6 +637,9 @@ BOARD_ITEM* PCB_PARSER::Parse() token = CurTok(); + if( token == -1 ) // EOF + Unexpected( token ); + if( token != T_LEFT ) Expecting( T_LEFT );