Commit 85477537 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

more richio enhancements, /new work, SCH::LIB_TABLE nearly finished

parent 258cebf1
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
@@ -4,6 +4,20 @@ KiCad ChangeLog 2010
Please add newer entries at the top, list the date and your name with
email address.

2010-Dec-28 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++new:
    Completed a good portion of /new class LIB_TABLE.
    Starting LPID.
++common:
    Tricked xnode.h into not issuing deprecation warnings.
++richio:
  * Added support of DSNLEXER( LINE_READER* ) to TokenList2DsnLexer.cmake, which
    allows the chaining of different grammars on top of a common LINE_READER.
  * Changed OUTPUT_FORMATTER::Quoted() to return a std::string and not modify
    its input parameter.


2010-dec-21 UPDATE Wayne Stambaugh <stambaughw@verizon.net>
================================================================================
++all
+21 −3
Original line number Diff line number Diff line
@@ -223,8 +223,9 @@ using namespace DSN; // enum ${enum} is in this namespace
class ${RESULT}_LEXER : public DSNLEXER
{
public:

    /**
     * Constructor ${RESULT}_LEXER
     * Constructor ( const std::string&, const wxString& )
     * @param aSExpression is (utf8) text possibly from the clipboard that you want to parse.
     * @param aSource is a description of the origin of @a aSExpression, such as a filename.
     *   If left empty, then _("clipboard") is used.
@@ -236,7 +237,7 @@ public:
    }

    /**
     * Constructor ${RESULT}_LEXER
     * Constructor ( FILE* )
     * takes @a aFile already opened for reading and @a aFilename as parameters.
     * The opened file is assumed to be positioned at the beginning of the file
     * for purposes of accurate line number reporting in error messages.  The
@@ -250,6 +251,23 @@ public:
    {
    }

    /**
     * Constructor ( LINE_READER* )
     * intializes a lexer and prepares to read from @a aLineReader which
     * is assumed ready, and may be in use by other DSNLEXERs also.  No ownership
     * is taken of @a aLineReader. This enables it to be used by other lexers also.
     * The transition between grammars in such a case, must happen on a text
     * line boundary, not within the same line of text.
     *
     * @param aLineReader is any subclassed instance of LINE_READER, such as
     *  STRING_LINE_READER or FILE_LINE_READER.  No ownership is taken of aLineReader.
     */
    ${RESULT}_LEXER( LINE_READER* aLineReader ) :
        DSNLEXER( DSN::${result}_keywords, DSN::${result}_keyword_count,
                  aLineReader )
    {
    }

