KiCad PCB EDA Suite
DSNLEXER Class Reference

Implement a lexical analyzer for the SPECCTRA DSN file format. More...

#include <dsnlexer.h>

Public Member Functions

 DSNLEXER (const KEYWORD *aKeywordTable, unsigned aKeywordCount, const KEYWORD_MAP *aKeywordMap, FILE *aFile, const wxString &aFileName)
 Initialize a DSN lexer and prepares to read from aFile which is already open and has aFilename. More...
 
 DSNLEXER (const KEYWORD *aKeywordTable, unsigned aKeywordCount, const KEYWORD_MAP *aKeywordMap, const std::string &aSExpression, const wxString &aSource=wxEmptyString)
 Initialize a DSN lexer and prepares to read from aSExpression. More...
 
 DSNLEXER (const std::string &aSExpression, const wxString &aSource=wxEmptyString)
 Initialize a DSN lexer and prepares to read from aSExpression. More...
 
 DSNLEXER (const KEYWORD *aKeywordTable, unsigned aKeywordCount, const KEYWORD_MAP *aKeywordMap, LINE_READER *aLineReader=nullptr)
 Initialize a DSN lexer and prepares to read from aLineReader which is already open, and may be in use by other DSNLEXERs also. More...
 
virtual ~DSNLEXER ()
 
void InitParserState ()
 Reinit variables used during parsing, to ensure od states are not used in a new parsing must be called before parsing a new file after parsing an old file to avoid starting with some variables in a non initial state. More...
 
bool SyncLineReaderWith (DSNLEXER &aLexer)
 Usable only for DSN lexers which share the same LINE_READER. More...
 
void SetSpecctraMode (bool aMode)
 Change the behavior of this lexer into or out of "specctra mode". More...
 
void PushReader (LINE_READER *aLineReader)
 Manage a stack of LINE_READERs in order to handle nested file inclusion. More...
 
LINE_READERPopReader ()
 Delete the top most LINE_READER from an internal stack of LINE_READERs and in the case of FILE_LINE_READER this means the associated FILE is closed. More...
 
int NextTok ()
 Return the next token found in the input file or DSN_EOF when reaching the end of file. More...
 
int NeedSYMBOL ()
 Call NextTok() and then verifies that the token read in satisfies IsSymbol(). More...
 
int NeedSYMBOLorNUMBER ()
 Call NextTok() and then verifies that the token read in satisfies bool IsSymbol() or the next token is DSN_NUMBER. More...
 
int NeedNUMBER (const char *aExpectation)
 Call NextTok() and then verifies that the token read is type DSN_NUMBER. More...
 
int CurTok () const
 Return whatever NextTok() returned the last time it was called. More...
 
int PrevTok () const
 Return whatever NextTok() returned the 2nd to last time it was called. More...
 
int GetCurStrAsToken () const
 Used to support "loose" matches (quoted tokens). More...
 
char SetStringDelimiter (char aStringDelimiter)
 Change the string delimiter from the default " to some other character and return the old value. More...
 
bool SetSpaceInQuotedTokens (bool val)
 Change the setting controlling whether a space in a quoted string isa terminator. More...
 
bool SetCommentsAreTokens (bool val)
 Change the handling of comments. More...
 
wxArrayString * ReadCommentLines ()
 Check the next sequence of tokens and reads them into a wxArrayString if they are comments. More...
 
void Expecting (int aTok) const
 Throw an IO_ERROR exception with an input file specific error message. More...
 
void Expecting (const char *aTokenList) const
 Throw an IO_ERROR exception with an input file specific error message. More...
 
void Unexpected (int aTok) const
 Throw an IO_ERROR exception with an input file specific error message. More...
 
void Unexpected (const char *aToken) const
 Throw an IO_ERROR exception with an input file specific error message. More...
 
void Duplicate (int aTok)
 Throw an IO_ERROR exception with a message saying specifically that aTok is a duplicate of one already seen in current context. More...
 
void NeedLEFT ()
 Call NextTok() and then verifies that the token read in is a DSN_LEFT. More...
 
void NeedRIGHT ()
 Call NextTok() and then verifies that the token read in is a DSN_RIGHT. More...
 
const char * GetTokenText (int aTok) const
 Return the C string representation of a DSN_T value. More...
 
wxString GetTokenString (int aTok) const
 Return a quote wrapped wxString representation of a token value. More...
 
const char * CurText () const
 Return a pointer to the current token's text. More...
 
const std::string & CurStr () const
 Return a reference to current token in std::string form. More...
 
wxString FromUTF8 () const
 Return the current token text as a wxString, assuming that the input byte stream is UTF8 encoded. More...
 
int CurLineNumber () const
 Return the current line number within my LINE_READER. More...
 
const char * CurLine () const
 Return the current line of text from which the CurText() would return its token. More...
 
const wxString & CurSource () const
 Return the current LINE_READER source. More...
 
int CurOffset () const
 Return the byte offset within the current line, using a 1 based index. More...
 

Static Public Member Functions

static bool IsSymbol (int aTok)
 Test a token to see if it is a symbol. More...
 
static const char * Syntax (int aTok)
 

Protected Types

typedef std::vector< LINE_READER * > READER_STACK
 

Protected Member Functions

void init ()
 
int readLine ()
 
int findToken (const std::string &aToken) const
 Take aToken string and looks up the string in the keywords table. More...
 
bool isStringTerminator (char cc) const
 
double parseDouble ()
 Parse the current token as an ASCII numeric string with possible leading whitespace into a double precision floating point number. More...
 
double parseDouble (const char *aExpected)
 
template<typename T >
double parseDouble (T aToken)
 

Protected Attributes

bool iOwnReaders
 on readerStack, should I delete them? More...
 
const char * start
 
const char * next
 
const char * limit
 
char dummy [1]
 when there is no reader. More...
 
READER_STACK readerStack
 all the LINE_READERs by pointer. More...
 
LINE_READERreader
 
bool specctraMode
 if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_in_quoted_tokens is functional else not. More...
 
char stringDelimiter
 
bool space_in_quoted_tokens
 blank spaces within quoted strings More...
 
bool commentsAreTokens
 true if should return comments as tokens More...
 
int prevTok
 curTok from previous NextTok() call. More...
 
int curOffset
 offset within current line of the current token More...
 
int curTok
 the current token obtained on last NextTok() More...
 
std::string curText
 the text of the current token More...
 
const KEYWORDkeywords
 table sorted by CMake for bsearch() More...
 
unsigned keywordCount
 count of keywords table More...
 
const KEYWORD_MAPkeywordsLookup
 fast, specialized "C string" hashtable More...
 

Detailed Description

Implement a lexical analyzer for the SPECCTRA DSN file format.

It reads lexical tokens from the current LINE_READER through the NextTok() function.

Definition at line 78 of file dsnlexer.h.

Member Typedef Documentation

