Commit 84ed5f50 authored by Dick Hollenbeck's avatar Dick Hollenbeck
Browse files

++new:

  * Added the basic structure to the Sweet parser in sch_part.cpp.
  * Got inheritence working off of the 'extends' keyword and PART::inherit()
  * Tossed the units support out of sweet.keywords, since we agreed to go dimensionless.
++richio:
  * Added the problemInputLine support to PARSE_ERROR, so UI can show the
    offending line of bytes.  Yes bytes, not even guaranteed to be characters.
parent e7d5770f
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -4,6 +4,17 @@ KiCad ChangeLog 2010
Please add newer entries at the top, list the date and your name with
email address.

2011-Jan-1 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++new:
  * Added the basic structure to the Sweet parser in sch_part.cpp.
  * Got inheritence working off of the 'extends' keyword and PART::inherit()
  * Tossed the units support out of sweet.keywords, since we agreed to go dimensionless.
++richio:
  * Added the problemInputLine support to PARSE_ERROR, so UI can show the
    offending line of bytes.  Yes bytes, not even guaranteed to be characters.


2010-dec-31 UPDATE Wayne Stambaugh <stambaughw@verizon.net>
================================================================================
++all
+16 −22
Original line number Diff line number Diff line
@@ -231,7 +231,7 @@ wxString DSNLEXER::GetTokenString( int aTok )
{
    wxString    ret;

    ret << wxT("'") << wxConvertMB2WX( GetTokenText(aTok) ) << wxT("'");
    ret << wxT("'") << wxString::FromUTF8( GetTokenText(aTok) ) << wxT("'");

    return ret;
}
@@ -249,24 +249,11 @@ bool DSNLEXER::IsSymbol( int aTok )
}


void DSNLEXER::ThrowIOError( wxString aText, int charOffset ) throw( IO_ERROR )
{
    // @todo convert this to THROW_PARSE_ERROR()

    // append to aText, do not overwrite
    aText << wxT(" ") << _("in") << wxT(" \"") << CurSource()
          << wxT("\" ") << _("on line") << wxT(" ") << reader->LineNumber()
          << wxT(" ") << _("at offset") << wxT(" ") << charOffset;

    THROW_IO_ERROR( aText );
}


void DSNLEXER::Expecting( int aTok ) throw( IO_ERROR )
{
    wxString    errText( _("Expecting") );
    errText << wxT(" ") << GetTokenString( aTok );
    ThrowIOError( errText, CurOffset() );
    THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}


@@ -274,7 +261,7 @@ void DSNLEXER::Expecting( const wxString& text ) throw( IO_ERROR )
{
    wxString    errText( _("Expecting") );
    errText << wxT(" '") << text << wxT("'");
    ThrowIOError( errText, CurOffset() );
    THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}


@@ -282,15 +269,22 @@ void DSNLEXER::Unexpected( int aTok ) throw( IO_ERROR )
{
    wxString    errText( _("Unexpected") );
    errText << wxT(" ") << GetTokenString( aTok );
    ThrowIOError( errText, CurOffset() );
    THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}

void DSNLEXER::Duplicate( int aTok ) throw( IO_ERROR )
{
    wxString    errText;

    errText.Printf( _("%s is a duplicate"), GetTokenString( aTok ).GetData() );
    THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}

void DSNLEXER::Unexpected( const wxString& text ) throw( IO_ERROR )
{
    wxString    errText( _("Unexpected") );
    errText << wxT(" '") << text << wxT("'");
    ThrowIOError( errText, CurOffset() );
    THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}


@@ -408,7 +402,7 @@ L_read:
            case '"':
                break;
            default:
                ThrowIOError( errtxt, CurOffset() );
                THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
            }

            curText = cc;
@@ -417,7 +411,7 @@ L_read:

            if( head<limit && *head!=')' && *head!='(' && !isSpace(*head) )
            {
                ThrowIOError( errtxt, CurOffset() );
                THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
            }

            curTok = DSN_QUOTE_DEF;
@@ -514,7 +508,7 @@ L_read:
            }

            wxString errtxt(_("Un-terminated delimited string") );
            ThrowIOError( errtxt, CurOffset() );
            THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() );

#else   // old code, did not understand nested quotes
            ++cur;  // skip over the leading delimiter: ",', or $