    /**
     * Function NextTok
     * returns the next token found in the input file or T_EOF when reaching
+25 −1
Original line number Diff line number Diff line
@@ -62,6 +62,7 @@ void DSNLEXER::init()

DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
                    FILE* aFile, const wxString& aFilename ) :
    iOwnReaders( true ),
    keywords( aKeywordTable ),
    keywordCount( aKeywordCount )
{
@@ -73,6 +74,7 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,

DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
                    const std::string& aClipboardTxt, const wxString& aSource ) :
    iOwnReaders( true ),
    keywords( aKeywordTable ),
    keywordCount( aKeywordCount )
{
@@ -83,6 +85,28 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
}


DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
                    LINE_READER* aLineReader ) :
    iOwnReaders( false ),
    keywords( aKeywordTable ),
    keywordCount( aKeywordCount )
{
    PushReader( aLineReader );
    init();
}


DSNLEXER::~DSNLEXER()
{
    if( iOwnReaders )
    {
        // delete the LINE_READERs from the stack, since I own them.
        for( READER_STACK::iterator it = readerStack.begin(); it!=readerStack.end();  ++it )
            delete *it;
    }
}


void DSNLEXER::PushReader( LINE_READER* aLineReader )
{
    readerStack.push_back( aLineReader );
@@ -102,7 +126,7 @@ bool DSNLEXER::PopReader()
    {
        readerStack.pop_back();

        reader = &readerStack.back();
        reader = readerStack.back();
        start  = (char*) (*reader);

        // force a new readLine() as first thing.
+12 −10
Original line number Diff line number Diff line
@@ -278,30 +278,32 @@ int OUTPUTFORMATTER::Print( int nestLevel, const char* fmt, ... ) throw( IO_ERRO
}


const char* OUTPUTFORMATTER::Quoted( std::string* aWrapee ) throw( IO_ERROR )
std::string OUTPUTFORMATTER::Quoted( const std::string& aWrapee ) throw( IO_ERROR )
{
    // derived class's notion of what a quote character is
    char quote          = *GetQuoteChar( "(" );

    // Will the string be wrapped based on its interior content?
    const char* squote  = GetQuoteChar( aWrapee->c_str() );
    const char* squote  = GetQuoteChar( aWrapee.c_str() );

    std::string wrapee  = aWrapee;  // return this

    // Search the interior of the string for 'quote' chars
    // and replace them as found with duplicated quotes.
    // Note that necessarily any string which has internal quotes will
    // also be wrapped in quotes later in this function.
    for( unsigned i=0;  i<aWrapee->size();  ++i )
    for( unsigned i=0;  i<wrapee.size();  ++i )
    {
        if( (*aWrapee)[i] == quote )
        if( wrapee[i] == quote )
        {
            aWrapee->insert( aWrapee->begin()+i, quote );
            wrapee.insert( wrapee.begin()+i, quote );
            ++i;
        }
        else if( (*aWrapee)[0]=='\r' || (*aWrapee)[0]=='\n' )
        else if( wrapee[i]=='\r' || wrapee[i]=='\n' )
        {
            // In a desire to maintain accurate line number reporting within DSNLEXER
            // a decision was made to make all S-expression strings be on a single
            // line.  You can embedd \n (human readable) in the text but not
            // line.  You can embed \n (human readable) in the text but not
            // '\n' which is 0x0a.
            throw IO_ERROR( _( "S-expression string has newline" ) );
        }
@@ -310,11 +312,11 @@ const char* OUTPUTFORMATTER::Quoted( std::string* aWrapee ) throw( IO_ERROR )
    if( *squote )
    {
        // wrap the beginning and end of the string in a quote.
        aWrapee->insert( aWrapee->begin(), quote );
        aWrapee->insert( aWrapee->end(), quote );
        wrapee.insert( wrapee.begin(), quote );
        wrapee.insert( wrapee.end(), quote );
    }

    return aWrapee->c_str();
    return wrapee;
}


+5 −7
Original line number Diff line number Diff line
@@ -50,17 +50,14 @@ void XNODE::Format( OUTPUTFORMATTER* out, int nestLevel ) throw( IO_ERROR )

void XNODE::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IO_ERROR )
{
    std::string utf8;

    // output attributes first if they exist
    for( XATTR* attr = (XATTR*) GetAttributes();  attr;  attr = (XATTR*) attr->GetNext() )
    {
        utf8  = CONV_TO_UTF8( attr->GetValue() );   // capture the content

        out->Print( 0, " (%s %s)",
            // attr names should never need quoting, no spaces, we designed the file.
            CONV_TO_UTF8( attr->GetName() ),
            out->Quoted( &utf8 ) );
            out->Quoted( CONV_TO_UTF8( attr->GetValue() ) ).c_str()
            );
    }

    // we only expect to have used one of two types here:
@@ -85,8 +82,9 @@ void XNODE::FormatContents( OUTPUTFORMATTER* out, int nestLevel ) throw( IO_ERRO
        break;

    case wxXML_TEXT_NODE:
        utf8  = CONV_TO_UTF8( GetContent() );
        out->Print( 0, " %s", out->Quoted( &utf8 ) );
        out->Print( 0, " %s",
            out->Quoted( CONV_TO_UTF8( GetContent() ) ).c_str()
            );
        break;

    default:
Loading