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

++all:

  * TokenList2DsnLexer.cmake now supports comments, which start with a leading
    # character, and may be either on their own line or on a line after a token.
  * DSNLEXER::PopReader() now pops even the last LINE_READER* and returns it.
++pcbnew:
  * SPECCTRA_DB now inherits from new class SPECCTRA_LEXER, which led to a great
    deal of simplification and code factoring.
  * Moved specctra keywords into specctra.keywords.
parent 42b9e0e6
Loading
Loading
Loading
Loading
+2 −0
Original line number Original line Diff line number Diff line
@@ -17,6 +17,8 @@ install_manifest.txt
Documentation/doxygen
Documentation/doxygen
*.cmake
*.cmake
*.bak
*.bak
pcbnew/specctra_keywords.cpp
pcbnew/specctra_lexer.h
new/html
new/html
new/sch_lib_table_keywords.cpp
new/sch_lib_table_keywords.cpp
new/sch_lib_table_lexer.h
new/sch_lib_table_lexer.h
+11 −0
Original line number Original line 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
Please add newer entries at the top, list the date and your name with
email address.
email address.


2011-Jan-19 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
++all:
  * TokenList2DsnLexer.cmake now supports comments, which start with a leading
    # character, and may be either on their own line or on a line after a token.
  * DSNLEXER::PopReader() now pops even the last LINE_READER* and returns it.
++pcbnew:
  * SPECCTRA_DB now inherits from new class SPECCTRA_LEXER, which led to a great
    deal of simplification and code factoring.
  * Moved specctra keywords into specctra.keywords.

2011-Jan-17 UPDATE Dick Hollenbeck <dick@softplc.com>
2011-Jan-17 UPDATE Dick Hollenbeck <dick@softplc.com>
================================================================================
================================================================================
++all:
++all:
+44 −13
Original line number Original line Diff line number Diff line
#

#  This program source code file is part of KICAD, a free EDA CAD application.
#  This program source code file is part of KICAD, a free EDA CAD application.
#
#
#  Copyright (C) 2010 Wayne Stambaugh <stambaughw@verizon.net>
#  Copyright (C) 2010 Wayne Stambaugh <stambaughw@verizon.net>
@@ -160,26 +160,33 @@ const KEYWORD ${LEXERCLASS}::keywords[] = {
"
"
)
)


file( STRINGS ${inputFile} tmpTokens NO_HEX_CONVERSION )
file( STRINGS ${inputFile} lines NO_HEX_CONVERSION )


foreach( tmpToken ${tmpTokens} )
foreach( line ${lines} )
    math( EXPR lineCount "${lineCount} + 1" )
    math( EXPR lineCount "${lineCount} + 1" )


    string( STRIP tmpToken "${tmpToken}" )
    # strip any comment from # to end of line
    string( REGEX REPLACE "#.*$" "" tmpToken "${line}" )
    string( STRIP "${tmpToken}" token )


    # Ignore empty lines.
    # Ignore empty lines.
    if( tmpToken )
    if( NOT token STREQUAL "" )           # if token is "off" simple if( token) does not work
        # Make sure token is valid.
        # Make sure token is valid.
        string( REGEX MATCH "[a-z][_0-9a-z]*[0-9a-z]$" validToken "${tmpToken}" )

        if( validToken STREQUAL tmpToken )
        #message( "token=${token}" )

        string( REGEX MATCH "[a-z][_0-9a-z]*" validToken "${token}" )
        #message( "validToken=${validToken}" )

        if( validToken STREQUAL token )
            list( APPEND tokens "${validToken}" )
            list( APPEND tokens "${validToken}" )
        else( validToken STREQUAL tmpToken )
        else()
            message( FATAL_ERROR
            message( FATAL_ERROR
                     "Invalid token string \"${tmpToken}\" at line ${lineCount} in file "
                     "Invalid token string \"${tmpToken}\" at line ${lineCount} in file "
                     "<${inputFile}>." )
                     "<${inputFile}>." )
        endif( validToken STREQUAL tmpToken )
        endif()
    endif( tmpToken )
    endif()
endforeach( tmpToken ${tmpTokens} )
endforeach()


list( SORT tokens )
list( SORT tokens )


@@ -190,7 +197,7 @@ list( LENGTH tokens tokensAfter )


if( NOT ( tokensBefore EQUAL tokensAfter ) )
if( NOT ( tokensBefore EQUAL tokensAfter ) )
    message( FATAL_ERROR "Duplicate tokens found in file <${inputFile}>." )
    message( FATAL_ERROR "Duplicate tokens found in file <${inputFile}>." )
endif( NOT ( tokensBefore EQUAL tokensAfter ) )
endif()


file( WRITE "${outHeaderFile}" "${includeFileHeader}" )
file( WRITE "${outHeaderFile}" "${includeFileHeader}" )
file( WRITE "${outCppFile}" "${sourceFileHeader}" )
file( WRITE "${outCppFile}" "${sourceFileHeader}" )
@@ -214,7 +221,7 @@ foreach( token ${tokens} )
        file( APPEND "${outCppFile}" ",\n" )
        file( APPEND "${outCppFile}" ",\n" )
    endif( lineCount EQUAL tokensAfter )
    endif( lineCount EQUAL tokensAfter )
    math( EXPR lineCount "${lineCount} + 1" )
    math( EXPR lineCount "${lineCount} + 1" )