◆ READER_STACK

typedef std::vector<LINE_READER*> DSNLEXER::READER_STACK
protected

Definition at line 528 of file dsnlexer.h.

Constructor & Destructor Documentation

◆ DSNLEXER() [1/4]

DSNLEXER::DSNLEXER ( const KEYWORD aKeywordTable,
unsigned  aKeywordCount,
const KEYWORD_MAP aKeywordMap,
FILE *  aFile,
const wxString &  aFileName 
)

Initialize a DSN lexer and prepares to read from aFile which is already open and has aFilename.

Parameters
aKeywordTableis an array of KEYWORDS holding aKeywordCount. This token table need not contain the lexer separators such as '(' ')', etc.
aKeywordCountis the count of tokens in aKeywordTable.
aFileis an open file, which will be closed when this is destructed.
aFileNameis the name of the file

Definition at line 55 of file dsnlexer.cpp.

57 :
58 iOwnReaders( true ),
59 start( nullptr ),
60 next( nullptr ),
61 limit( nullptr ),
62 reader( nullptr ),
63 keywords( aKeywordTable ),
64 keywordCount( aKeywordCount ),
65 keywordsLookup( aKeywordMap )
66{
67 FILE_LINE_READER* fileReader = new FILE_LINE_READER( aFile, aFilename );
68 PushReader( fileReader );
69 init();
70}
const char * next
Definition: dsnlexer.h:524
unsigned keywordCount
count of keywords table
Definition: dsnlexer.h:553
void init()
Definition: dsnlexer.cpp:40
const char * start
Definition: dsnlexer.h:523
LINE_READER * reader
Definition: dsnlexer.h:533
const char * limit
Definition: dsnlexer.h:525
const KEYWORD * keywords
table sorted by CMake for bsearch()
Definition: dsnlexer.h:552
const KEYWORD_MAP * keywordsLookup
fast, specialized "C string" hashtable
Definition: dsnlexer.h:554
bool iOwnReaders
on readerStack, should I delete them?
Definition: dsnlexer.h:522
void PushReader(LINE_READER *aLineReader)
Manage a stack of LINE_READERs in order to handle nested file inclusion.
Definition: dsnlexer.cpp:189
A LINE_READER that reads from an open file.
Definition: richio.h:173

References init(), and PushReader().

◆ DSNLEXER() [2/4]

DSNLEXER::DSNLEXER ( const KEYWORD aKeywordTable,
unsigned  aKeywordCount,
const KEYWORD_MAP aKeywordMap,
const std::string &  aSExpression,
const wxString &  aSource = wxEmptyString 
)

Initialize a DSN lexer and prepares to read from aSExpression.

Parameters
aKeywordTableis an array of KEYWORDS holding aKeywordCount. This token table need not contain the lexer separators such as '(' ')', etc.
aKeywordCountis the count of tokens in aKeywordTable.
aSExpressionis text to feed through a STRING_LINE_READER
aSourceis a description of aSExpression, used for error reporting.

Definition at line 73 of file dsnlexer.cpp.

75 :
76 iOwnReaders( true ),
77 start( nullptr ),
78 next( nullptr ),
79 limit( nullptr ),
80 reader( nullptr ),
81 keywords( aKeywordTable ),
82 keywordCount( aKeywordCount ),
83 keywordsLookup( aKeywordMap )
84{
85 STRING_LINE_READER* stringReader = new STRING_LINE_READER( aClipboardTxt, aSource.IsEmpty() ?
86 wxString( FMT_CLIPBOARD ) : aSource );
87 PushReader( stringReader );
88 init();
89}
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:241
#define FMT_CLIPBOARD
Definition: dsnlexer.cpp:35

References FMT_CLIPBOARD, init(), and PushReader().

◆ DSNLEXER() [3/4]

DSNLEXER::DSNLEXER ( const std::string &  aSExpression,
const wxString &  aSource = wxEmptyString 
)

Initialize a DSN lexer and prepares to read from aSExpression.

Use this one without a keyword table with the DOM parser in ptree.h.

Parameters
aSExpressionis text to feed through a STRING_LINE_READER
aSourceis a description of aSExpression, used for error reporting.

Definition at line 112 of file dsnlexer.cpp.

112 :
113 iOwnReaders( true ),
114 start( nullptr ),
115 next( nullptr ),
116 limit( nullptr ),
117 reader( nullptr ),
119 keywordCount( 0 ),
120 keywordsLookup( nullptr )
121{
122 STRING_LINE_READER* stringReader = new STRING_LINE_READER( aSExpression, aSource.IsEmpty() ?
123 wxString( FMT_CLIPBOARD ) : aSource );
124 PushReader( stringReader );
125 init();
126}
static const KEYWORD empty_keywords[1]
Definition: dsnlexer.cpp:110

References FMT_CLIPBOARD, init(), and PushReader().

◆ DSNLEXER() [4/4]

DSNLEXER::DSNLEXER ( const KEYWORD aKeywordTable,
unsigned  aKeywordCount,
const KEYWORD_MAP aKeywordMap,
LINE_READER aLineReader = nullptr 
)

Initialize a DSN lexer and prepares to read from aLineReader which is already open, and may be in use by other DSNLEXERs also.

No ownership is taken of aLineReader. This enables it to be used by other DSNLEXERs.

Parameters
aKeywordTableis an array of #KEYWORDS holding aKeywordCount. This token table need not contain the lexer separators such as '(' ')', etc.
aKeywordCountis the count of tokens in aKeywordTable.
aLineReaderis any subclassed instance of LINE_READER, such as STRING_LINE_READER or FILE_LINE_READER. No ownership is taken.

Definition at line 92 of file dsnlexer.cpp.

94 :
95 iOwnReaders( false ),
96 start( nullptr ),
97 next( nullptr ),
98 limit( nullptr ),
99 reader( nullptr ),
100 keywords( aKeywordTable ),
101 keywordCount( aKeywordCount ),
102 keywordsLookup( aKeywordMap )
103{
104 if( aLineReader )
105 PushReader( aLineReader );
106 init();
107}

References init(), and PushReader().

◆ ~DSNLEXER()

DSNLEXER::~DSNLEXER ( )
virtual

Definition at line 129 of file dsnlexer.cpp.

130{
131 if( iOwnReaders )
132 {
133 // delete the LINE_READERs from the stack, since I own them.
134 for( READER_STACK::iterator it = readerStack.begin(); it!=readerStack.end(); ++it )
135 delete *it;
136 }
137}
READER_STACK readerStack
all the LINE_READERs by pointer.
Definition: dsnlexer.h:530

References iOwnReaders, and readerStack.

Member Function Documentation

◆ CurLine()

const char * DSNLEXER::CurLine ( ) const
inline

Return the current line of text from which the CurText() would return its token.

Definition at line 431 of file dsnlexer.h.

