34 #define FMT_CLIPBOARD _( "clipboard" ) 63 for( ; it < end; ++it )
72 FILE* aFile,
const wxString& aFilename ) :
78 keywords( aKeywordTable ),
79 keywordCount( aKeywordCount )
88 const std::string& aClipboardTxt,
const wxString& aSource ) :
94 keywords( aKeywordTable ),
95 keywordCount( aKeywordCount )
106 iOwnReaders( false ),
111 keywords( aKeywordTable ),
112 keywordCount( aKeywordCount )
230 KEYWORD_MAP::const_iterator it =
keyword_hash.find( tok.c_str() );
249 ret =
"string_quote";
252 ret =
"quoted text delimiter";
270 ret =
"quoted string";
273 ret =
"end of input";
296 ret =
"token too big";
306 ret << wxT(
"'") << wxString::FromUTF8(
GetTokenText(aTok) ) << wxT(
"'");
332 _(
"Expecting '%s'" ), wxString::FromUTF8( text ) );
356 _(
"Unexpected '%s'" ), wxString::FromUTF8( text ) );
401 _(
"need a number for '%s'" ), wxString::FromUTF8( aExpectation ).GetData() );
418 if( (
unsigned char) cc <=
' ' )
420 switch( (
unsigned char) cc )
436 return '0' <= cc && cc <=
'9';
443 return isSpace( cc ) || cc==
'(' || cc==
')';
458 static bool isNumber(
const char* cp,
const char* limit )
463 bool sawNumber =
false;
465 if( cp < limit && ( *cp==
'-' || *cp==
'+' ) )
468 while( cp < limit &&
isDigit( *cp ) )
474 if( cp < limit && *cp ==
'.' )
478 while( cp < limit &&
isDigit( *cp ) )
487 if( cp < limit && ( *cp==
'E' || *cp==
'e' ) )
493 if( cp < limit && ( *cp==
'-' || *cp==
'+' ) )
496 while( cp < limit &&
isDigit( *cp ) )
504 return sawNumber && cp==limit;
510 const char* cur =
next;
511 const char* head = cur;
539 if( cur<
limit && *cur==
'#' )
546 while(
limit[-1] ==
'\n' ||
limit[-1] ==
'\r' )
610 if( ++head >=
limit )
616 case '\\': c = head[-1];
break;
617 case 'a': c =
'\x07';
break;
618 case 'b': c =
'\x08';
break;
619 case 'f': c =
'\x0c';
break;
620 case 'n': c =
'\n';
break;
621 case 'r': c =
'\r';
break;
622 case 't': c =
'\x09';
break;
623 case 'v': c =
'\x0b';
break;
628 if( !isxdigit( head[i] ) )
634 c = (char) strtoul( tbuf,
NULL, 16 );
644 if( head[i] <
'0' || head[i] >
'7' )
650 c = (char) strtoul( tbuf,
NULL, 8 );
660 else if( *head ==
'"' )
673 wxString errtxt(
_(
"Un-terminated delimited string" ) );
696 static const wxString errtxt(
_(
"String delimiter must be a single character of ', \", or $"));
734 wxString errtxt(
_(
"Un-terminated delimited string" ) );
781 wxArrayString* ret = 0;
787 ret =
new wxArrayString();
int curOffset
offset within current line of the current token
int CurLineNumber() const
Return the current line number within my LINE_READER.
int NeedNUMBER(const char *aExpectation)
Call NextTok() and then verifies that the token read is type DSN_NUMBER.
bool commentsAreTokens
true if should return comments as tokens
bool SetCommentsAreTokens(bool val)
Change the handling of comments.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
void PushReader(LINE_READER *aLineReader)
Manage a stack of LINE_READERs in order to handle nested file inclusion.
bool isSep(char cc)
return true if cc is an s-expression separator character
bool isStringTerminator(char cc) const
char * Line() const
Return a pointer to the last line that was read in.
int NeedSYMBOLorNUMBER()
Call NextTok() and then verifies that the token read in satisfies bool IsSymbol() or the next token i...
const KEYWORD * keywords
table sorted by CMake for bsearch()
const char * name
unique keyword.
wxArrayString * ReadCommentLines()
Check the next sequence of tokens and reads them into a wxArrayString if they are comments.
KEYWORD_MAP keyword_hash
fast, specialized "C string" hashtable
static bool isNumber(const char *cp, const char *limit)
Function isNumber returns true if the next sequence of text is a number: either an integer,...
void SetSpecctraMode(bool aMode)
Change the behavior of this lexer into or out of "specctra mode".
bool space_in_quoted_tokens
blank spaces within quoted strings
int findToken(const std::string &aToken) const
Take aToken string and looks up the string in the keywords table.
wxString GetTokenString(int aTok) const
Return a quote wrapped wxString representation of a token value.
int NeedSYMBOL()
Call NextTok() and then verifies that the token read in satisfies IsSymbol().
LINE_READER * PopReader()
Delete the top most LINE_READER from an internal stack of LINE_READERs and in the case of FILE_LINE_R...
void NeedLEFT()
Call NextTok() and then verifies that the token read in is a DSN_LEFT.
A LINE_READER that reads from an open file.
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
static bool IsSymbol(int aTok)
Test a token to see if it is a symbol.
static bool isSpace(char cc)
Function isSpace tests for whitespace.
const char * GetTokenText(int aTok) const
Return the C string representation of a DSN_T value.
bool iOwnReaders
on readerStack, should I delete them?
READER_STACK readerStack
all the LINE_READERs by pointer.
static const KEYWORD empty_keywords[1]
bool specctraMode
if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_...
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
int prevTok
curTok from previous NextTok() call.
int CurOffset() const
Return the byte offset within the current line, using a 1 based index.
bool SyncLineReaderWith(DSNLEXER &aLexer)
Usable only for DSN lexers which share the same LINE_READER.
void Duplicate(int aTok)
Throw an IO_ERROR exception with a message saying specifically that aTok is a duplicate of one alread...
std::string curText
the text of the current token
int NextTok()
Return the next token found in the input file or DSN_EOF when reaching the end of file.
void Expecting(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
const char * CurLine() const
Return the current line of text from which the CurText() would return its token.
void NeedRIGHT()
Call NextTok() and then verifies that the token read in is a DSN_RIGHT.
unsigned keywordCount
count of keywords table
const wxString & CurSource() const
Return the current LINE_READER source.
char dummy[1]
when there is no reader.
int curTok
the current token obtained on last NextTok()
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
void Unexpected(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
Hold a keyword string and its unique integer token.
Implement a lexical analyzer for the SPECCTRA DSN file format.
DSNLEXER(const KEYWORD *aKeywordTable, unsigned aKeywordCount, FILE *aFile, const wxString &aFileName)
Initialize a DSN lexer and prepares to read from aFile which is already open and has aFilename.
wxString FromUTF8() const
Return the current token text as a wxString, assuming that the input byte stream is UTF8 encoded.
int token
a zero based index into an array of KEYWORDs
static const char * Syntax(int aTok)