endforeach( token ${tokens} )
endforeach()


file( APPEND "${outHeaderFile}"
file( APPEND "${outHeaderFile}"
"    };
"    };
@@ -275,6 +282,12 @@ public:
    {
    {
    }
    }


    /**
     * Function TokenName
     * returns the name of the token in ASCII form.
     */
    static const char* TokenName( ${enum}::T aTok );

    /**
    /**
     * Function NextTok
     * 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 T_EOF when reaching
@@ -356,5 +369,23 @@ file( APPEND "${outCppFile}"


const unsigned ${LEXERCLASS}::keyword_count = unsigned( sizeof( ${LEXERCLASS}::keywords )/sizeof( ${LEXERCLASS}::keywords[0] ) );
const unsigned ${LEXERCLASS}::keyword_count = unsigned( sizeof( ${LEXERCLASS}::keywords )/sizeof( ${LEXERCLASS}::keywords[0] ) );



const char* ${LEXERCLASS}::TokenName( T aTok )
{
    const char* ret;

    if( (unsigned) aTok < keyword_count )
    {
        ret = keywords[aTok].name;
    }
    else if( aTok < 0 )
    {
        return DSNLEXER::Syntax( aTok );
    }
    else
        ret = \"token too big\";

    return ret;
}
"
"
)
)
+31 −17
Original line number Original line Diff line number Diff line
@@ -91,6 +91,7 @@ DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
    keywords( aKeywordTable ),
    keywords( aKeywordTable ),
    keywordCount( aKeywordCount )
    keywordCount( aKeywordCount )
{
{
    if( aLineReader )
        PushReader( aLineReader );
        PushReader( aLineReader );
    init();
    init();
}
}
@@ -119,22 +120,33 @@ void DSNLEXER::PushReader( LINE_READER* aLineReader )
}
}




bool DSNLEXER::PopReader()
LINE_READER* DSNLEXER::PopReader()
{
{
    // the very last reader cannot be popped, for that would screw up limit and next.
    LINE_READER*    ret = 0;
    if( readerStack.size() >= 2 )

    if( readerStack.size() )
    {
    {
        ret = reader;
        readerStack.pop_back();
        readerStack.pop_back();


        if( readerStack.size() )
        {
            reader = readerStack.back();
            reader = readerStack.back();
        start  = (const char*) (*reader);
            start  = reader->Line();


            // force a new readLine() as first thing.
            // force a new readLine() as first thing.
            limit = start;
            limit = start;
            next  = start;
            next  = start;
        return true;
        }
        }
    return false;
        else
        {
            reader = 0;
            start  = dummy;
            limit  = dummy;
            limit  = dummy;
        }
    }
    return ret;
}
}




@@ -198,7 +210,7 @@ const char* DSNLEXER::Syntax( int aTok )
        ret = "quoted string";
        ret = "quoted string";
        break;
        break;
    case DSN_EOF:
    case DSN_EOF:
        ret = "end of file";
        ret = "end of input";
        break;
        break;
    default:
    default:
        ret = "???";
        ret = "???";
@@ -257,10 +269,10 @@ void DSNLEXER::Expecting( int aTok ) throw( IO_ERROR )
}
}




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


@@ -272,6 +284,7 @@ void DSNLEXER::Unexpected( int aTok ) throw( IO_ERROR )
    THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
    THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
}



void DSNLEXER::Duplicate( int aTok ) throw( IO_ERROR )
void DSNLEXER::Duplicate( int aTok ) throw( IO_ERROR )
{
{
    wxString    errText;
    wxString    errText;
@@ -280,10 +293,11 @@ void DSNLEXER::Duplicate( int aTok ) throw( IO_ERROR )
    THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
    THROW_PARSE_ERROR( errText, CurSource(), CurLine(), CurLineNumber(), CurOffset() );
}
}


void DSNLEXER::Unexpected( const wxString& text ) throw( IO_ERROR )

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


@@ -317,7 +331,7 @@ int DSNLEXER::NeedSYMBOLorNUMBER() throw( IO_ERROR )
{
{
    int  tok = NextTok();
    int  tok = NextTok();
    if( !IsSymbol( tok ) && tok!=DSN_NUMBER )
    if( !IsSymbol( tok ) && tok!=DSN_NUMBER )
        Expecting( _("symbol|number") );
        Expecting( "symbol|number" );
    return tok;
    return tok;
}
}


+2 −2
Original line number Original line Diff line number Diff line
@@ -79,7 +79,7 @@ void TEMPLATE_FIELDNAME::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IO_ERROR
            break;
            break;


        default:
        default:
            in->Expecting( wxT( "value|visible" ) );
            in->Expecting( "value|visible" );
            break;
            break;
        }
        }
    }
    }
@@ -129,7 +129,7 @@ void TEMPLATES::Parse( TEMPLATE_FIELDNAMES_LEXER* in ) throw( IO_ERROR )
            break;
            break;


        default:
        default:
            in->Unexpected( CONV_FROM_UTF8( in->CurText() ) );
            in->Unexpected( in->CurText() );
            break;
            break;
        }
        }
    }
    }
Loading