432 {
433 return (const char*)(*reader);
434 }

Referenced by Duplicate(), Expecting(), NeedNUMBER(), NextTok(), parseDouble(), and Unexpected().

◆ CurLineNumber()

int DSNLEXER::CurLineNumber ( ) const
inline

Return the current line number within my LINE_READER.

Definition at line 423 of file dsnlexer.h.

424 {
425 return reader->LineNumber();
426 }
virtual unsigned LineNumber() const
Return the line number of the last line read from this LINE_READER.
Definition: richio.h:135

References LINE_READER::LineNumber(), and reader.

Referenced by Duplicate(), Expecting(), NeedNUMBER(), NextTok(), parseDouble(), and Unexpected().

◆ CurOffset()

int DSNLEXER::CurOffset ( ) const
inline

Return the byte offset within the current line, using a 1 based index.

Returns
a one based index into the current line.

Definition at line 451 of file dsnlexer.h.

452 {
453 return curOffset + 1;
454 }
int curOffset
offset within current line of the current token
Definition: dsnlexer.h:547

References curOffset.

Referenced by Duplicate(), Expecting(), NeedNUMBER(), NextTok(), parseDouble(), and Unexpected().

◆ CurSource()

const wxString & DSNLEXER::CurSource ( ) const
inline

Return the current LINE_READER source.

Returns
source of the lines of text, e.g. a filename or "clipboard".

Definition at line 441 of file dsnlexer.h.

442 {
443 return reader->GetSource();
444 }
virtual const wxString & GetSource() const
Returns the name of the source of the lines in an abstract sense.
Definition: richio.h:109

References LINE_READER::GetSource(), and reader.

Referenced by Duplicate(), Expecting(), NeedNUMBER(), NextTok(), parseDouble(), and Unexpected().

◆ CurStr()

const std::string & DSNLEXER::CurStr ( ) const
inline

Return a reference to current token in std::string form.

Definition at line 406 of file dsnlexer.h.

407 {
408 return curText;
409 }
std::string curText
the text of the current token
Definition: dsnlexer.h:550

References curText.

Referenced by parseDouble().

◆ CurText()

const char * DSNLEXER::CurText ( ) const
inline

Return a pointer to the current token's text.

Definition at line 398 of file dsnlexer.h.

399 {
400 return curText.c_str();
401 }

References curText.

Referenced by CADSTAR_ARCHIVE_PARSER::LoadArchiveFile(), PCAD2KICAD::LoadInputFile(), parseDouble(), scanAtom(), and scanList().

◆ CurTok()

int DSNLEXER::CurTok ( ) const
inline

Return whatever NextTok() returned the last time it was called.

Definition at line 237 of file dsnlexer.h.

238 {
239 return curTok;
240 }
int curTok
the current token obtained on last NextTok()
Definition: dsnlexer.h:549

References curTok.

Referenced by Scan(), and scanList().

◆ Duplicate()

void DSNLEXER::Duplicate ( int  aTok)

Throw an IO_ERROR exception with a message saying specifically that aTok is a duplicate of one already seen in current context.

Parameters
aTokis the token/keyword type which was not expected at the current input location.
Exceptions
IO_ERRORwith the location within the input file of the problem.

Definition at line 350 of file dsnlexer.cpp.

351{
352 wxString errText = wxString::Format(
353 _("%s is a duplicate"), GetTokenString( aTok ).GetData() );
355}
const wxString & CurSource() const
Return the current LINE_READER source.
Definition: dsnlexer.h:441
const char * CurLine() const
Return the current line of text from which the CurText() would return its token.
Definition: dsnlexer.h:431
wxString GetTokenString(int aTok) const
Return a quote wrapped wxString representation of a token value.
Definition: dsnlexer.cpp:307
int CurOffset() const
Return the byte offset within the current line, using a 1 based index.
Definition: dsnlexer.h:451
int CurLineNumber() const
Return the current line number within my LINE_READER.
Definition: dsnlexer.h:423
#define _(s)
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200

References _, CurLine(), CurLineNumber(), CurOffset(), CurSource(), Format(), GetTokenString(), and THROW_PARSE_ERROR.

◆ Expecting() [1/2]

void DSNLEXER::Expecting ( const char *  aTokenList) const

Throw an IO_ERROR exception with an input file specific error message.

Parameters
aTokenListis the token/keyword type which was expected at the current input location, e.g. "pin|graphic|property".
Exceptions
IO_ERRORwith the location within the input file of the problem.

Definition at line 334 of file dsnlexer.cpp.

335{
336 wxString errText = wxString::Format(
337 _( "Expecting '%s'" ), wxString::FromUTF8( text ) );
339}

References _, CurLine(), CurLineNumber(), CurOffset(), CurSource(), Format(), text, and THROW_PARSE_ERROR.

◆ Expecting() [2/2]

void DSNLEXER::Expecting ( int  aTok) const

Throw an IO_ERROR exception with an input file specific error message.

Parameters
aTokis the token/keyword type which was expected at the current input location.
Exceptions
IO_ERRORwith the location within the input file of the problem.

Definition at line 326 of file dsnlexer.cpp.

327{
328 wxString errText = wxString::Format(
329 _( "Expecting %s" ), GetTokenString( aTok ) );
331}

References _, CurLine(), CurLineNumber(), CurOffset(), CurSource(), Format(), GetTokenString(), and THROW_PARSE_ERROR.

Referenced by NeedLEFT(), NeedRIGHT(), NeedSYMBOL(), and NeedSYMBOLorNUMBER().

◆ findToken()

int DSNLEXER::findToken ( const std::string &  aToken) const
protected

Take aToken string and looks up the string in the keywords table.

Parameters
aTokenis a string to lookup in the keywords table.
Returns
with a value from the enum DSN_T matching the keyword text, or DSN_SYMBOL if aToken is not in the keywords table.

Definition at line 230 of file dsnlexer.cpp.

231{
232 if( keywordsLookup != nullptr )
233 {
234 KEYWORD_MAP::const_iterator it = keywordsLookup->find( tok.c_str() );
235
236 if( it != keywordsLookup->end() )
237 return it->second;
238 }
239
240 return DSN_SYMBOL; // not a keyword, some arbitrary symbol.
241}
@ DSN_SYMBOL
Definition: dsnlexer.h:64

References DSN_SYMBOL, and keywordsLookup.

Referenced by GetCurStrAsToken(), and NextTok().

◆ FromUTF8()

wxString DSNLEXER::FromUTF8 ( ) const
inline

Return the current token text as a wxString, assuming that the input byte stream is UTF8 encoded.

Definition at line 415 of file dsnlexer.h.

416 {
417 return wxString::FromUTF8( curText.c_str() );
418 }

References curText.

Referenced by ReadCommentLines().

◆ GetCurStrAsToken()

int DSNLEXER::GetCurStrAsToken ( ) const
inline