@@ -527,7 +521,7 @@ L_read:
            if( head >= limit )
            {
                wxString errtxt(_("Un-terminated delimited string") );
                ThrowIOError( errtxt, CurOffset() );
                THROW_PARSE_ERROR( errtxt, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
            }

            curText.clear();
+31 −8
Original line number Diff line number Diff line
@@ -330,13 +330,6 @@ public:
     */
    static bool IsSymbol( int aTok );

    /**
     * Function ThrowIOError
     * encapsulates the formatting of an error message which contains the exact
     * location within the input file of something the caller is rejecting.
     */
    void ThrowIOError( wxString aText, int charOffset ) throw( IO_ERROR );

    /**
     * Function Expecting
     * throws an IO_ERROR exception with an input file specific error message.
@@ -363,6 +356,16 @@ public:
     */
    void Unexpected( int aTok ) throw( IO_ERROR );

    /**
     * Function Duplicate
     * throws an IO_ERROR exception with a message saying specifically that aTok
     * is a duplicate of one already seen in current context.
     * @param aTok is the token/keyword type which was not expected at the
     *         current input location.
     * @throw IO_ERROR with the location within the input file of the problem.
     */
    void Duplicate( int aTok ) throw( IO_ERROR );

    /**
     * Function Unexpected
     * throws an IO_ERROR exception with an input file specific error message.
@@ -411,6 +414,16 @@ public:
        return curText.c_str();
    }

    /**
     * Function FromUTF8
     * returns the current token text as a wxString, assuming that the input
     * byte stream is UTF8 encoded.
     */
    wxString FromUTF8()
    {
        return wxString::FromUTF8( curText.c_str() );
    }

    /**
     * Function CurLineNumber
     * returns the current line number within my LINE_READER
@@ -420,6 +433,16 @@ public:
        return reader->LineNumber();
    }

    /**
     * Function CurLine
     * returns the current line of text, from which the CurText() would return
     * its token.
     */
    const char* CurLine()
    {
        return (const char*)(*reader);
    }

    /**
     * Function CurFilename
     * returns the current LINE_READER source.
@@ -433,7 +456,7 @@ public:

    /**
     * Function CurOffset
     * returns the char offset within the current line, using a 1 based index.
     * returns the byte offset within the current line, using a 1 based index.
     * @return int - a one based index into the current line.
     */
    int CurOffset()
+28 −12
Original line number Diff line number Diff line
@@ -46,8 +46,8 @@
 */


#define IO_FORMAT       _( "IO_ERROR: '%s'\n from %s : %s" )
#define PARSE_FORMAT    _( "PARSE_ERROR: '%s' in input/source '%s', line %d, offset %d\n from %s : %s" )
#define IO_FORMAT       _( "IO_ERROR: %s\n from %s : %s" )
#define PARSE_FORMAT    _( "PARSE_ERROR: %s in input/source \"%s\", line %d, offset %d\n from %s : %s" )

// references:
// http://stackoverflow.com/questions/2670816/how-can-i-use-the-compile-time-constant-line-in-a-string
@@ -123,12 +123,11 @@ struct IO_ERROR // : std::exception
};


#define THROW_PARSE_ERROR( msg, input, line, offset )   throw PARSE_ERROR( __FILE__, __LOC__, msg, input, line, offset )

/**
 * Class PARSE_ERROR
 * contains a filename or source description, a line number, a character offset,
 * and an error message.
 * contains a filename or source description, a problem input line, a line number,
 * a byte offset, and an error message which contains the the caller's report and his
 * call site information: CPP source file, function, and line number.
 * @author Dick Hollenbeck
 */
struct PARSE_ERROR : public IO_ERROR
@@ -138,24 +137,36 @@ struct PARSE_ERROR : public IO_ERROR
    int         lineNumber;     ///< at which line number, 1 based index.
    int         byteIndex;      ///< at which character position within the line, 1 based index

    /// problem line of input [say, from a LINE_READER].
    /// this is brought up in original byte format rather than wxString form, incase
    /// there was a problem with the encoding, in which case converting to wxString is
    /// not reliable in this context.
    std::string inputLine;

    /**
     * Constructor
     * which is normally called via the macro THROW_PARSE_ERROR so that
     * __FILE__ and __LOC__ can be captured from the call site.
     */
    PARSE_ERROR( const char* aThrowersFile, const char* aThrowersLoc,
                 const wxString& aMsg, const wxString& aSource,
                 const char* aInputLine,
                 int aLineNumber, int aByteIndex ) :
        IO_ERROR()
    {
        init( aThrowersFile, aThrowersLoc, aMsg, aSource, aLineNumber, aByteIndex );
        init( aThrowersFile, aThrowersLoc, aMsg, aSource, aInputLine, aLineNumber, aByteIndex );
    }

    void init( const char* aThrowersFile, const char* aThrowersLoc,
               const wxString& aMsg, const wxString& aSource,
               const char* aInputLine,
               int aLineNumber, int aByteIndex )
    {
        // save line and offset in binary for Sweet text editor, which will catch exceptions
        // save inpuLine, lineNumber, and offset for UI (.e.g. Sweet text editor)
        inputLine  = aInputLine;
        lineNumber = aLineNumber;
        byteIndex  = aByteIndex;

        // #define PARSE_FORMAT    _( "PARSE_ERROR: %s in source %s, line %d, offset %d\nfrom cpp:%s func:%s" )

        errorText.Printf( PARSE_FORMAT, aMsg.GetData(), aSource.GetData(),
            aLineNumber, aByteIndex,
            wxString::FromUTF8( aThrowersFile ).GetData(),
@@ -165,6 +176,11 @@ struct PARSE_ERROR : public IO_ERROR
    ~PARSE_ERROR() throw ( /*none*/ ){}
};


#define THROW_PARSE_ERROR( aMsg, aSource, aInputLine, aLineNumber, aByteIndex )  \
        throw PARSE_ERROR( __FILE__, __LOC__, aMsg, aSource, aInputLine, aLineNumber, aByteIndex )


/** @} exception_types */


+1 −2
Original line number Diff line number Diff line
@@ -16,8 +16,7 @@ for C in ${CATEGORIES}; do

    for P in ${PARTS};  do
        for R in ${REVS}; do
            echo "#$R: (part $C/$P)" > $BASEDIR/$C/$P.part.$R
            (part $C/$P/$R extends $P/$R (value 22)(footprint SM0805)) > $BASEDIR/$C/$P.part.$R
        done
    done
done
Loading