Switch the LINE_READER being used by DSN_LEXER as owned, and accessible via pointer.

This paves the way for other kinds of LINE_READERs, such as one which reads from a
multiline string which comes from the clipboard. 

Will still need to:
1) add new additional DSN_LEXER constructor,
2) virtualize the LINE_READER's ReadLine() function
3) create derived class from LINE_READER.
This commit is contained in:
dickelbeck 2010-03-02 19:15:30 +00:00
parent a9ad1f4c05
commit a800351eab
2 changed files with 19 additions and 9 deletions

View File

@ -49,9 +49,10 @@ static int compare( const void* a1, const void* a2 )
//-----<DSNLEXER>------------------------------------------------------------- //-----<DSNLEXER>-------------------------------------------------------------
DSNLEXER::DSNLEXER( FILE* aFile, const wxString& aFilename, DSNLEXER::DSNLEXER( FILE* aFile, const wxString& aFilename,
const KEYWORD* aKeywordTable, unsigned aKeywordCount ) : const KEYWORD* aKeywordTable, unsigned aKeywordCount )
reader( aFile, 4096 )
{ {
reader = new LINE_READER( aFile, 4096 );
keywords = aKeywordTable; keywords = aKeywordTable;
keywordCount = aKeywordCount; keywordCount = aKeywordCount;
@ -66,7 +67,7 @@ DSNLEXER::DSNLEXER( FILE* aFile, const wxString& aFilename,
// "start" should never change until we change the reader. The DSN // "start" should never change until we change the reader. The DSN
// format spec supports an include file mechanism but we can add that later // format spec supports an include file mechanism but we can add that later
// using a std::stack to hold a stack of LINE_READERs to track nesting. // using a std::stack to hold a stack of LINE_READERs to track nesting.
start = (char*) reader; start = (char*) (*reader);
limit = start; limit = start;
next = start; next = start;
@ -166,7 +167,7 @@ void DSNLEXER::ThrowIOError( wxString aText, int charOffset ) throw (IOError)
{ {
// append to aText, do not overwrite // append to aText, do not overwrite
aText << wxT(" ") << _("in file") << wxT(" \"") << filename aText << wxT(" ") << _("in file") << wxT(" \"") << filename
<< wxT("\" ") << _("on line") << wxT(" ") << reader.LineNumber() << wxT("\" ") << _("on line") << wxT(" ") << reader->LineNumber()
<< wxT(" ") << _("at offset") << wxT(" ") << charOffset; << wxT(" ") << _("at offset") << wxT(" ") << charOffset;
throw IOError( aText ); throw IOError( aText );

View File

@ -74,7 +74,7 @@ enum DSN_SYNTAX_T {
* Class DLEXER * Class DLEXER
* implements a lexical analyzer for the SPECCTRA DSN file format. It * implements a lexical analyzer for the SPECCTRA DSN file format. It
* reads lexical tokens from the current LINE_READER through the NextTok() * reads lexical tokens from the current LINE_READER through the NextTok()
* function. The NextTok() function returns one of the DSN_T values. * function.
*/ */
class DSNLEXER class DSNLEXER
{ {
@ -82,7 +82,7 @@ class DSNLEXER
char* start; char* start;
char* limit; char* limit;
LINE_READER reader; LINE_READER* reader;
int stringDelimiter; int stringDelimiter;
bool space_in_quoted_tokens; ///< blank spaces within quoted strings bool space_in_quoted_tokens; ///< blank spaces within quoted strings
bool commentsAreTokens; ///< true if should return comments as tokens bool commentsAreTokens; ///< true if should return comments as tokens
@ -101,7 +101,7 @@ class DSNLEXER
int readLine() throw (IOError) int readLine() throw (IOError)
{ {
int len = reader.ReadLine(); int len = reader->ReadLine();
next = start; next = start;
limit = start + len; limit = start + len;
@ -159,6 +159,12 @@ public:
DSNLEXER( FILE* aFile, const wxString& aFilename, DSNLEXER( FILE* aFile, const wxString& aFilename,
const KEYWORD* aKeywordTable, unsigned aKeywordCount ); const KEYWORD* aKeywordTable, unsigned aKeywordCount );
~DSNLEXER()
{
delete reader;
}
/** /**
* Function SetStringDelimiter * Function SetStringDelimiter
* changes the string delimiter from the default " to some other character * changes the string delimiter from the default " to some other character
@ -203,7 +209,10 @@ public:
/** /**
* 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
* the end of file. * 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
* with another usage).
* @return int - the type of token found next. * @return int - the type of token found next.
* @throw IOError - only if the LINE_READER throws it. * @throw IOError - only if the LINE_READER throws it.
*/ */
@ -250,7 +259,7 @@ public:
*/ */
int CurLineNumber() int CurLineNumber()
{ {
return reader.LineNumber(); return reader->LineNumber();
} }
/** /**