Used to support "loose" matches (quoted tokens).

Definition at line 253 of file dsnlexer.h.

254 {
255 return findToken( curText );
256 }
int findToken(const std::string &aToken) const
Take aToken string and looks up the string in the keywords table.
Definition: dsnlexer.cpp:230

References curText, and findToken().

◆ GetTokenString()

wxString DSNLEXER::GetTokenString ( int  aTok) const

Return a quote wrapped wxString representation of a token value.

Definition at line 307 of file dsnlexer.cpp.

308{
309 wxString ret;
310
311 ret << wxT("'") << wxString::FromUTF8( GetTokenText(aTok) ) << wxT("'");
312
313 return ret;
314}
const char * GetTokenText(int aTok) const
Return the C string representation of a DSN_T value.
Definition: dsnlexer.cpp:288

References GetTokenText().

Referenced by Duplicate(), Expecting(), and Unexpected().

◆ GetTokenText()

const char * DSNLEXER::GetTokenText ( int  aTok) const

Return the C string representation of a DSN_T value.

Definition at line 288 of file dsnlexer.cpp.

289{
290 const char* ret;
291
292 if( aTok < 0 )
293 {
294 return Syntax( aTok );
295 }
296 else if( (unsigned) aTok < keywordCount )
297 {
298 ret = keywords[aTok].name;
299 }
300 else
301 ret = "token too big";
302
303 return ret;
304}
static const char * Syntax(int aTok)
Definition: dsnlexer.cpp:244
const char * name
unique keyword.
Definition: dsnlexer.h:41

References keywordCount, keywords, KEYWORD::name, and Syntax().

Referenced by GetTokenString(), and parseDouble().

◆ init()

void DSNLEXER::init ( )
protected

Definition at line 40 of file dsnlexer.cpp.

41{
44
45 stringDelimiter = '"';
46
47 specctraMode = false;
49 commentsAreTokens = false;
50
51 curOffset = 0;
52}
bool commentsAreTokens
true if should return comments as tokens
Definition: dsnlexer.h:544
bool space_in_quoted_tokens
blank spaces within quoted strings
Definition: dsnlexer.h:542
bool specctraMode
if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_...
Definition: dsnlexer.h:535
char stringDelimiter
Definition: dsnlexer.h:541
int prevTok
curTok from previous NextTok() call.
Definition: dsnlexer.h:546
@ DSN_NONE
Definition: dsnlexer.h:59

References commentsAreTokens, curOffset, curTok, DSN_NONE, prevTok, space_in_quoted_tokens, specctraMode, and stringDelimiter.

Referenced by DSNLEXER().

◆ InitParserState()

void DSNLEXER::InitParserState ( )

Reinit variables used during parsing, to ensure od states are not used in a new parsing must be called before parsing a new file after parsing an old file to avoid starting with some variables in a non initial state.

Definition at line 156 of file dsnlexer.cpp.

157{
160 commentsAreTokens = false;
161
162 curOffset = 0;
163}

References commentsAreTokens, curOffset, curTok, DSN_NONE, and prevTok.

◆ isStringTerminator()

bool DSNLEXER::isStringTerminator ( char  cc) const
inlineprotected

Definition at line 490 of file dsnlexer.h.

491 {
492 if( !space_in_quoted_tokens && cc == ' ' )
493 return true;
494
495 if( cc == stringDelimiter )
496 return true;
497
498 return false;
499 }

References space_in_quoted_tokens, and stringDelimiter.

Referenced by NextTok().

◆ IsSymbol()

bool DSNLEXER::IsSymbol ( int  aTok)
static

Test a token to see if it is a symbol.

This means it cannot be a special delimiter character such as DSN_LEFT, DSN_RIGHT, #DSN_QUOTE, etc. It may however, coincidentally match a keyword and still be a symbol.

Definition at line 317 of file dsnlexer.cpp.

318{
319 // This is static and not inline to reduce code space.
320
321 // if aTok is >= 0, then it is a coincidental match to a keyword.
322 return aTok == DSN_SYMBOL || aTok == DSN_STRING || aTok >= 0;
323}
@ DSN_STRING
Definition: dsnlexer.h:68

References DSN_STRING, and DSN_SYMBOL.

Referenced by NeedSYMBOL(), and NeedSYMBOLorNUMBER().

◆ NeedLEFT()

void DSNLEXER::NeedLEFT ( )

Call NextTok() and then verifies that the token read in is a DSN_LEFT.

Exceptions
IO_ERRORif the next token is not a DSN_LEFT

Definition at line 366 of file dsnlexer.cpp.

367{
368 int tok = NextTok();
369 if( tok != DSN_LEFT )
371}
int NextTok()
Return the next token found in the input file or DSN_EOF when reaching the end of file.
Definition: dsnlexer.cpp:519
void Expecting(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
Definition: dsnlexer.cpp:326
@ DSN_LEFT
Definition: dsnlexer.h:67

References DSN_LEFT, Expecting(), and NextTok().

◆ NeedNUMBER()

int DSNLEXER::NeedNUMBER ( const char *  aExpectation)

Call NextTok() and then verifies that the token read is type DSN_NUMBER.

Returns
the actual token read in.
Exceptions
IO_ERRORif the next token does not satisfy the above test.

Definition at line 405 of file dsnlexer.cpp.

406{
407 int tok = NextTok();
408
409 if( tok != DSN_NUMBER )
410 {
411 wxString errText = wxString::Format( _( "need a number for '%s'" ),
412 wxString::FromUTF8( aExpectation ).GetData() );
414 }
415
416 return tok;
417}
@ DSN_NUMBER
Definition: dsnlexer.h:65

References _, CurLine(), CurLineNumber(), CurOffset(), CurSource(), DSN_NUMBER, Format(), NextTok(), and THROW_PARSE_ERROR.

Referenced by parseDouble().

◆ NeedRIGHT()

void DSNLEXER::NeedRIGHT ( )

Call NextTok() and then verifies that the token read in is a DSN_RIGHT.

Exceptions
IO_ERRORif the next token is not a DSN_RIGHT

Definition at line 374 of file dsnlexer.cpp.

375{
376 int tok = NextTok();
377
378 if( tok != DSN_RIGHT )
380}
@ DSN_RIGHT
Definition: dsnlexer.h:66

References DSN_RIGHT, Expecting(), and NextTok().

◆ NeedSYMBOL()

int DSNLEXER::NeedSYMBOL ( )

Call NextTok() and then verifies that the token read in satisfies IsSymbol().

Returns
the actual token read in.
Exceptions
IO_ERRORif the next token does not satisfy IsSymbol().

Definition at line 383 of file dsnlexer.cpp.

384{
385 int tok = NextTok();
386
387 if( !IsSymbol( tok ) )
389
390 return tok;
391}
static bool IsSymbol(int aTok)
Test a token to see if it is a symbol.
Definition: dsnlexer.cpp:317

References DSN_SYMBOL, Expecting(), IsSymbol(), and NextTok().

◆ NeedSYMBOLorNUMBER()

int DSNLEXER::NeedSYMBOLorNUMBER ( )

Call NextTok() and then verifies that the token read in satisfies bool IsSymbol() or the next token is DSN_NUMBER.

Returns
the actual token read in.
Exceptions
IO_ERRORif the next token does not satisfy the above test.

Definition at line 394 of file dsnlexer.cpp.

395{
396 int tok = NextTok();
397
398 if( !IsSymbol( tok ) && tok!=DSN_NUMBER )
399 Expecting( "a symbol or number" );
400
401 return tok;
402}

References DSN_NUMBER, Expecting(), IsSymbol(), and NextTok().

◆ NextTok()

int DSNLEXER::NextTok ( )

Return the next token found in the input file or DSN_EOF when reaching 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).

