From 115d1adbebeb93b97a505708f8ffd468341e809d Mon Sep 17 00:00:00 2001 From: Dick Hollenbeck Date: Mon, 28 Mar 2011 00:02:59 -0500 Subject: [PATCH] more sweet parser & beginnings of Format()ing --- new/eeschema_part_sexpr_format_EN.odt | Bin 21086 -> 21090 bytes new/make-dir-lib-source-test-data.sh | 5 + new/sch_part.cpp | 73 +++- new/sch_part.h | 39 ++- new/sch_sweet_parser.cpp | 487 ++++++++++++++------------ new/sch_sweet_parser.h | 11 + 6 files changed, 375 insertions(+), 240 deletions(-) diff --git a/new/eeschema_part_sexpr_format_EN.odt b/new/eeschema_part_sexpr_format_EN.odt index a202786ef9d8be8b651fe65b31c9915c71e095c2..638bc853c1c71d9f887f9b9229f56b55278c4481 100644 GIT binary patch delta 6118 zcmZ8l1yG#JvR*7muwYBF*y8T)?k>UIJ=h`v77Y%81%hj^z#<`daCd?`fdmf_G&qms zoO9njx2yi@>8|;DdS?FWuclYuBW%1!z*1L2LM8wJ&;WoHGXF#@MWjbnW8jVjl}bH2 zC`kb3j;W1R_337YUu^80&hUz~UEc0)d_SGhed!m7-xNaMkAZiGzf;{Pz232Q)*Y|O zhjh3$9fE6&>{onaVoJWWq1?C$P?>cUA|syOyE(KShX`MVD^FkP7Pb#fKbQfZr6TCCo(Lz!|$gL5-l zZzA38{92S=U7LNJNT%T|ld(cKAtS-~DkZ>fR}h&|u&OUF7_O&j5$Fsm@Uyjx7wT}Q z-#{r<41GU-_iD&GG0mnJrwNIJz9{_|H%v5#i>Vfp@}!d6EFidyKI2ApG0n9E%NgHf zf5-Mqqz$;Kr-%@pPLH-x0vhrlxK>BgTznJ2FA(ss9)0)i>~gRB>4gfOOrZ7JTe3Xd zkBCg{5h+?m<+C*7^K3ru;VVNvOuFSLqoPuUw#GUfGj@J-F;i7^@0xUWwQG&hjx1$` zyz@9`P)udAJgh7O@x4dsgJle&G)1F8#N@cd9uM&oU>^OHNM2=pHYnWlJ^`($?CJmA~jW&SJ}2j`_CUx2RASnW%k}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a{O^7G|FQ`e*5kaLtM%LSKb)pYb^rhX diff --git a/new/make-dir-lib-source-test-data.sh b/new/make-dir-lib-source-test-data.sh index 5337384eac..44e1e6441e 100755 --- a/new/make-dir-lib-source-test-data.sh +++ b/new/make-dir-lib-source-test-data.sh @@ -61,6 +61,9 @@ PROP1=" (effects (at 1 34 270)(font (size .5 1) italic bold)(visible no)) )" +KEYWORDS=" + (keywords varistor batcave einstein)" + for C in ${CATEGORIES}; do @@ -79,6 +82,7 @@ for C in ${CATEGORIES}; do $PIN1 $PIN2 $PROP1 + $KEYWORDS )" > $BASEDIR/$C/$P.part.$R done # also make the part without a rev: @@ -93,6 +97,7 @@ for C in ${CATEGORIES}; do $PIN1 $PIN2 $PROP1 + $KEYWORDS )" > $BASEDIR/$C/$P.part done done diff --git a/new/sch_part.cpp b/new/sch_part.cpp index 9ddcb34e3c..6e1fa433c5 100644 --- a/new/sch_part.cpp +++ b/new/sch_part.cpp @@ -28,7 +28,7 @@ #include #include #include - +//#include using namespace SCH; @@ -74,6 +74,11 @@ void PART::clear() delete *it; properties.clear(); + keywords.clear(); + + contains = 0; + + // @todo clear the mandatory fields } @@ -120,12 +125,68 @@ void PART::Parse( SWEET_PARSER* aParser, LIB_TABLE* aTable ) throw( IO_ERROR, PA } -#if 0 && defined(DEBUG) - -int main( int argc, char** argv ) +void PART::PropertyDelete( const wxString& aPropertyName ) throw( IO_ERROR ) { - return 0; + PROPERTIES::iterator it = propertyFind( aPropertyName ); + if( it == properties.end() ) + { + wxString msg; + msg.Printf( _( "Unable to find property: %s" ), aPropertyName.GetData() ); + THROW_IO_ERROR( msg ); + } + + delete *it; + properties.erase( it ); + return; +} + + +PROPERTIES::iterator PART::propertyFind( const wxString& aPropertyName ) +{ + PROPERTIES::iterator it; + for( it = properties.begin(); it!=properties.end(); ++it ) + if( (*it)->name == aPropertyName ) + break; + return it; +} + + +void PART::Format( OUTPUTFORMATTER* out, int indent, int ctl ) const throw( IO_ERROR ) +{ + out->Print( indent, "(part %s", partNameAndRev.c_str() ); + + if( extends ) + out->Print( 0, " inherits %s", extends->Format().c_str() ); + + out->Print( 0, "\n" ); + +/* + @todo + for( int i=0; iFormat( out, indent+1, ctl ); + } + + if( anchor.x || anchor.y ) + { + out->Print( indent+1, "(anchor (at %.6g %.6g))\n", + InternalToLogical( anchor.x ), + InternalToLogical( anchor.y ) ); + } + + for( GRAPHICS::const_iterator it = graphics.begin(); it != graphics.end(); ++it ) + { + (*it)->Format( out, indent+1, ctl ); + } + + for( PINS::const_iterator it = pins.begin(); it != pins.end(); ++it ) + { + (*it)->Format( out, indent+1, ctl ); + } } -#endif diff --git a/new/sch_part.h b/new/sch_part.h index 5dda678b12..021b59953e 100644 --- a/new/sch_part.h +++ b/new/sch_part.h @@ -34,8 +34,10 @@ #include #include #include +#include #include +class OUTPUTFORMATTER; namespace SCH { @@ -114,6 +116,10 @@ public: {} virtual ~BASE_GRAPHIC() {} + + virtual void Format( OUTPUTFORMATTER* aOutputFormatter, int aNestLevel, int aControlBits ) const + throw( IO_ERROR ) + {} }; typedef std::deque POINTS; @@ -278,6 +284,11 @@ public: isVisible( true ) {} +/* + void Format( OUTPUTFORMATTER* aOutputFormatter, int aNestLevel, int aControlBits ) const + throw( IO_ERROR ); +*/ + protected: PART* birthplace; ///< at which PART in inheritance chain was this PIN added POINT pos; @@ -309,6 +320,7 @@ namespace SCH { typedef std::vector< BASE_GRAPHIC* > GRAPHICS; typedef std::vector< PIN* > PINS; typedef std::vector< PROPERTY* > PROPERTIES; +typedef std::set< wxString > KEYWORDS; class LPID; class SWEET_PARSER; @@ -347,6 +359,14 @@ protected: // not likely to have C++ descendants, but protected none-the-le */ void inherit( const PART& aBasePart ); + /** + * Function propertyFind + * searches for aPropertyName and returns a PROPERTIES::iterator which + * is the found item or properties.end() if not found. + */ + PROPERTIES::iterator propertyFind( const wxString& aPropertyName ); + + POINT anchor; //PART( LIB* aOwner ); @@ -396,14 +416,14 @@ protected: // not likely to have C++ descendants, but protected none-the-le /// Alternate body forms. //ALTERNATES alternates; - wxString keywords; + KEYWORDS keywords; public: virtual ~PART(); - PART& operator=( const PART& other ); + PART& operator = ( const PART& other ); /** * Function Owner @@ -424,6 +444,21 @@ public: */ void Parse( SWEET_PARSER* aParser, LIB_TABLE* aLibTable ) throw( IO_ERROR, PARSE_ERROR ); + /** + * Function Format + * outputs this PART in UTF8 encoded s-expression format to @a aFormatter. + * @param aFormatter is the output sink to write to. + * @param aNestLevel is the initial indent level + * @param aControlBits are bit flags ORed together which control how the output + * is done. + */ + void Format( OUTPUTFORMATTER* aFormatter, int aNestLevel, int aControlBits = 0 ) const + throw( IO_ERROR ); + + void PropertyDelete( const wxString& aPropertyName ) throw( IO_ERROR ); + + + /* void SetValue( const wxString& aValue ) { diff --git a/new/sch_sweet_parser.cpp b/new/sch_sweet_parser.cpp index 4850f4d4df..1807fc90b0 100644 --- a/new/sch_sweet_parser.cpp +++ b/new/sch_sweet_parser.cpp @@ -34,7 +34,6 @@ using namespace PR; #define MAX_INHERITANCE_NESTING 6 ///< max depth of inheritance, no problem going larger -#define INTERNAL_PER_LOGICAL 10000 ///< no. internal units per logical unit /** @@ -148,7 +147,7 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E // Caller may not have read the first two tokens out of the // stream: T_LEFT and T_part, so ignore them if seen here. // The 1st two tokens T_LEFT and T_part are then optional in the grammar. - if( (tok = NextTok() ) == T_LEFT ) + if( ( tok = NextTok() ) == T_LEFT ) { if( ( tok = NextTok() ) != T_part ) Expecting( T_part ); @@ -174,236 +173,249 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E for( ; tok!=T_RIGHT; tok = NextTok() ) { - if( tok==T_EOF ) - Unexpected( T_EOF ); - if( tok == T_LEFT ) - tok = NextTok(); - - // because exceptions are thrown, any 'new' allocation has to be stored - // somewhere other than on the stack, ASAP. - - switch( tok ) { - default: - // describe what we expect at this level - Expecting( - "anchor|value|footprint|model|keywords|alternates\n" - "|property\n" - " |property_del\n" - "|pin\n" - " |pin_merge|pin_swap|pin_renum|pin_rename|route_pin_swap\n" - "|polyline|line|rectangle|circle|arc|bezier|text" - ); - break; - - case T_anchor: - if( contains & PB(ANCHOR) ) - Duplicate( tok ); - NeedNUMBER( "anchor x" ); - me->anchor.x = internal( CurText() ); - NeedNUMBER( "anchor y" ); - me->anchor.y = internal( CurText() ); - contains |= PB(ANCHOR); - break; - - case T_line: - case T_polyline: - POLY_LINE* pl; - pl = new POLY_LINE( me ); - me->graphics.push_back( pl ); - parsePolyLine( pl ); - break; - - case T_rectangle: - RECTANGLE* rect; - rect = new RECTANGLE( me ); - me->graphics.push_back( rect ); - parseRectangle( rect ); - break; - - case T_circle: - CIRCLE* circ; - circ = new CIRCLE( me ); - me->graphics.push_back( circ ); - parseCircle( circ ); - break; - - case T_arc: - ARC* arc; - arc = new ARC( me ); - me->graphics.push_back( arc ); - parseArc( arc ); - break; - - case T_bezier: - BEZIER* bezier; - bezier = new BEZIER( me ); - me->graphics.push_back( bezier ); - parseBezier( bezier ); - break; - - case T_text: - GR_TEXT* text; - text = new GR_TEXT( me ); - me->graphics.push_back( text ); - parseText( text ); - break; - - // reference in a PART is incomplete, it is just the prefix of an - // unannotated reference. Only components have full reference designators. - case T_reference: - if( contains & PB(REFERENCE) ) - Duplicate( tok ); - contains |= PB(REFERENCE); - NeedSYMBOLorNUMBER(); - me->reference.text = FromUTF8(); tok = NextTok(); - if( tok == T_LEFT ) + + // because exceptions are thrown, any 'new' allocation has to be stored + // somewhere other than on the stack, ASAP. + + switch( tok ) { - tok = NextTok(); - if( tok != T_effects ) - Expecting( T_effects ); - parseTextEffects( &me->reference.effects ); - NeedRIGHT(); - } - else if( tok != T_RIGHT ) - Expecting( ") | effects" ); - break; + default: + // describe what we expect at this level + Expecting( + "anchor|value|footprint|model|keywords|alternates\n" + "|property\n" + " |property_del\n" + "|pin\n" + " |pin_merge|pin_swap|pin_renum|pin_rename|route_pin_swap\n" + "|polyline|line|rectangle|circle|arc|bezier|text" + ); + break; - case T_value: - if( contains & PB(VALUE) ) - Duplicate( tok ); - contains |= PB(VALUE); - NeedSYMBOLorNUMBER(); - me->value.text = FromUTF8(); - tok = NextTok(); - if( tok == T_LEFT ) + case T_anchor: + if( contains & PB(ANCHOR) ) + Duplicate( tok ); + NeedNUMBER( "anchor x" ); + me->anchor.x = internal( CurText() ); + NeedNUMBER( "anchor y" ); + me->anchor.y = internal( CurText() ); + contains |= PB(ANCHOR); + break; + + case T_line: + case T_polyline: + POLY_LINE* pl; + pl = new POLY_LINE( me ); + me->graphics.push_back( pl ); + parsePolyLine( pl ); + break; + + case T_rectangle: + RECTANGLE* rect; + rect = new RECTANGLE( me ); + me->graphics.push_back( rect ); + parseRectangle( rect ); + break; + + case T_circle: + CIRCLE* circ; + circ = new CIRCLE( me ); + me->graphics.push_back( circ ); + parseCircle( circ ); + break; + + case T_arc: + ARC* arc; + arc = new ARC( me ); + me->graphics.push_back( arc ); + parseArc( arc ); + break; + + case T_bezier: + BEZIER* bezier; + bezier = new BEZIER( me ); + me->graphics.push_back( bezier ); + parseBezier( bezier ); + break; + + case T_text: + GR_TEXT* text; + text = new GR_TEXT( me ); + me->graphics.push_back( text ); + parseText( text ); + break; + + // reference in a PART is incomplete, it is just the prefix of an + // unannotated reference. Only components have full reference designators. + case T_reference: + if( contains & PB(REFERENCE) ) + Duplicate( tok ); + contains |= PB(REFERENCE); + NeedSYMBOLorNUMBER(); + me->reference.text = FromUTF8(); + tok = NextTok(); + if( tok == T_LEFT ) + { + tok = NextTok(); + if( tok != T_effects ) + Expecting( T_effects ); + parseTextEffects( &me->reference.effects ); + NeedRIGHT(); + } + else if( tok != T_RIGHT ) + Expecting( ") | effects" ); + break; + + case T_value: + if( contains & PB(VALUE) ) + Duplicate( tok ); + contains |= PB(VALUE); + NeedSYMBOLorNUMBER(); + me->value.text = FromUTF8(); + tok = NextTok(); + if( tok == T_LEFT ) + { + tok = NextTok(); + if( tok != T_effects ) + Expecting( T_effects ); + parseTextEffects( &me->value.effects ); + NeedRIGHT(); + } + else if( tok != T_RIGHT ) + Expecting( ") | effects" ); + break; + + case T_footprint: + if( contains & PB(FOOTPRINT) ) + Duplicate( tok ); + contains |= PB(FOOTPRINT); + NeedSYMBOLorNUMBER(); + me->footprint.text = FromUTF8(); + tok = NextTok(); + if( tok == T_LEFT ) + { + tok = NextTok(); + if( tok != T_effects ) + Expecting( T_effects ); + parseTextEffects( &me->footprint.effects ); + NeedRIGHT(); + } + else if( tok != T_RIGHT ) + Expecting( ") | effects" ); + break; + + case T_datasheet: + if( contains & PB(MODEL) ) + Duplicate( tok ); + contains |= PB(MODEL); + NeedSYMBOLorNUMBER(); + me->datasheet.text = FromUTF8(); + tok = NextTok(); + if( tok == T_LEFT ) + { + tok = NextTok(); + if( tok != T_effects ) + Expecting( T_effects ); + parseTextEffects( &me->datasheet.effects ); + NeedRIGHT(); + } + else if( tok != T_RIGHT ) + Expecting( ") | effects" ); + break; + + case T_model: + if( contains & PB(MODEL) ) + Duplicate( tok ); + contains |= PB(MODEL); + NeedSYMBOLorNUMBER(); + me->model.text = FromUTF8(); + tok = NextTok(); + if( tok == T_LEFT ) + { + tok = NextTok(); + if( tok != T_effects ) + Expecting( T_effects ); + parseTextEffects( &me->model.effects ); + NeedRIGHT(); + } + else if( tok != T_RIGHT ) + Expecting( ") | effects" ); + break; + + case T_property: + PROPERTY* property; + property = new PROPERTY( me ); + // @todo check for uniqueness + me->properties.push_back( property ); + NeedSYMBOLorNUMBER(); + property->name = FromUTF8(); + NeedSYMBOLorNUMBER(); + property->text = FromUTF8(); + tok = NextTok(); + if( tok == T_LEFT ) + { + tok = NextTok(); + if( tok != T_effects ) + Expecting( T_effects ); + parseTextEffects( &property->effects ); + NeedRIGHT(); + } + else if( tok != T_RIGHT ) + Expecting( ") | effects" ); + break; + + case T_property_del: + NeedSYMBOLorNUMBER(); + me->PropertyDelete( FromUTF8() ); + NeedRIGHT(); + break; + + case T_pin: + PIN* pin; + pin = new PIN( me ); + me->pins.push_back( pin ); + parsePin( pin ); + break; + + case T_keywords: + parseKeywords( me ); + break; + + /* + @todo + + // do we want to inherit alternates? + case T_alternates: + break; + + case T_pin_merge: + break; + + case T_pin_swap: + break; + + case T_pin_renum: + break; + + case T_pin_rename: + break; + + case T_route_pin_swap: + break; + + */ + } + } + + else + { + switch( tok ) { - tok = NextTok(); - if( tok != T_effects ) - Expecting( T_effects ); - parseTextEffects( &me->value.effects ); - NeedRIGHT(); + default: + Unexpected( tok ); } - else if( tok != T_RIGHT ) - Expecting( ") | effects" ); - break; - - case T_footprint: - if( contains & PB(FOOTPRINT) ) - Duplicate( tok ); - contains |= PB(FOOTPRINT); - NeedSYMBOLorNUMBER(); - me->footprint.text = FromUTF8(); - tok = NextTok(); - if( tok == T_LEFT ) - { - tok = NextTok(); - if( tok != T_effects ) - Expecting( T_effects ); - parseTextEffects( &me->footprint.effects ); - NeedRIGHT(); - } - else if( tok != T_RIGHT ) - Expecting( ") | effects" ); - break; - - case T_datasheet: - if( contains & PB(MODEL) ) - Duplicate( tok ); - contains |= PB(MODEL); - NeedSYMBOLorNUMBER(); - me->datasheet.text = FromUTF8(); - tok = NextTok(); - if( tok == T_LEFT ) - { - tok = NextTok(); - if( tok != T_effects ) - Expecting( T_effects ); - parseTextEffects( &me->datasheet.effects ); - NeedRIGHT(); - } - else if( tok != T_RIGHT ) - Expecting( ") | effects" ); - break; - - case T_model: - if( contains & PB(MODEL) ) - Duplicate( tok ); - contains |= PB(MODEL); - NeedSYMBOLorNUMBER(); - me->model.text = FromUTF8(); - tok = NextTok(); - if( tok == T_LEFT ) - { - tok = NextTok(); - if( tok != T_effects ) - Expecting( T_effects ); - parseTextEffects( &me->model.effects ); - NeedRIGHT(); - } - else if( tok != T_RIGHT ) - Expecting( ") | effects" ); - break; - - case T_property: - PROPERTY* property; - property = new PROPERTY( me ); - // @todo check for uniqueness - me->properties.push_back( property ); - NeedSYMBOLorNUMBER(); - property->name = FromUTF8(); - NeedSYMBOLorNUMBER(); - property->text = FromUTF8(); - tok = NextTok(); - if( tok == T_LEFT ) - { - tok = NextTok(); - if( tok != T_effects ) - Expecting( T_effects ); - parseTextEffects( &property->effects ); - NeedRIGHT(); - } - else if( tok != T_RIGHT ) - Expecting( ") | effects" ); - break; - - case T_pin: - PIN* pin; - pin = new PIN( me ); - me->pins.push_back( pin ); - parsePin( pin ); - break; - - -/* - @todo - case T_keywords: - break; - - case T_alternates: - break; - - case T_property_del: - break; - - case T_pin_merge: - break; - - case T_pin_swap: - break; - - case T_pin_renum: - break; - - case T_pin_rename: - break; - - case T_route_pin_swap: - break; - -*/ } } @@ -413,6 +425,21 @@ void SWEET_PARSER::Parse( PART* me, LIB_TABLE* aTable ) throw( IO_ERROR, PARSE_E } +void SWEET_PARSER::parseKeywords( PART* me ) +{ + T tok; + + while( ( tok = NextTok() ) != T_RIGHT ) + { + if( !IsSymbol( tok ) && tok!=T_NUMBER ) + Expecting( "symbol|number" ); + + // just insert them, duplicates are silently removed and tossed. + me->keywords.insert( FromUTF8() ); + } +} + + void SWEET_PARSER::parseFont( FONT* me ) { /* @@ -436,7 +463,7 @@ void SWEET_PARSER::parseFont( FONT* me ) tok = NextTok(); } - while( tok != T_RIGHT ) + for( ; tok != T_RIGHT; tok = NextTok() ) { if( tok == T_LEFT ) { @@ -483,8 +510,6 @@ void SWEET_PARSER::parseFont( FONT* me ) Unexpected( "bold|italic" ); } } - - tok = NextTok(); } } @@ -681,7 +706,7 @@ void SWEET_PARSER::parseTextEffects( TEXT_EFFECTS* me ) /* (effects [PROPERTY] - # Position requires an X and Y coordinates. Position coordinates can be + # Position requires X and Y coordinates. Position coordinates can be # non-intergr. Angle is in degrees and defaults to 0 if not defined. (at X Y [ANGLE]) @@ -709,7 +734,7 @@ void SWEET_PARSER::parseTextEffects( TEXT_EFFECTS* me ) tok = NextTok(); } - while( tok != T_RIGHT ) + for( ; tok != T_RIGHT; tok = NextTok() ) { if( tok != T_LEFT ) Expecting( T_LEFT ); @@ -743,8 +768,6 @@ void SWEET_PARSER::parseTextEffects( TEXT_EFFECTS* me ) default: Expecting( "at|font|visible" ); } - - tok = NextTok(); } } diff --git a/new/sch_sweet_parser.h b/new/sch_sweet_parser.h index 8b6f86f799..44584b46f0 100644 --- a/new/sch_sweet_parser.h +++ b/new/sch_sweet_parser.h @@ -28,6 +28,16 @@ #include #include + +#define INTERNAL_PER_LOGICAL 10000 ///< no. internal units per logical unit + + +static inline double InternalToLogical( int aCoord ) +{ + return double( aCoord ) / INTERNAL_PER_LOGICAL; +} + + class POINT; namespace SCH { @@ -80,6 +90,7 @@ class SWEET_PARSER : public SWEET_LEXER void parseFont( FONT* me ); void parsePinText( PINTEXT* me ); void parseTextEffects( TEXT_EFFECTS* me ); + void parseKeywords( PART* me ); public: