From a6cbee35c5c45e1ff773be1224d87bb09a275ab0 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Thu, 17 Jun 2010 13:21:28 -0500 Subject: [PATCH 1/4] use Unexpected not Expected --- pcbnew/specctra.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pcbnew/specctra.cpp b/pcbnew/specctra.cpp index 6cf2e0356f..f2eee90bd9 100644 --- a/pcbnew/specctra.cpp +++ b/pcbnew/specctra.cpp @@ -560,7 +560,7 @@ void SPECCTRA_DB::expecting( const char* text ) throw( IOError ) void SPECCTRA_DB::unexpected( DSN_T aTok ) throw( IOError ) { - lexer->Expecting( aTok ); + lexer->Unexpected( aTok ); } void SPECCTRA_DB::unexpected( const char* text ) throw( IOError ) From 1ff2b5596f479e3d8c7f65db93b1c93acb481371 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Thu, 17 Jun 2010 14:27:27 -0500 Subject: [PATCH 2/4] Forgot to give Brian credit --- CHANGELOG.txt | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 9cc37b4c09..90b8691d87 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -7,7 +7,11 @@ email address. 2010-Jun-17 UPDATE Dick Hollenbeck ================================================================================ ++eeschema: - Added "template fieldnames" to eeschema. This is a list of template elements + Added "template fieldnames" to eeschema. Thanks to + Brian Sidebotham for the origins of this patch. + https://lists.launchpad.net/kicad-developers/msg04828.html + + A template fieldnames are a list of template elements consisting of {name, value, visibility} which you want shown in the eeschema component fieldname (property) editors (both schematic and library versions of the editors). Template fieldnames are forced into the editors' From 0361ad6a55ec5db9d2ef640c564f59d0f33de082 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Fri, 18 Jun 2010 11:00:16 -0500 Subject: [PATCH 3/4] factor some pioneering code into a the stable building block class DSNLEXER, generalize expected valued for name and value within the template field parser. --- common/dsnlexer.cpp | 45 ++++++++++++++++++++++++++++ eeschema/template_fieldnames.cpp | 20 +++++-------- include/dsnlexer.h | 46 +++++++++++++++++++++++++++-- pcbnew/specctra.cpp | 50 -------------------------------- pcbnew/specctra.h | 37 +++++++++++++++++------ 5 files changed, 124 insertions(+), 74 deletions(-) diff --git a/common/dsnlexer.cpp b/common/dsnlexer.cpp index 151fa6d405..66fb642bd8 100644 --- a/common/dsnlexer.cpp +++ b/common/dsnlexer.cpp @@ -192,6 +192,18 @@ wxString DSNLEXER::GetTokenString( int aTok ) } +bool DSNLEXER::IsSymbol( int aTok ) +{ + // This is static and not inline to reduce code space. + + // if aTok is >= 0, then it is a coincidental match to a keyword. + return aTok==DSN_SYMBOL + || aTok==DSN_STRING + || aTok>=0 + ; +} + + void DSNLEXER::ThrowIOError( wxString aText, int charOffset ) throw (IOError) { // append to aText, do not overwrite @@ -235,6 +247,39 @@ void DSNLEXER::Unexpected( const wxString& text ) throw( IOError ) } +void DSNLEXER::NeedLEFT() throw( IOError ) +{ + int tok = NextTok(); + if( tok != DSN_LEFT ) + Expecting( DSN_LEFT ); +} + + +void DSNLEXER::NeedRIGHT() throw( IOError ) +{ + int tok = NextTok(); + if( tok != DSN_RIGHT ) + Expecting( DSN_RIGHT ); +} + + +int DSNLEXER::NeedSYMBOL() throw( IOError ) +{ + int tok = NextTok(); + if( !IsSymbol( tok ) ) + Expecting( DSN_SYMBOL ); + return tok; +} + + +int DSNLEXER::NeedSYMBOLorNUMBER() throw( IOError ) +{ + int tok = NextTok(); + if( !IsSymbol( tok ) && tok!=DSN_NUMBER ) + Expecting( _("symbol|number") ); + return tok; +} + /** * Function isspace * strips the upper bits of the int to ensure the value passed to ::isspace() is diff --git a/eeschema/template_fieldnames.cpp b/eeschema/template_fieldnames.cpp index a4a4fd01b1..daa21419db 100644 --- a/eeschema/template_fieldnames.cpp +++ b/eeschema/template_fieldnames.cpp @@ -50,35 +50,29 @@ void TEMPLATE_FIELDNAME::Parse( DSNLEXER* in ) throw( IOError ) { TFIELD_T tok; - if( (tok = (TFIELD_T) in->NextTok()) != T_LEFT ) - in->Expecting( T_LEFT ); + in->NeedLEFT(); // begin (name ...) if( (tok = (TFIELD_T) in->NextTok()) != T_name ) in->Expecting( T_name ); - if( (tok = (TFIELD_T) in->NextTok()) != T_SYMBOL && tok!=T_STRING ) - in->Expecting( _("field's name") ); + in->NeedSYMBOLorNUMBER(); m_Name = CONV_FROM_UTF8( in->CurText() ); - if( (tok = (TFIELD_T) in->NextTok()) != T_RIGHT ) - in->Expecting( T_RIGHT ); + in->NeedRIGHT(); // end (name ...) while( (tok = (TFIELD_T) in->NextTok() ) != T_RIGHT && tok != T_EOF ) { + // "visible" has no '(' prefix, "value" does, so T_LEFT is optional. if( tok == T_LEFT ) tok = (TFIELD_T) in->NextTok(); switch( tok ) { case T_value: - if( (tok = (TFIELD_T) in->NextTok()) != T_SYMBOL && tok!=T_STRING ) - in->Expecting( _("field's value") ); - + in->NeedSYMBOLorNUMBER(); m_Value = CONV_FROM_UTF8( in->CurText() ); - - if( (tok = (TFIELD_T) in->NextTok()) != T_RIGHT ) - in->Expecting( T_RIGHT ); + in->NeedRIGHT(); break; case T_visible: @@ -86,7 +80,7 @@ void TEMPLATE_FIELDNAME::Parse( DSNLEXER* in ) throw( IOError ) break; default: - in->Unexpected( CONV_FROM_UTF8( in->CurText() ) ); + in->Expecting( wxT( "value|visible" ) ); break; } } diff --git a/include/dsnlexer.h b/include/dsnlexer.h index 363b44d259..acda44614a 100644 --- a/include/dsnlexer.h +++ b/include/dsnlexer.h @@ -208,10 +208,9 @@ public: return old; } - /** * Function NextTok - * returns the next token found in the input file or T_EOF when reaching + * returns the next token found in the input file or DSN_EOF when reaching * the end of file. Users should wrap this function to return an enum * to aid in grammar debugging while running under a debugger, but leave * this lower level function returning an int (so the enum does not collide @@ -221,6 +220,13 @@ public: */ int NextTok() throw (IOError); + /** + * Function IsSymbol + * tests a token to see if it is a symbol. This means it cannot be a + * special delimiter character such as DSN_LEFT, DSN_RIGHT, DSN_QUOTE, etc. It may + * however, coincidentally match a keyword and still be a symbol. + */ + static bool IsSymbol( int aTok ); /** * Function ThrowIOError @@ -264,6 +270,42 @@ public: */ void Unexpected( const wxString& aErrorMsg ) throw( IOError ); + /** + * Function NeedLEFT + * calls NextTok() and then verifies that the token read in is a DSN_LEFT. + * If it is not, an IOError is thrown. + * @throw IOError, if the next token is not a DSN_LEFT + */ + void NeedLEFT() throw( IOError ); + + /** + * Function NeedRIGHT + * calls NextTok() and then verifies that the token read in is a DSN_RIGHT. + * If it is not, an IOError is thrown. + * @throw IOError, if the next token is not a DSN_RIGHT + */ + void NeedRIGHT() throw( IOError ); + + /** + * Function NeedSYMBOL + * calls NextTok() and then verifies that the token read in + * satisfies bool IsSymbol(). + * If not, an IOError is thrown. + * @return int - the actual token read in. + * @throw IOError, if the next token does not satisfy IsSymbol() + */ + int NeedSYMBOL() throw( IOError ); + + /** + * Function NeedSYMBOLorNUMBER + * calls NextTok() and then verifies that the token read in + * satisfies bool IsSymbol() or tok==DSN_NUMBER. + * If not, an IOError is thrown. + * @return int - the actual token read in. + * @throw IOError, if the next token does not satisfy the above test + */ + int NeedSYMBOLorNUMBER() throw( IOError ); + /** * Function GetTokenText * returns the C string representation of a DSN_T value. diff --git a/pcbnew/specctra.cpp b/pcbnew/specctra.cpp index f2eee90bd9..13b52b618e 100644 --- a/pcbnew/specctra.cpp +++ b/pcbnew/specctra.cpp @@ -547,21 +547,12 @@ void SPECCTRA_DB::ThrowIOError( const wxChar* fmt, ... ) throw( IOError ) } -void SPECCTRA_DB::expecting( DSN_T aTok ) throw( IOError ) -{ - lexer->Expecting( aTok ); -} - void SPECCTRA_DB::expecting( const char* text ) throw( IOError ) { wxString errText = CONV_FROM_UTF8( text ); lexer->Expecting( errText ); } -void SPECCTRA_DB::unexpected( DSN_T aTok ) throw( IOError ) -{ - lexer->Unexpected( aTok ); -} void SPECCTRA_DB::unexpected( const char* text ) throw( IOError ) { @@ -576,47 +567,6 @@ DSN_T SPECCTRA_DB::nextTok() return ret; } - -bool SPECCTRA_DB::isSymbol( DSN_T aTok ) -{ - // if aTok is >= 0, then it might be a coincidental match to a keyword. - return aTok==T_SYMBOL - || aTok==T_STRING - || aTok>=0 - ; -} - - -void SPECCTRA_DB::needLEFT() throw( IOError ) -{ - DSN_T tok = nextTok(); - if( tok != T_LEFT ) - expecting( T_LEFT ); -} - -void SPECCTRA_DB::needRIGHT() throw( IOError ) -{ - DSN_T tok = nextTok(); - if( tok != T_RIGHT ) - expecting( T_RIGHT ); -} - -DSN_T SPECCTRA_DB::needSYMBOL() throw( IOError ) -{ - DSN_T tok = nextTok(); - if( !isSymbol( tok ) ) - expecting( T_SYMBOL ); - return tok; -} - -DSN_T SPECCTRA_DB::needSYMBOLorNUMBER() throw( IOError ) -{ - DSN_T tok = nextTok(); - if( !isSymbol( tok ) && tok!=T_NUMBER ) - expecting( "symbol|number" ); - return tok; -} - void SPECCTRA_DB::readCOMPnPIN( std::string* component_id, std::string* pin_id ) throw( IOError ) { DSN_T tok; diff --git a/pcbnew/specctra.h b/pcbnew/specctra.h index 7039c4cf65..4b27d03988 100644 --- a/pcbnew/specctra.h +++ b/pcbnew/specctra.h @@ -4039,15 +4039,16 @@ class SPECCTRA_DB : public OUTPUTFORMATTER */ DSN_T nextTok(); - /** * Function isSymbol * tests a token to see if it is a symbol. This means it cannot be a * special delimiter character such as T_LEFT, T_RIGHT, T_QUOTE, etc. It may * however, coincidentally match a keyword and still be a symbol. */ - static bool isSymbol( DSN_T aTok ); - + static bool isSymbol( DSN_T aTok ) + { + return DSNLEXER::IsSymbol( aTok ); + } /** * Function needLEFT @@ -4055,7 +4056,10 @@ class SPECCTRA_DB : public OUTPUTFORMATTER * If it is not, an IOError is thrown. * @throw IOError, if the next token is not a T_LEFT */ - void needLEFT() throw( IOError ); + void needLEFT() throw( IOError ) + { + lexer->NeedLEFT(); + } /** * Function needRIGHT @@ -4063,7 +4067,10 @@ class SPECCTRA_DB : public OUTPUTFORMATTER * If it is not, an IOError is thrown. * @throw IOError, if the next token is not a T_RIGHT */ - void needRIGHT() throw( IOError ); + void needRIGHT() throw( IOError ) + { + lexer->NeedRIGHT(); + } /** * Function needSYMBOL @@ -4073,7 +4080,10 @@ class SPECCTRA_DB : public OUTPUTFORMATTER * @return DSN_T - the actual token read in. * @throw IOError, if the next token does not satisfy isSymbol() */ - DSN_T needSYMBOL() throw( IOError ); + DSN_T needSYMBOL() throw( IOError ) + { + return (DSN_T) lexer->NeedSYMBOL(); + } /** * Function needSYMBOLorNUMBER @@ -4083,7 +4093,10 @@ class SPECCTRA_DB : public OUTPUTFORMATTER * @return DSN_T - the actual token read in. * @throw IOError, if the next token does not satisfy the above test */ - DSN_T needSYMBOLorNUMBER() throw( IOError ); + DSN_T needSYMBOLorNUMBER() throw( IOError ) + { + return (DSN_T) lexer->NeedSYMBOLorNUMBER(); + } /** * Function readCOMPnPIN @@ -4127,9 +4140,15 @@ class SPECCTRA_DB : public OUTPUTFORMATTER * @param int is the token type which was expected at the current input location. * @throw IOError with the location within the input file of the problem. */ - void expecting( DSN_T aTok ) throw( IOError ); + void expecting( DSN_T aTok ) throw( IOError ) + { + lexer->Expecting( aTok ); + } + void unexpected( DSN_T aTok ) throw( IOError ) + { + lexer->Unexpected( aTok ); + } void expecting( const char* text ) throw( IOError ); - void unexpected( DSN_T aTok ) throw( IOError ); void unexpected( const char* text ) throw( IOError ); void doPCB( PCB* growth ) throw(IOError); From fcbcb64058471aa7e1f4e34ed7ebcef1008bd675 Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Fri, 18 Jun 2010 11:12:15 -0500 Subject: [PATCH 4/4] *.lst -> *.keywords, rename input filenames to CMake script TokenList2DsnLexer.cmake --- CMakeModules/TokenList2DsnLexer.cmake | 4 ++-- eeschema/CMakeLists.txt | 12 ++++++------ eeschema/{cmp_library.lst => cmp_library.keywords} | 0 ...e_fieldnames.lst => template_fieldnames.keywords} | 0 4 files changed, 8 insertions(+), 8 deletions(-) rename eeschema/{cmp_library.lst => cmp_library.keywords} (100%) rename eeschema/{template_fieldnames.lst => template_fieldnames.keywords} (100%) diff --git a/CMakeModules/TokenList2DsnLexer.cmake b/CMakeModules/TokenList2DsnLexer.cmake index 49ae4a7683..4223089373 100644 --- a/CMakeModules/TokenList2DsnLexer.cmake +++ b/CMakeModules/TokenList2DsnLexer.cmake @@ -43,9 +43,9 @@ # ${CMAKE_BINARY_DIR}/cmp_library_keywords.cpp # COMMAND ${CMAKE_COMMAND} # -Denum=YOURTOK_T -# -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst +# -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords # -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake -# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst +# DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords # ) # # Input parameters: diff --git a/eeschema/CMakeLists.txt b/eeschema/CMakeLists.txt index 956dfaf86c..f260c712a3 100644 --- a/eeschema/CMakeLists.txt +++ b/eeschema/CMakeLists.txt @@ -160,11 +160,11 @@ add_custom_command( OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.h ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.cpp COMMAND ${CMAKE_COMMAND} - -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst + -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords COMMENT "creating ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library_keywords.h(.cpp) - from ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.lst" + from ${CMAKE_CURRENT_SOURCE_DIR}/cmp_library.keywords" ) set_source_files_properties( cmp_library_lexer.cpp PROPERTIES @@ -177,11 +177,11 @@ add_custom_command( ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.cpp COMMAND ${CMAKE_COMMAND} -Denum=TFIELD_T - -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.lst + -DinputFile=${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords -P ${CMAKE_MODULE_PATH}/TokenList2DsnLexer.cmake - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.lst + DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords COMMENT "creating ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames_keywords.h(.cpp) - from ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.lst" + from ${CMAKE_CURRENT_SOURCE_DIR}/template_fieldnames.keywords" ) diff --git a/eeschema/cmp_library.lst b/eeschema/cmp_library.keywords similarity index 100% rename from eeschema/cmp_library.lst rename to eeschema/cmp_library.keywords diff --git a/eeschema/template_fieldnames.lst b/eeschema/template_fieldnames.keywords similarity index 100% rename from eeschema/template_fieldnames.lst rename to eeschema/template_fieldnames.keywords