Returns
the type of token found next.
Exceptions
IO_ERRORonly if the LINE_READER throws it.

Definition at line 519 of file dsnlexer.cpp.

520{
521 const char* cur = next;
522 const char* head = cur;
523
524 prevTok = curTok;
525
526 if( curTok == DSN_EOF )
527 goto exit;
528
529 if( cur >= limit )
530 {
531L_read:
532 // blank lines are returned as "\n" and will have a len of 1.
533 // EOF will have a len of 0 and so is detectable.
534 int len = readLine();
535
536 if( len == 0 )
537 {
538 cur = start; // after readLine(), since start can change, set cur offset to start
539 curTok = DSN_EOF;
540 goto exit;
541 }
542
543 cur = start; // after readLine() since start can change.
544
545 // skip leading whitespace
546 while( cur < limit && isSpace( *cur ) )
547 ++cur;
548
549 // If the first non-blank character is #, this line is a comment.
550 // Comments cannot follow any other token on the same line.
551 if( cur<limit && *cur=='#' )
552 {
554 {
555 // Grab the entire current line [excluding end of line char(s)] as the
556 // current token. The '#' character may not be at offset zero.
557
558 while( limit[-1] == '\n' || limit[-1] == '\r' )
559 --limit;
560
561 curText.clear();
562 curText.append( start, limit );
563
564 cur = start; // ensure a good curOffset below
566 head = limit; // do a readLine() on next call in here.
567 goto exit;
568 }
569 else
570 {
571 goto L_read;
572 }
573 }
574 }
575 else
576 {
577 // skip leading whitespace
578 while( cur < limit && isSpace( *cur ) )
579 ++cur;
580 }
581
582 if( cur >= limit )
583 goto L_read;
584
585 if( *cur == '(' )
586 {
587 curText = *cur;
589 head = cur+1;
590 goto exit;
591 }
592
593 if( *cur == ')' )
594 {
595 curText = *cur;
597 head = cur+1;
598 goto exit;
599 }
600
601 // Non-specctraMode, understands and deciphers escaped \, \r, \n, and \".
602 // Strips off leading and trailing double quotes
603 if( !specctraMode )
604 {
605 // a quoted string, will return DSN_STRING
606 if( *cur == stringDelimiter )
607 {
608 // copy the token, character by character so we can remove doubled up quotes.
609 curText.clear();
610
611 ++cur; // skip over the leading delimiter, which is always " in non-specctraMode
612
613 head = cur;
614
615 while( head<limit )
616 {
617 // ESCAPE SEQUENCES:
618 if( *head =='\\' )
619 {
620 char tbuf[8];
621 char c;
622 int i;
623
624 if( ++head >= limit )
625 break; // throw exception at L_unterminated
626
627 switch( *head++ )
628 {
629 case '"':
630 case '\\': c = head[-1]; break;
631 case 'a': c = '\x07'; break;
632 case 'b': c = '\x08'; break;
633 case 'f': c = '\x0c'; break;
634 case 'n': c = '\n'; break;
635 case 'r': c = '\r'; break;
636 case 't': c = '\x09'; break;
637 case 'v': c = '\x0b'; break;
638
639 case 'x': // 1 or 2 byte hex escape sequence
640 for( i = 0; i < 2; ++i )
641 {
642 if( !isxdigit( head[i] ) )
643 break;
644
645 tbuf[i] = head[i];
646 }
647
648 tbuf[i] = '\0';
649
650 if( i > 0 )
651 c = (char) strtoul( tbuf, nullptr, 16 );
652 else
653 c = 'x'; // a goofed hex escape sequence, interpret as 'x'
654
655 head += i;
656 break;
657
658 default: // 1-3 byte octal escape sequence
659 --head;
660
661 for( i=0; i<3; ++i )
662 {
663 if( head[i] < '0' || head[i] > '7' )
664 break;
665
666 tbuf[i] = head[i];
667 }
668
669 tbuf[i] = '\0';
670
671 if( i > 0 )
672 c = (char) strtoul( tbuf, nullptr, 8 );
673 else
674 c = '\\'; // a goofed octal escape sequence, interpret as '\'
675
676 head += i;
677 break;
678 }
679
680 curText += c;
681 }
682
683 else if( *head == '"' ) // end of the non-specctraMode DSN_STRING
684 {
686 ++head; // omit this trailing double quote
687 goto exit;
688 }
689
690 else
691 curText += *head++;
692
693 } // while
694
695 // L_unterminated:
696 wxString errtxt( _( "Un-terminated delimited string" ) );
698 cur - start + curText.length() );
699 }
700 }
701 else // is specctraMode, tests in this block should not occur in KiCad mode.
702 {
703 /* get the dash out of a <pin_reference> which is embedded for example
704 like: U2-14 or "U2"-"14"
705 This is detectable by a non-space immediately preceding the dash.
706 */
707 if( *cur == '-' && cur>start && !isSpace( cur[-1] ) )
708 {
709 curText = '-';
711 head = cur+1;
712 goto exit;
713 }
714
715 // switching the string_quote character
717 {
718 static const wxString errtxt( _("String delimiter must be a single character of "
719 "', \", or $") );
720
721 char cc = *cur;
722 switch( cc )
723 {
724 case '\'':
725 case '$':
726 case '"':
727 break;
728 default:
730 }
731
732 curText = cc;
733
734 head = cur+1;
735
736 if( head<limit && !isSep( *head ) )
737 {
739 }
740
742 goto exit;
743 }
744
745 // specctraMode DSN_STRING
746 if( *cur == stringDelimiter )
747 {
748 ++cur; // skip over the leading delimiter: ",', or $
749
750 head = cur;
751
752 while( head<limit && !isStringTerminator( *head ) )
753 ++head;
754
755 if( head >= limit )
756 {
757 wxString errtxt( _( "Un-terminated delimited string" ) );
759 }
760
761 curText.clear();
762 curText.append( cur, head );
763
764 ++head; // skip over the trailing delimiter
765
767 goto exit;
768 }
769 } // specctraMode
770
771 // non-quoted token, read it into curText.
772 curText.clear();
773
774 head = cur;
775 while( head<limit && !isSep( *head ) )
776 curText += *head++;
777
778 if( isNumber( curText.c_str(), curText.c_str() + curText.size() ) )
779 {
781 goto exit;
782 }
783
784 if( specctraMode && curText == "string_quote" )
785 {
787 goto exit;
788 }
789
791
792exit: // single point of exit, no returns elsewhere please.
793
794 curOffset = cur - start;
795
796 next = head;
797
798 return curTok;
799}
bool isStringTerminator(char cc) const
Definition: dsnlexer.h:490
int readLine()
Definition: dsnlexer.h:461
static bool isNumber(const char *cp, const char *limit)
Return true if the next sequence of text is a number: either an integer, fixed point,...
Definition: dsnlexer.cpp:469
static bool isSpace(char cc)
Test for whitespace.
Definition: dsnlexer.cpp:426
bool isSep(char cc)
Definition: dsnlexer.cpp:454
@ DSN_QUOTE_DEF
Definition: dsnlexer.h:62
@ DSN_STRING_QUOTE
Definition: dsnlexer.h:61
@ DSN_DASH
Definition: dsnlexer.h:63
@ DSN_COMMENT
Definition: dsnlexer.h:60
@ DSN_EOF
Definition: dsnlexer.h:69

References _, commentsAreTokens, CurLine(), CurLineNumber(), CurOffset(), curOffset, CurSource(), curText, curTok, DSN_COMMENT, DSN_DASH, DSN_EOF, DSN_LEFT, DSN_NUMBER, DSN_QUOTE_DEF, DSN_RIGHT, DSN_STRING, DSN_STRING_QUOTE, exit, findToken(), isNumber(), isSep(), isSpace(), isStringTerminator(), limit, next, prevTok, readLine(), specctraMode, start, stringDelimiter, and THROW_PARSE_ERROR.

Referenced by CADSTAR_ARCHIVE_PARSER::LoadArchiveFile(), PCAD2KICAD::LoadInputFile(), NeedLEFT(), NeedNUMBER(), NeedRIGHT(), NeedSYMBOL(), NeedSYMBOLorNUMBER(), ReadCommentLines(), Scan(), and scanList().

◆ parseDouble() [1/3]

double DSNLEXER::parseDouble ( )
protected

Parse the current token as an ASCII numeric string with possible leading whitespace into a double precision floating point number.

Exceptions
IO_ERRORif an error occurs attempting to convert the current token.
Returns
The result of the parsed token.

Definition at line 825 of file dsnlexer.cpp.

826{
827#if ( defined( __GNUC__ ) && __GNUC__ < 11 ) || ( defined( __clang__ ) && __clang_major__ < 13 )
828 // GCC older than 11 "supports" C++17 without supporting the C++17 std::from_chars for doubles
829 // clang is similar
830
831 char* tmp;
832
833 errno = 0;
834
835 double fval = strtod( CurText(), &tmp );
836
837 if( errno )
838 {
839 wxString error;
840 error.Printf( _( "Invalid floating point number in\nfile: '%s'\nline: %d\noffset: %d" ),
842
843 THROW_IO_ERROR( error );
844 }
845
846 if( CurText() == tmp )
847 {
848 wxString error;
849 error.Printf( _( "Missing floating point number in\nfile: '%s'\nline: %d\noffset: %d" ),
851
852 THROW_IO_ERROR( error );
853 }
854
855 return fval;
856#else
857 // Use std::from_chars which is designed to be locale independent and performance oriented for data interchange
858
859 const std::string& str = CurStr();
860
861 // Offset any leading whitespace, this is one thing from_chars does not handle
862 size_t woff = 0;
863 while( std::isspace( str[woff] ) && woff < str.length() )
864 {
865 woff++;
866 }
867
868 double dval{};
869 std::from_chars_result res =
870 std::from_chars( str.data() + woff, str.data() + str.size(), dval );
871
872 if( res.ec != std::errc() )
873 {
874 THROW_PARSE_ERROR( _( "Invalid floating point number" ), CurSource(), CurLine(),
876 }
877
878 return dval;
879#endif
880}
const char * CurText() const
Return a pointer to the current token's text.
Definition: dsnlexer.h:398
const std::string & CurStr() const
Return a reference to current token in std::string form.
Definition: dsnlexer.h:406
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
VECTOR3I res

References _, CurLine(), CurLineNumber(), CurOffset(), CurSource(), CurStr(), CurText(), res, THROW_IO_ERROR, and THROW_PARSE_ERROR.

Referenced by DRAWING_SHEET_PARSER::parseDouble(), PCB_PLOT_PARAMS_PARSER::parseDouble(), parseDouble(), and STROKE_PARAMS_PARSER::parseDouble().

◆ parseDouble() [2/3]

double DSNLEXER::parseDouble ( const char *  aExpected)
inlineprotected

Definition at line 510 of file dsnlexer.h.

511 {
512 NeedNUMBER( aExpected );
513 return parseDouble();
514 }
int NeedNUMBER(const char *aExpectation)
Call NextTok() and then verifies that the token read is type DSN_NUMBER.
Definition: dsnlexer.cpp:405
double parseDouble()
Parse the current token as an ASCII numeric string with possible leading whitespace into a double pre...
Definition: dsnlexer.cpp:825

References NeedNUMBER(), and parseDouble().

◆ parseDouble() [3/3]

template<typename T >
double DSNLEXER::parseDouble ( aToken)
inlineprotected

Definition at line 517 of file dsnlexer.h.

518 {
519 return parseDouble( GetTokenText( aToken ) );
520 }

References GetTokenText(), and parseDouble().

◆ PopReader()

LINE_READER * DSNLEXER::PopReader ( )

Delete the top most LINE_READER from an internal stack of LINE_READERs and in the case of FILE_LINE_READER this means the associated FILE is closed.

The most recently used former LINE_READER on the stack becomes the current LINE_READER and its previous position in its input stream and the its latest line number should pertain. PopReader always starts reading from a new line upon returning to the previous LINE_READER. A pop is only possible if there are at least 2 #LINE_READERs on the stack, since popping the last one is not supported.

Returns
the LINE_READER that was in use before the pop, or NULL if there was not at least two readers on the stack and therefore the pop failed.

Definition at line 201 of file dsnlexer.cpp.

202{
203 LINE_READER* ret = nullptr;
204
205 if( readerStack.size() )
206 {
207 ret = reader;
208 readerStack.pop_back();
209
210 if( readerStack.size() )
211 {
212 reader = readerStack.back();
213 start = reader->Line();
214
215 // force a new readLine() as first thing.
216 limit = start;
217 next = start;
218 }
219 else
220 {
221 reader = nullptr;
222 start = dummy;
223 limit = dummy;
224 }
225 }
226 return ret;
227}
char dummy[1]
when there is no reader.
Definition: dsnlexer.h:526
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:81
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117

References dummy, limit, LINE_READER::Line(), next, reader, readerStack, and start.

◆ PrevTok()

int DSNLEXER::PrevTok ( ) const
inline

Return whatever NextTok() returned the 2nd to last time it was called.

Definition at line 245 of file dsnlexer.h.

246 {
247 return prevTok;
248 }

References prevTok.

◆ PushReader()

void DSNLEXER::PushReader ( LINE_READER aLineReader)

Manage a stack of LINE_READERs in order to handle nested file inclusion.

This function pushes aLineReader onto the top of a stack of LINE_READERs and makes it the current LINE_READER with its own #GetSource(), line number and line text. A grammar must be designed such that the "include" token (whatever its various names), and any of its parameters are not followed by anything on that same line, because PopReader always starts reading from a new line upon returning to the original LINE_READER.

Definition at line 189 of file dsnlexer.cpp.

190{
191 readerStack.push_back( aLineReader );
192 reader = aLineReader;
193 start = (const char*) (*reader);
194
195 // force a new readLine() as first thing.
196 limit = start;
197 next = start;
198}

References limit, next, reader, readerStack, and start.

Referenced by DSNLEXER().

◆ ReadCommentLines()

wxArrayString * DSNLEXER::ReadCommentLines ( )

Check the next sequence of tokens and reads them into a wxArrayString if they are comments.

Reading continues until a non-comment token is encountered, and such last read token remains as CurTok() and as CurText(). No push back or "un get" mechanism is used for this support. Upon return you simply avoid calling NextTok() for the next token, but rather CurTok().

Returns
Heap allocated block of comments or NULL if none. The caller owns the allocation and must delete if not NULL.

Definition at line 802 of file dsnlexer.cpp.

803{
804 wxArrayString* ret = nullptr;
805 bool cmt_setting = SetCommentsAreTokens( true );
806 int tok = NextTok();
807
808 if( tok == DSN_COMMENT )
809 {
810 ret = new wxArrayString();
811
812 do
813 {
814 ret->Add( FromUTF8() );
815 }
816 while( ( tok = NextTok() ) == DSN_COMMENT );
817 }
818
819 SetCommentsAreTokens( cmt_setting );
820
821 return ret;
822}
wxString FromUTF8() const
Return the current token text as a wxString, assuming that the input byte stream is UTF8 encoded.
Definition: dsnlexer.h:415
bool SetCommentsAreTokens(bool val)
Change the handling of comments.
Definition: dsnlexer.h:296

References DSN_COMMENT, FromUTF8(), NextTok(), and SetCommentsAreTokens().

◆ readLine()

int DSNLEXER::readLine ( )
inlineprotected

Definition at line 461 of file dsnlexer.h.

462 {
463 if( reader )
464 {
465 reader->ReadLine();
466
467 unsigned len = reader->Length();
468
469 // start may have changed in ReadLine(), which can resize and
470 // relocate reader's line buffer.
471 start = reader->Line();
472
473 next = start;
474 limit = next + len;
475
476 return len;
477 }
478 return 0;
479 }
virtual char * ReadLine()=0
Read a line of text into the buffer and increments the line number counter.
unsigned Length() const
Return the number of bytes in the last line read from this LINE_READER.
Definition: richio.h:143

References LINE_READER::Length(), limit, LINE_READER::Line(), next, reader, LINE_READER::ReadLine(), and start.

Referenced by NextTok().

◆ SetCommentsAreTokens()

bool DSNLEXER::SetCommentsAreTokens ( bool  val)
inline

Change the handling of comments.

If set true, comments are returned as single line strings with a terminating newline. Otherwise they are consumed by the lexer and not returned.

Definition at line 296 of file dsnlexer.h.

297 {
298 bool old = commentsAreTokens;
299 commentsAreTokens = val;
300 return old;
301 }

References commentsAreTokens.

Referenced by ReadCommentLines().

◆ SetSpaceInQuotedTokens()

bool DSNLEXER::SetSpaceInQuotedTokens ( bool  val)
inline

Change the setting controlling whether a space in a quoted string isa terminator.

Parameters
valIf true, means

Definition at line 280 of file dsnlexer.h.

281 {
282 bool old = space_in_quoted_tokens;
283
284 if( specctraMode )
286
287 return old;
288 }

References space_in_quoted_tokens, and specctraMode.

◆ SetSpecctraMode()

void DSNLEXER::SetSpecctraMode ( bool  aMode)

Change the behavior of this lexer into or out of "specctra mode".

If specctra mode, then: -#) stringDelimiter can be changed. -#) KiCad quoting protocol is not in effect. -#) space_in_quoted_tokens is functional else none of the above are true.

The default mode is non-specctra mode, meaning: -#) stringDelimiter cannot be changed. -#) KiCad quoting protocol is in effect. -#) space_in_quoted_tokens is not functional.

Definition at line 140 of file dsnlexer.cpp.

141{
142 specctraMode = aMode;
143 if( aMode )
144 {
145 // specctra mode defaults, some of which can still be changed in this mode.
147 }
148 else
149 {
151 stringDelimiter = '"';
152 }
153}

References space_in_quoted_tokens, specctraMode, and stringDelimiter.

◆ SetStringDelimiter()

char DSNLEXER::SetStringDelimiter ( char  aStringDelimiter)
inline

Change the string delimiter from the default " to some other character and return the old value.

Parameters
aStringDelimiterThe character in lowest 8 bits.
Returns
The old delimiter in the lowest 8 bits.

Definition at line 265 of file dsnlexer.h.

266 {
267 int old = stringDelimiter;
268
269 if( specctraMode )
270 stringDelimiter = aStringDelimiter;
271
272 return old;
273 }

References specctraMode, and stringDelimiter.

◆ SyncLineReaderWith()

bool DSNLEXER::SyncLineReaderWith ( DSNLEXER aLexer)

Usable only for DSN lexers which share the same LINE_READER.

Synchronizes the pointers handling the data read by the LINE_READER. Allows 2 #DNSLEXER objects to share the same current line, when switching from a #DNSLEXER to another #DNSLEXER

Parameters
aLexerthe model.
Returns
true if the sync can be made ( at least the same line reader ).

Definition at line 166 of file dsnlexer.cpp.

167{
168 // Synchronize the pointers handling the data read by the LINE_READER
169 // only if aLexer shares the same LINE_READER, because only in this case
170 // the char buffer is be common
171
172 if( reader != aLexer.reader )
173 return false;
174
175 // We can synchronize the pointers which handle the data currently read
176 start = aLexer.start;
177 next = aLexer.next;
178 limit = aLexer.limit;
179
180 // Sync these parameters is not mandatory, but could help
181 // for instance in debug
182 curText = aLexer.curText;
183 curOffset = aLexer.curOffset;
184
185 return true;
186}

References curOffset, curText, limit, next, reader, and start.

◆ Syntax()

const char * DSNLEXER::Syntax ( int  aTok)
static

Definition at line 244 of file dsnlexer.cpp.

245{
246 const char* ret;
247
248 switch( aTok )
249 {
250 case DSN_NONE:
251 ret = "NONE";
252 break;
253 case DSN_STRING_QUOTE:
254 ret = "string_quote"; // a special DSN syntax token, see specctra spec.
255 break;
256 case DSN_QUOTE_DEF:
257 ret = "quoted text delimiter";
258 break;
259 case DSN_DASH:
260 ret = "-";
261 break;
262 case DSN_SYMBOL:
263 ret = "symbol";
264 break;
265 case DSN_NUMBER:
266 ret = "number";
267 break;
268 case DSN_RIGHT:
269 ret = ")";
270 break;
271 case DSN_LEFT:
272 ret = "(";
273 break;
274 case DSN_STRING:
275 ret = "quoted string";
276 break;
277 case DSN_EOF:
278 ret = "end of input";
279 break;
280 default:
281 ret = "???";
282 }
283
284 return ret;
285}

References DSN_DASH, DSN_EOF, DSN_LEFT, DSN_NONE, DSN_NUMBER, DSN_QUOTE_DEF, DSN_RIGHT, DSN_STRING, DSN_STRING_QUOTE, and DSN_SYMBOL.

Referenced by GetTokenText().

◆ Unexpected() [1/2]

void DSNLEXER::Unexpected ( const char *  aToken) const

Throw an IO_ERROR exception with an input file specific error message.

Parameters
aTokenis the token which was not expected at the current input location.
Exceptions
IO_ERRORwith the location within the input file of the problem.

Definition at line 358 of file dsnlexer.cpp.

359{
360 wxString errText = wxString::Format(
361 _( "Unexpected '%s'" ), wxString::FromUTF8( text ) );
363}

References _, CurLine(), CurLineNumber(), CurOffset(), CurSource(), Format(), text, and THROW_PARSE_ERROR.

◆ Unexpected() [2/2]

void DSNLEXER::Unexpected ( int  aTok) const

Throw an IO_ERROR exception with an input file specific error message.

Parameters
aTokis the token/keyword type which was not expected at the current input location.
Exceptions
IO_ERRORwith the location within the input file of the problem.

Definition at line 342 of file dsnlexer.cpp.

343{
344 wxString errText = wxString::Format(
345 _( "Unexpected %s" ), GetTokenString( aTok ) );
347}

References _, CurLine(), CurLineNumber(), CurOffset(), CurSource(), Format(), GetTokenString(), and THROW_PARSE_ERROR.

Referenced by Scan(), and scanList().

Member Data Documentation

◆ commentsAreTokens

bool DSNLEXER::commentsAreTokens
protected

true if should return comments as tokens

Definition at line 544 of file dsnlexer.h.

Referenced by init(), InitParserState(), NextTok(), and SetCommentsAreTokens().

◆ curOffset

int DSNLEXER::curOffset
protected

offset within current line of the current token

Definition at line 547 of file dsnlexer.h.

Referenced by CurOffset(), init(), InitParserState(), NextTok(), and SyncLineReaderWith().

◆ curText

std::string DSNLEXER::curText
protected

the text of the current token

Definition at line 550 of file dsnlexer.h.

Referenced by CurStr(), CurText(), FromUTF8(), GetCurStrAsToken(), NextTok(), and SyncLineReaderWith().

◆ curTok

int DSNLEXER::curTok
protected

the current token obtained on last NextTok()

Definition at line 549 of file dsnlexer.h.

Referenced by CurTok(), init(), InitParserState(), and NextTok().

◆ dummy

char DSNLEXER::dummy[1]
protected

when there is no reader.

Definition at line 526 of file dsnlexer.h.

Referenced by PopReader().

◆ iOwnReaders

bool DSNLEXER::iOwnReaders
protected

on readerStack, should I delete them?

Definition at line 522 of file dsnlexer.h.

Referenced by ~DSNLEXER().

◆ keywordCount

unsigned DSNLEXER::keywordCount
protected

count of keywords table

Definition at line 553 of file dsnlexer.h.

Referenced by GetTokenText().

◆ keywords

const KEYWORD* DSNLEXER::keywords
protected

table sorted by CMake for bsearch()

Definition at line 552 of file dsnlexer.h.

Referenced by GetTokenText().

◆ keywordsLookup

const KEYWORD_MAP* DSNLEXER::keywordsLookup
protected

fast, specialized "C string" hashtable

Definition at line 554 of file dsnlexer.h.

Referenced by findToken().

◆ limit

const char* DSNLEXER::limit
protected

Definition at line 525 of file dsnlexer.h.

Referenced by NextTok(), PopReader(), PushReader(), readLine(), and SyncLineReaderWith().

◆ next

const char* DSNLEXER::next
protected

Definition at line 524 of file dsnlexer.h.

Referenced by NextTok(), PopReader(), PushReader(), readLine(), and SyncLineReaderWith().

◆ prevTok

int DSNLEXER::prevTok
protected

curTok from previous NextTok() call.

Definition at line 546 of file dsnlexer.h.

Referenced by init(), InitParserState(), NextTok(), and PrevTok().

◆ reader

LINE_READER* DSNLEXER::reader
protected

◆ readerStack

READER_STACK DSNLEXER::readerStack
protected

all the LINE_READERs by pointer.

no ownership. ownership is via readerStack, maybe, if iOwnReaders

Definition at line 530 of file dsnlexer.h.

Referenced by PopReader(), PushReader(), and ~DSNLEXER().

◆ space_in_quoted_tokens

bool DSNLEXER::space_in_quoted_tokens
protected

blank spaces within quoted strings

Definition at line 542 of file dsnlexer.h.

Referenced by init(), isStringTerminator(), SetSpaceInQuotedTokens(), and SetSpecctraMode().

◆ specctraMode

bool DSNLEXER::specctraMode
protected

if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_in_quoted_tokens is functional else not.

Definition at line 535 of file dsnlexer.h.

Referenced by init(), NextTok(), SetSpaceInQuotedTokens(), SetSpecctraMode(), and SetStringDelimiter().

◆ start

const char* DSNLEXER::start
protected

Definition at line 523 of file dsnlexer.h.

Referenced by NextTok(), PopReader(), PushReader(), readLine(), and SyncLineReaderWith().

◆ stringDelimiter

char DSNLEXER::stringDelimiter
protected

Definition at line 541 of file dsnlexer.h.

Referenced by init(), isStringTerminator(), NextTok(), SetSpecctraMode(), and SetStringDelimiter().


The documentation for this class was generated from the following files: