KiCad PCB EDA Suite
KICAD_NETLIST_PARSER Class Reference

Class KICAD_NETLIST_PARSER is the parser for reading the KiCad s-expression netlist format. More...

#include <netlist_reader.h>

Inheritance diagram for KICAD_NETLIST_PARSER:
NETLIST_LEXER DSNLEXER

Public Member Functions

 KICAD_NETLIST_PARSER (LINE_READER *aReader, NETLIST *aNetlist)
 
void SetLineReader (LINE_READER *aLineReader)
 
void SetNetlist (NETLIST *aNetlist)
 
void Parse ()
 Function Parse parse the full netlist. More...
 
const char * getTokenName (NL_T::T aTok)
 
NL_T::T NextTok ()
 Function NextTok returns the next token found in the input file or T_EOF when reaching the end of file. More...
 
NL_T::T NeedSYMBOL ()
 Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(). More...
 
NL_T::T NeedSYMBOLorNUMBER ()
 Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool IsSymbol() or tok==T_NUMBER. More...
 
NL_T::T CurTok ()
 Function CurTok returns whatever NextTok() returned the last time it was called. More...
 
NL_T::T PrevTok ()
 Function PrevTok returns whatever NextTok() returned the 2nd to last time it was called. More...
 
bool SyncLineReaderWith (DSNLEXER &aLexer)
 Useable only for DSN lexers which share the same LINE_READER Synchronizes the pointers handling the data read by the LINE_READER Allows 2 DNSLEXER to share the same current line, when switching from a DNSLEXER to an other DNSLEXER. More...
 
void SetSpecctraMode (bool aMode)
 Function SetSpecctraMode changes the behavior of this lexer into or out of "specctra mode". More...
 
void PushReader (LINE_READER *aLineReader)
 Function PushReader manages a stack of LINE_READERs in order to handle nested file inclusion. More...
 
LINE_READERPopReader ()
 Function PopReader deletes 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 NeedNUMBER (const char *aExpectation)
 Function NeedNUMBER calls NextTok() and then verifies that the token read is type DSN_NUMBER. More...
 
char SetStringDelimiter (char aStringDelimiter)
 Function SetStringDelimiter changes the string delimiter from the default " to some other character and returns the old value. More...
 
bool SetSpaceInQuotedTokens (bool val)
 Function SetSpaceInQuotedTokens changes the setting controlling whether a space in a quoted string is a terminator. More...
 
bool SetCommentsAreTokens (bool val)
 Function SetCommentsAreTokens changes the handling of comments. More...
 
wxArrayString * ReadCommentLines ()
 Function ReadCommentLines checks the next sequence of tokens and reads them into a wxArrayString if they are comments. More...
 
void Expecting (int aTok)
 Function Expecting throws an IO_ERROR exception with an input file specific error message. More...
 
void Expecting (const char *aTokenList)
 Function Expecting throws an IO_ERROR exception with an input file specific error message. More...
 
void Unexpected (int aTok)
 Function Unexpected throws an IO_ERROR exception with an input file specific error message. More...
 
void Unexpected (const char *aToken)
 Function Unexpected throws an IO_ERROR exception with an input file specific error message. More...
 
void Duplicate (int aTok)
 Function Duplicate throws an IO_ERROR exception with a message saying specifically that aTok is a duplicate of one already seen in current context. More...
 
void NeedLEFT ()
 Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT. More...
 
void NeedRIGHT ()
 Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT. More...
 
const char * GetTokenText (int aTok)
 Function GetTokenText returns the C string representation of a DSN_T value. More...
 
wxString GetTokenString (int aTok)
 Function GetTokenString returns a quote wrapped wxString representation of a token value. More...
 
const char * CurText ()
 Function CurText returns a pointer to the current token's text. More...
 
const std::string & CurStr ()
 Function CurStr returns a reference to current token in std::string form. More...
 
wxString FromUTF8 ()
 Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream is UTF8 encoded. More...
 
int CurLineNumber ()
 Function CurLineNumber returns the current line number within my LINE_READER. More...
 
const char * CurLine ()
 Function CurLine returns the current line of text, from which the CurText() would return its token. More...
 
const wxString & CurSource ()
 Function CurFilename returns the current LINE_READER source. More...
 
int CurOffset ()
 Function CurOffset returns the byte offset within the current line, using a 1 based index. More...
 

Static Public Member Functions

static const char * TokenName (NL_T::T aTok)
 Function TokenName returns the name of the token in ASCII form. More...
 
static bool IsSymbol (int aTok)
 Function IsSymbol tests 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)
 Function findToken takes aToken string and looks up the string in the keywords table. More...
 
bool isStringTerminator (char cc)
 

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
 no ownership. ownership is via readerStack, maybe, if iOwnReaders More...
 
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...
 
unsigned keywordCount
 count of keywords table More...
 
KEYWORD_MAP keyword_hash
 fast, specialized "C string" hashtable More...
 

Private Member Functions

void skipCurrent ()
 Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes the current description. More...
 
void parseComponent ()
 Function parseComponent parse a component description: (comp (ref P1) (value DB25FEMELLE) (footprint DB25FC) (libsource (lib conn) (part DB25)) (sheetpath (names /) (tstamps /)) (tstamp 3256759C)) More...
 
void parseNet ()
 Function parseNet Parses a section like (net (code 20) (name /PC-A0) (node (ref BUS1) (pin 62)) (node (ref U3) (pin 3)) (node (ref U9) (pin M6))) More...
 
void parseLibPartList ()
 Function parseLibPartList reads the section "libparts" in the netlist: (libparts (libpart (lib device) (part C) (description "Condensateur non polarise") (footprints (fp SM*) (fp C?) (fp C1-1)) (fields (field (name Reference) C) (field (name Value) C)) (pins (pin (num 1) (name ~) (type passive)) (pin (num 2) (name ~) (type passive)))) More...
 

Private Attributes

NL_T::T token
 
LINE_READERm_lineReader
 The line reader used to parse the netlist. Not owned. More...
 
NETLISTm_netlist
 The netlist to parse into. Not owned. More...
 

Detailed Description

Class KICAD_NETLIST_PARSER is the parser for reading the KiCad s-expression netlist format.

Definition at line 294 of file netlist_reader.h.

Member Typedef Documentation

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

Definition at line 89 of file dsnlexer.h.

Constructor & Destructor Documentation

KICAD_NETLIST_PARSER::KICAD_NETLIST_PARSER ( LINE_READER aReader,
NETLIST aNetlist 
)

Definition at line 55 of file kicad_netlist_reader.cpp.

References m_lineReader, m_netlist, DSN::T_NONE, and token.

55  :
56  NETLIST_LEXER( aReader )
57 {
58  m_lineReader = aReader;
59  m_netlist = aNetlist;
60  token = T_NONE;
61 }
NETLIST * m_netlist
The netlist to parse into. Not owned.
LINE_READER * m_lineReader
The line reader used to parse the netlist. Not owned.
NETLIST_LEXER(const std::string &aSExpression, const wxString &aSource=wxEmptyString)
Constructor ( const std::string&, const wxString& )

Member Function Documentation

const char* DSNLEXER::CurLine ( )
inlineinherited

Function CurLine returns the current line of text, from which the CurText() would return its token.

Definition at line 517 of file dsnlexer.h.

Referenced by DSNLEXER::Duplicate(), DSNLEXER::Expecting(), CLIPBOARD_IO::Load(), PCB_IO::Load(), DSNLEXER::NeedNUMBER(), DSNLEXER::NextTok(), and DSNLEXER::Unexpected().

518  {
519  return (const char*)(*reader);
520  }
int DSNLEXER::CurLineNumber ( )
inlineinherited

Function CurLineNumber returns the current line number within my LINE_READER.

Definition at line 507 of file dsnlexer.h.

References LINE_READER::LineNumber().

Referenced by DSNLEXER::Duplicate(), DSNLEXER::Expecting(), CLIPBOARD_IO::Load(), PCB_IO::Load(), DSNLEXER::NeedNUMBER(), DSNLEXER::NextTok(), FP_LIB_TABLE::Parse(), SYMBOL_LIB_TABLE::Parse(), parseComponent(), and DSNLEXER::Unexpected().

508  {
509  return reader->LineNumber();
510  }
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
LINE_READER * reader
no ownership. ownership is via readerStack, maybe, if iOwnReaders
Definition: dsnlexer.h:92
int DSNLEXER::CurOffset ( )
inlineinherited

Function CurOffset returns the byte offset within the current line, using a 1 based index.

Returns
int - a one based index into the current line.

Definition at line 538 of file dsnlexer.h.

Referenced by DSNLEXER::Duplicate(), DSNLEXER::Expecting(), CLIPBOARD_IO::Load(), PCB_IO::Load(), DSNLEXER::NeedNUMBER(), DSNLEXER::NextTok(), parseComponent(), and DSNLEXER::Unexpected().

539  {
540  return curOffset + 1;
541  }
int curOffset
offset within current line of the current token
Definition: dsnlexer.h:106
const wxString& DSNLEXER::CurSource ( )
inlineinherited

Function CurFilename returns the current LINE_READER source.

Returns
const wxString& - the source of the lines of text, e.g. a filename or "clipboard".

Definition at line 528 of file dsnlexer.h.

References LINE_READER::GetSource().

Referenced by DSNLEXER::Duplicate(), DSNLEXER::Expecting(), CLIPBOARD_IO::Load(), PCB_IO::Load(), DSNLEXER::NeedNUMBER(), DSNLEXER::NextTok(), parseComponent(), and DSNLEXER::Unexpected().

529  {
530  return reader->GetSource();
531  }
LINE_READER * reader
no ownership. ownership is via readerStack, maybe, if iOwnReaders
Definition: dsnlexer.h:92
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
const std::string& DSNLEXER::CurStr ( )
inlineinherited

Function CurStr returns a reference to current token in std::string form.

Definition at line 488 of file dsnlexer.h.

References DSNLEXER::curText.

Referenced by PCB_PLOT_PARAMS_PARSER::Parse(), and PAGE_LAYOUT_READER_PARSER::readPngdata().

489  {
490  return curText;
491  }
std::string curText
the text of the current token
Definition: dsnlexer.h:109
const char* DSNLEXER::CurText ( )
inlineinherited

Function CurText returns a pointer to the current token's text.

Definition at line 479 of file dsnlexer.h.

Referenced by DSN::SPECCTRA_DB::doANCESTOR(), DSN::SPECCTRA_DB::doCIRCLE(), DSN::SPECCTRA_DB::doCLASS(), DSN::SPECCTRA_DB::doCLASSES(), DSN::SPECCTRA_DB::doCOMP_ORDER(), DSN::SPECCTRA_DB::doCOMPONENT(), DSN::SPECCTRA_DB::doCONNECT(), DSN::SPECCTRA_DB::doCONTROL(), DSN::SPECCTRA_DB::doFROMTO(), DSN::SPECCTRA_DB::doGRID(), DSN::SPECCTRA_DB::doHISTORY(), DSN::SPECCTRA_DB::doIMAGE(), DSN::SPECCTRA_DB::doKEEPOUT(), DSN::SPECCTRA_DB::doLAYER(), DSN::SPECCTRA_DB::doLAYER_RULE(), DSN::SPECCTRA_DB::doLIBRARY(), DSN::SPECCTRA_DB::doNET(), DSN::SPECCTRA_DB::doNET_OUT(), DSN::SPECCTRA_DB::doNETWORK(), DSN::SPECCTRA_DB::doPADSTACK(), DSN::SPECCTRA_DB::doPARSER(), DSN::SPECCTRA_DB::doPATH(), DSN::SPECCTRA_DB::doPCB(), DSN::SPECCTRA_DB::doPIN(), DSN::SPECCTRA_DB::doPLACE(), DSN::SPECCTRA_DB::doPROPERTIES(), DSN::SPECCTRA_DB::doQARC(), DSN::SPECCTRA_DB::doRECTANGLE(), DSN::SPECCTRA_DB::doREGION(), DSN::SPECCTRA_DB::doRESOLUTION(), DSN::SPECCTRA_DB::doROUTE(), DSN::SPECCTRA_DB::doRULE(), DSN::SPECCTRA_DB::doSESSION(), DSN::SPECCTRA_DB::doSHAPE(), DSN::SPECCTRA_DB::doSPECCTRA_LAYER_PAIR(), DSN::SPECCTRA_DB::doSTRINGPROP(), DSN::SPECCTRA_DB::doSTRUCTURE(), DSN::SPECCTRA_DB::doSTRUCTURE_OUT(), DSN::SPECCTRA_DB::doSUPPLY_PIN(), DSN::SPECCTRA_DB::doTOKPROP(), DSN::SPECCTRA_DB::doTOPOLOGY(), DSN::SPECCTRA_DB::doVIA(), DSN::SPECCTRA_DB::doWAS_IS(), DSN::SPECCTRA_DB::doWINDOW(), DSN::SPECCTRA_DB::doWIRE(), DSN::SPECCTRA_DB::doWIRE_VIA(), DSN::SPECCTRA_DB::doWIRING(), PCAD2KICAD::LoadInputFile(), PCB_PLOT_PARAMS_PARSER::Parse(), PAGE_LAYOUT_READER_PARSER::Parse(), TEMPLATE_FIELDNAME::Parse(), TEMPLATES::Parse(), PAGE_LAYOUT_READER_PARSER::parseBitmap(), parseComponent(), PAGE_LAYOUT_READER_PARSER::parseCoordinate(), PCB_PLOT_PARAMS_PARSER::parseDouble(), PAGE_LAYOUT_READER_PARSER::parseDouble(), PAGE_LAYOUT_READER_PARSER::parseGraphic(), PCB_PARSER::parseHex(), PCB_PLOT_PARAMS_PARSER::parseInt(), PAGE_LAYOUT_READER_PARSER::parseInt(), PCB_PARSER::parseInt(), parseLibPartList(), parseNet(), BOM_CFG_READER_PARSER::parsePlugin(), PAGE_LAYOUT_READER_PARSER::parsePolygon(), PAGE_LAYOUT_READER_PARSER::parsePolyOutline(), PAGE_LAYOUT_READER_PARSER::parseSetup(), PAGE_LAYOUT_READER_PARSER::parseText(), DSN::SPECCTRA_DB::readCOMPnPIN(), PAGE_LAYOUT_READER_PARSER::readOption(), PAGE_LAYOUT_READER_PARSER::readPngdata(), DSN::SPECCTRA_DB::readTIME(), scanAtom(), and scanList().

480  {
481  return curText.c_str();
482  }
std::string curText
the text of the current token
Definition: dsnlexer.h:109
NL_T::T NETLIST_LEXER::CurTok ( )
inlineinherited

Function CurTok returns whatever NextTok() returned the last time it was called.

Definition at line 191 of file netlist_lexer.h.

References DSNLEXER::CurTok().

192  {
193  return (NL_T::T) DSNLEXER::CurTok();
194  }
int CurTok()
Function CurTok returns whatever NextTok() returned the last time it was called.
Definition: dsnlexer.h:320
T
enum T contains all this lexer's tokens.
Definition: netlist_lexer.h:26
void DSNLEXER::Duplicate ( int  aTok)
inherited

Function Duplicate throws 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 377 of file dsnlexer.cpp.

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

Referenced by FP_LIB_TABLE::Parse(), SYMBOL_LIB_TABLE::Parse(), and LIB_TABLE_ROW::Parse().

378 {
379  wxString errText = wxString::Format(
380  _("%s is a duplicate"), GetTokenString( aTok ).GetData() );
382 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void DSNLEXER::Expecting ( int  aTok)
inherited

Function Expecting throws 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 353 of file dsnlexer.cpp.

References DSNLEXER::CurLine(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), Format(), GetChars(), DSNLEXER::GetTokenString(), and THROW_PARSE_ERROR.

Referenced by DSN::SPECCTRA_DB::doANCESTOR(), DSN::SPECCTRA_DB::doBOUNDARY(), DSN::SPECCTRA_DB::doCIRCLE(), DSN::SPECCTRA_DB::doCLASS(), DSN::SPECCTRA_DB::doCLASS_CLASS(), DSN::SPECCTRA_DB::doCLASSES(), DSN::SPECCTRA_DB::doCOMP_ORDER(), DSN::SPECCTRA_DB::doCOMPONENT(), DSN::SPECCTRA_DB::doCONNECT(), DSN::SPECCTRA_DB::doCONTROL(), DSN::SPECCTRA_DB::doFROMTO(), DSN::SPECCTRA_DB::doGRID(), DSN::SPECCTRA_DB::doHISTORY(), DSN::SPECCTRA_DB::doIMAGE(), DSN::SPECCTRA_DB::doKEEPOUT(), DSN::SPECCTRA_DB::doLAYER(), DSN::SPECCTRA_DB::doLAYER_NOISE_WEIGHT(), DSN::SPECCTRA_DB::doLAYER_RULE(), DSN::SPECCTRA_DB::doLIBRARY(), DSN::SPECCTRA_DB::doNET(), DSN::SPECCTRA_DB::doNET_OUT(), DSN::SPECCTRA_DB::doNETWORK(), DSN::SPECCTRA_DB::doPADSTACK(), DSN::SPECCTRA_DB::doPARSER(), DSN::SPECCTRA_DB::doPATH(), DSN::SPECCTRA_DB::doPCB(), DSN::SPECCTRA_DB::doPIN(), DSN::SPECCTRA_DB::doPLACE(), DSN::SPECCTRA_DB::doPLACEMENT(), DSN::SPECCTRA_DB::doPROPERTIES(), DSN::SPECCTRA_DB::doQARC(), DSN::SPECCTRA_DB::doRECTANGLE(), DSN::SPECCTRA_DB::doREGION(), DSN::SPECCTRA_DB::doRESOLUTION(), DSN::SPECCTRA_DB::doROUTE(), DSN::SPECCTRA_DB::doSESSION(), DSN::SPECCTRA_DB::doSHAPE(), DSN::SPECCTRA_DB::doSPECCTRA_LAYER_PAIR(), DSN::SPECCTRA_DB::doSTRUCTURE(), DSN::SPECCTRA_DB::doSTRUCTURE_OUT(), DSN::SPECCTRA_DB::doSUPPLY_PIN(), DSN::SPECCTRA_DB::doTOPOLOGY(), DSN::SPECCTRA_DB::doUNIT(), DSN::SPECCTRA_DB::doVIA(), DSN::SPECCTRA_DB::doWAS_IS(), DSN::SPECCTRA_DB::doWINDOW(), DSN::SPECCTRA_DB::doWIRE(), DSN::SPECCTRA_DB::doWIRE_VIA(), DSN::SPECCTRA_DB::doWIRING(), DSN::SPECCTRA_DB::LoadPCB(), DSN::SPECCTRA_DB::LoadSESSION(), DSNLEXER::NeedLEFT(), DSNLEXER::NeedRIGHT(), DSNLEXER::NeedSYMBOL(), DSNLEXER::NeedSYMBOLorNUMBER(), PCB_PLOT_PARAMS_PARSER::Parse(), FP_LIB_TABLE::Parse(), SYMBOL_LIB_TABLE::Parse(), TEMPLATE_FIELDNAME::Parse(), LIB_TABLE_ROW::Parse(), PCB_PLOT_PARAMS_PARSER::parseBool(), parseComponent(), PCB_PLOT_PARAMS_PARSER::parseDouble(), PAGE_LAYOUT_READER_PARSER::parseDouble(), PCB_PLOT_PARAMS_PARSER::parseInt(), PAGE_LAYOUT_READER_PARSER::parseInt(), parseLibPartList(), DSN::SPECCTRA_DB::readCOMPnPIN(), and DSN::SPECCTRA_DB::readTIME().

354 {
355  wxString errText = wxString::Format(
356  _("Expecting '%s'"), GetChars( GetTokenString( aTok ) ) );
358 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void DSNLEXER::Expecting ( const char *  aTokenList)
inherited

Function Expecting throws 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 361 of file dsnlexer.cpp.

References DSNLEXER::CurLine(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), Format(), GetChars(), and THROW_PARSE_ERROR.

362 {
363  wxString errText = wxString::Format(
364  _("Expecting '%s'"), GetChars( wxString::FromUTF8( text ) ) );
366 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
int DSNLEXER::findToken ( const std::string &  aToken)
inlineprotectedinherited

Function findToken takes aToken string and looks up the string in the keywords table.

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

Definition at line 260 of file dsnlexer.cpp.

References DSN_SYMBOL, and DSNLEXER::keyword_hash.

Referenced by DSNLEXER::NextTok().

261 {
262  KEYWORD_MAP::const_iterator it = keyword_hash.find( tok.c_str() );
263  if( it != keyword_hash.end() )
264  return it->second;
265 
266  return DSN_SYMBOL; // not a keyword, some arbitrary symbol.
267 }
KEYWORD_MAP keyword_hash
fast, specialized "C string" hashtable
Definition: dsnlexer.h:113
wxString DSNLEXER::FromUTF8 ( )
inlineinherited

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

Definition at line 498 of file dsnlexer.h.

Referenced by PAGE_LAYOUT_READER_PARSER::Parse(), FP_LIB_TABLE::Parse(), SYMBOL_LIB_TABLE::Parse(), LIB_TABLE_ROW::Parse(), PAGE_LAYOUT_READER_PARSER::parseBitmap(), parseComponent(), PAGE_LAYOUT_READER_PARSER::parseGraphic(), BOM_CFG_READER_PARSER::parsePlugin(), PAGE_LAYOUT_READER_PARSER::parsePolygon(), PAGE_LAYOUT_READER_PARSER::parseText(), and DSNLEXER::ReadCommentLines().

499  {
500  return wxString::FromUTF8( curText.c_str() );
501  }
std::string curText
the text of the current token
Definition: dsnlexer.h:109
const char* KICAD_NETLIST_PARSER::getTokenName ( NL_T::T  aTok)
inline

Definition at line 371 of file netlist_reader.h.

References NETLIST_LEXER::TokenName().

372  {
373  return NETLIST_LEXER::TokenName( aTok );
374  }
static const char * TokenName(NL_T::T aTok)
Function TokenName returns the name of the token in ASCII form.
wxString DSNLEXER::GetTokenString ( int  aTok)
inherited

Function GetTokenString returns a quote wrapped wxString representation of a token value.

Definition at line 334 of file dsnlexer.cpp.

References DSNLEXER::GetTokenText().

Referenced by DSNLEXER::Duplicate(), DSNLEXER::Expecting(), DSN::SPECCTRA_DB::makeVIA(), and DSNLEXER::Unexpected().

335 {
336  wxString ret;
337 
338  ret << wxT("'") << wxString::FromUTF8( GetTokenText(aTok) ) << wxT("'");
339 
340  return ret;
341 }
const char * GetTokenText(int aTok)
Function GetTokenText returns the C string representation of a DSN_T value.
Definition: dsnlexer.cpp:315
const char * DSNLEXER::GetTokenText ( int  aTok)
inherited

Function GetTokenText returns the C string representation of a DSN_T value.

Definition at line 315 of file dsnlexer.cpp.

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

Referenced by DSNLEXER::GetTokenString(), PCB_PARSER::parseBoardUnits(), and PCB_PARSER::parseDouble().

316 {
317  const char* ret;
318 
319  if( aTok < 0 )
320  {
321  return Syntax( aTok );
322  }
323  else if( (unsigned) aTok < keywordCount )
324  {
325  ret = keywords[aTok].name;
326  }
327  else
328  ret = "token too big";
329 
330  return ret;
331 }
const KEYWORD * keywords
table sorted by CMake for bsearch()
Definition: dsnlexer.h:111
const char * name
unique keyword.
Definition: dsnlexer.h:42
unsigned keywordCount
count of keywords table
Definition: dsnlexer.h:112
static const char * Syntax(int aTok)
Definition: dsnlexer.cpp:271
void DSNLEXER::init ( )
protectedinherited

Definition at line 44 of file dsnlexer.cpp.

References DSNLEXER::commentsAreTokens, DSNLEXER::curOffset, DSNLEXER::curTok, DSN_NONE, DSNLEXER::keyword_hash, DSNLEXER::keywordCount, DSNLEXER::keywords, KEYWORD::name, DSNLEXER::prevTok, DSNLEXER::space_in_quoted_tokens, DSNLEXER::specctraMode, DSNLEXER::stringDelimiter, and KEYWORD::token.

Referenced by DSNLEXER::DSNLEXER().

45 {
46  curTok = DSN_NONE;
47  prevTok = DSN_NONE;
48 
49  stringDelimiter = '"';
50 
51  specctraMode = false;
52  space_in_quoted_tokens = false;
53  commentsAreTokens = false;
54 
55  curOffset = 0;
56 
57 #if 1
58  if( keywordCount > 11 )
59  {
60  // resize the hashtable bucket count
61  keyword_hash.reserve( keywordCount );
62  }
63 
64  // fill the specialized "C string" hashtable from keywords[]
65  const KEYWORD* it = keywords;
66  const KEYWORD* end = it + keywordCount;
67 
68  for( ; it < end; ++it )
69  {
70  keyword_hash[it->name] = it->token;
71  }
72 #endif
73 }
int curOffset
offset within current line of the current token
Definition: dsnlexer.h:106
bool commentsAreTokens
true if should return comments as tokens
Definition: dsnlexer.h:103
const KEYWORD * keywords
table sorted by CMake for bsearch()
Definition: dsnlexer.h:111
const char * name
unique keyword.
Definition: dsnlexer.h:42
KEYWORD_MAP keyword_hash
fast, specialized "C string" hashtable
Definition: dsnlexer.h:113
bool space_in_quoted_tokens
blank spaces within quoted strings
Definition: dsnlexer.h:101
bool specctraMode
if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_...
Definition: dsnlexer.h:94
int prevTok
curTok from previous NextTok() call.
Definition: dsnlexer.h:105
unsigned keywordCount
count of keywords table
Definition: dsnlexer.h:112
int curTok
the current token obtained on last NextTok()
Definition: dsnlexer.h:108
Struct KEYWORD holds a keyword string and its unique integer token.
Definition: dsnlexer.h:40
char stringDelimiter
Definition: dsnlexer.h:100
int token
a zero based index into an array of KEYWORDs
Definition: dsnlexer.h:43
bool DSNLEXER::isStringTerminator ( char  cc)
inlineprotectedinherited

Definition at line 147 of file dsnlexer.h.

Referenced by DSNLEXER::NextTok().

148  {
149  if( !space_in_quoted_tokens && cc==' ' )
150  return true;
151 
152  if( cc == stringDelimiter )
153  return true;
154 
155  return false;
156  }
bool space_in_quoted_tokens
blank spaces within quoted strings
Definition: dsnlexer.h:101
char stringDelimiter
Definition: dsnlexer.h:100
bool DSNLEXER::IsSymbol ( int  aTok)
staticinherited

Function IsSymbol tests 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 344 of file dsnlexer.cpp.

References DSN_STRING, and DSN_SYMBOL.

Referenced by DSN::SPECCTRA_DB::doCLASS(), DSN::SPECCTRA_DB::doCLASSES(), DSN::SPECCTRA_DB::doCOMP_ORDER(), DSN::SPECCTRA_DB::doCOMPONENT(), DSN::SPECCTRA_DB::doFROMTO(), DSN::SPECCTRA_DB::doIMAGE(), DSN::SPECCTRA_DB::doKEEPOUT(), DSN::SPECCTRA_DB::doLAYER(), DSN::SPECCTRA_DB::doLAYER_RULE(), DSN::SPECCTRA_DB::doNET(), DSN::SPECCTRA_DB::doPADSTACK(), DSN::SPECCTRA_DB::doPATH(), DSN::SPECCTRA_DB::doPIN(), DSN::SPECCTRA_DB::doPLACE(), DSN::SPECCTRA_DB::doREGION(), DSN::SPECCTRA_DB::doSUPPLY_PIN(), DSN::SPECCTRA_DB::doVIA(), DSN::SPECCTRA_DB::doWIRE_VIA(), DSNLEXER::NeedSYMBOL(), DSNLEXER::NeedSYMBOLorNUMBER(), and DSN::SPECCTRA_DB::readCOMPnPIN().

345 {
346  // This is static and not inline to reduce code space.
347 
348  // if aTok is >= 0, then it is a coincidental match to a keyword.
349  return aTok==DSN_SYMBOL || aTok==DSN_STRING || aTok>=0;
350 }
void DSNLEXER::NeedLEFT ( )
inherited

Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT.

If it is not, an IO_ERROR is thrown.

Exceptions
IO_ERROR,ifthe next token is not a DSN_LEFT

Definition at line 393 of file dsnlexer.cpp.

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

Referenced by FP_LIB_TABLE::Parse(), SYMBOL_LIB_TABLE::Parse(), TEMPLATE_FIELDNAME::Parse(), and LIB_TABLE_ROW::Parse().

394 {
395  int tok = NextTok();
396  if( tok != DSN_LEFT )
397  Expecting( DSN_LEFT );
398 }
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
int NextTok()
Function NextTok returns the next token found in the input file or DSN_EOF when reaching the end of f...
Definition: dsnlexer.cpp:540
int DSNLEXER::NeedNUMBER ( const char *  aExpectation)
inherited

Function NeedNUMBER calls NextTok() and then verifies that the token read is type DSN_NUMBER.

If not, and IO_ERROR is thrown using text from aExpectation.

Returns
int - the actual token read in.
Exceptions
IO_ERROR,ifthe next token does not satisfy the above test

Definition at line 427 of file dsnlexer.cpp.

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

Referenced by PCB_PARSER::parseDouble(), and PCB_PARSER::parseInt().

428 {
429  int tok = NextTok();
430  if( tok != DSN_NUMBER )
431  {
432  wxString errText = wxString::Format(
433  _("need a NUMBER for '%s'"), wxString::FromUTF8( aExpectation ).GetData() );
435  }
436  return tok;
437 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int NextTok()
Function NextTok returns the next token found in the input file or DSN_EOF when reaching the end of f...
Definition: dsnlexer.cpp:540
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
void DSNLEXER::NeedRIGHT ( )
inherited

Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.

If it is not, an IO_ERROR is thrown.

Exceptions
IO_ERROR,ifthe next token is not a DSN_RIGHT

Definition at line 401 of file dsnlexer.cpp.

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

Referenced by DSN::SPECCTRA_DB::doANCESTOR(), DSN::SPECCTRA_DB::doBOUNDARY(), DSN::SPECCTRA_DB::doCONTROL(), DSN::SPECCTRA_DB::doFROMTO(), DSN::SPECCTRA_DB::doHISTORY(), DSN::SPECCTRA_DB::doIMAGE(), DSN::SPECCTRA_DB::doKEEPOUT(), DSN::SPECCTRA_DB::doLAYER_RULE(), DSN::SPECCTRA_DB::doNET(), DSN::SPECCTRA_DB::doNET_OUT(), DSN::SPECCTRA_DB::doPADSTACK(), DSN::SPECCTRA_DB::doPARSER(), DSN::SPECCTRA_DB::doPATH(), DSN::SPECCTRA_DB::doPIN(), DSN::SPECCTRA_DB::doPLACE(), DSN::SPECCTRA_DB::doPLACEMENT(), DSN::SPECCTRA_DB::doPROPERTIES(), DSN::SPECCTRA_DB::doQARC(), DSN::SPECCTRA_DB::doRECTANGLE(), DSN::SPECCTRA_DB::doRESOLUTION(), DSN::SPECCTRA_DB::doSESSION(), DSN::SPECCTRA_DB::doSHAPE(), DSN::SPECCTRA_DB::doSPECCTRA_LAYER_PAIR(), DSN::SPECCTRA_DB::doSTRINGPROP(), DSN::SPECCTRA_DB::doSUPPLY_PIN(), DSN::SPECCTRA_DB::doTOKPROP(), DSN::SPECCTRA_DB::doUNIT(), DSN::SPECCTRA_DB::doWAS_IS(), DSN::SPECCTRA_DB::doWIRE(), DSN::SPECCTRA_DB::doWIRE_VIA(), PCB_PLOT_PARAMS_PARSER::Parse(), FP_LIB_TABLE::Parse(), SYMBOL_LIB_TABLE::Parse(), TEMPLATE_FIELDNAME::Parse(), LIB_TABLE_ROW::Parse(), Parse(), PAGE_LAYOUT_READER_PARSER::parseBitmap(), parseComponent(), PAGE_LAYOUT_READER_PARSER::parseGraphic(), parseLibPartList(), parseNet(), BOM_CFG_READER_PARSER::parsePlugin(), PAGE_LAYOUT_READER_PARSER::parsePolygon(), PAGE_LAYOUT_READER_PARSER::parsePolyOutline(), PAGE_LAYOUT_READER_PARSER::parseSetup(), PAGE_LAYOUT_READER_PARSER::parseText(), and PAGE_LAYOUT_READER_PARSER::readPngdata().

402 {
403  int tok = NextTok();
404  if( tok != DSN_RIGHT )
405  Expecting( DSN_RIGHT );
406 }
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
int NextTok()
Function NextTok returns the next token found in the input file or DSN_EOF when reaching the end of f...
Definition: dsnlexer.cpp:540
NL_T::T NETLIST_LEXER::NeedSYMBOL ( )
inlineinherited

Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol().

If not, an IO_ERROR is thrown.

Returns
int - the actual token read in.
Exceptions
IO_ERROR,ifthe next token does not satisfy IsSymbol()

Definition at line 169 of file netlist_lexer.h.

References DSNLEXER::NeedSYMBOL().

170  {
171  return (NL_T::T) DSNLEXER::NeedSYMBOL();
172  }
int NeedSYMBOL()
Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(...
Definition: dsnlexer.cpp:409
T
enum T contains all this lexer's tokens.
Definition: netlist_lexer.h:26
NL_T::T NETLIST_LEXER::NeedSYMBOLorNUMBER ( )
inlineinherited

Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool IsSymbol() or tok==T_NUMBER.

If not, an IO_ERROR is thrown.

Returns
int - the actual token read in.
Exceptions
IO_ERROR,ifthe next token does not satisfy the above test

Definition at line 182 of file netlist_lexer.h.

References DSNLEXER::NeedSYMBOLorNUMBER().

Referenced by parseComponent(), parseLibPartList(), and parseNet().

183  {
185  }
int NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: dsnlexer.cpp:418
T
enum T contains all this lexer's tokens.
Definition: netlist_lexer.h:26
NL_T::T NETLIST_LEXER::NextTok ( )
inlineinherited

Function NextTok returns the next token found in the input file or T_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
NL_T::T - the type of token found next.
Exceptions
IO_ERROR- only if the LINE_READER throws it.

Definition at line 156 of file netlist_lexer.h.

References DSNLEXER::NextTok().

Referenced by Parse(), parseComponent(), parseLibPartList(), parseNet(), and skipCurrent().

157  {
158  return (NL_T::T) DSNLEXER::NextTok();
159  }
T
enum T contains all this lexer's tokens.
Definition: netlist_lexer.h:26
int NextTok()
Function NextTok returns the next token found in the input file or DSN_EOF when reaching the end of f...
Definition: dsnlexer.cpp:540
void KICAD_NETLIST_PARSER::Parse ( )

Function Parse parse the full netlist.

Definition at line 84 of file kicad_netlist_reader.cpp.

References DSNLEXER::NeedRIGHT(), NETLIST_LEXER::NextTok(), parseComponent(), parseLibPartList(), parseNet(), skipCurrent(), DSN::T_comp, NL_T::T_components, NL_T::T_design, DSN::T_EOF, NL_T::T_export, DSN::T_LEFT, NL_T::T_libpart, NL_T::T_libparts, NL_T::T_libraries, DSN::T_net, DSN::T_nets, DSN::T_RIGHT, TLIB_T::T_version, and token.

85 {
86  int plevel = 0; // the count of ')' to read and end of file,
87  // after parsing all sections
88 
89  while( ( token = NextTok() ) != T_EOF )
90  {
91  if( token == T_LEFT )
92  token = NextTok();
93 
94  switch( token )
95  {
96  case T_export: // The netlist starts here.
97  // nothing to do here,
98  // just increment the count of ')' to read and end of file
99  plevel++;
100  break;
101 
102  case T_version: // The netlist starts here.
103  // version id not yet used: read it but does not use it
104  NextTok();
105  NeedRIGHT();
106  break;
107 
108  case T_components: // The section comp starts here.
109  while( ( token = NextTok() ) != T_RIGHT )
110  {
111  if( token == T_LEFT )
112  token = NextTok();
113 
114  if( token == T_comp ) // A component section found. Read it
115  parseComponent();
116  }
117 
118  break;
119 
120  case T_nets: // The section nets starts here.
121  while( ( token = NextTok() ) != T_RIGHT )
122  {
123  if( token == T_LEFT )
124  token = NextTok();
125 
126  if( token == T_net )
127  {
128  // A net section if found. Read it
129  parseNet();
130  }
131  }
132 
133  break;
134 
135  case T_libparts: // The section libparts starts here.
136  while( ( token = NextTok() ) != T_RIGHT )
137  {
138  if( token == T_LEFT )
139  token = NextTok();
140 
141  if( token == T_libpart )
142  {
143  // A libpart section if found. Read it
145  }
146  }
147 
148  break;
149 
150  case T_libraries: // The section libraries starts here.
151  // List of libraries in use.
152  // Not used here, just skip it
153  skipCurrent();
154  break;
155 
156  case T_design: // The section design starts here.
157  // Not used (mainly they are comments), just skip it
158  skipCurrent();
159  break;
160 
161  case T_RIGHT: // The closing parenthesis of the file.
162  // Not used (mainly they are comments), just skip it
163  plevel--;
164  break;
165 
166  default:
167  skipCurrent();
168  break;
169  }
170  }
171 
172  if( plevel != 0 )
173  {
174  wxLogDebug( wxT( "KICAD_NETLIST_PARSER::Parse(): bad parenthesis count (count = %d"),
175  plevel );
176  }
177 }
void parseComponent()
Function parseComponent parse a component description: (comp (ref P1) (value DB25FEMELLE) (footprint ...
void skipCurrent()
Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes ...
NL_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
void parseLibPartList()
Function parseLibPartList reads the section "libparts" in the netlist: (libparts (libpart (lib device...
void parseNet()
Function parseNet Parses a section like (net (code 20) (name /PC-A0) (node (ref BUS1) (pin 62)) (node...
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
void KICAD_NETLIST_PARSER::parseComponent ( )
private

Function parseComponent parse a component description: (comp (ref P1) (value DB25FEMELLE) (footprint DB25FC) (libsource (lib conn) (part DB25)) (sheetpath (names /) (tstamps /)) (tstamp 3256759C))

Definition at line 271 of file kicad_netlist_reader.cpp.

References NETLIST::AddComponent(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), DSNLEXER::CurText(), DSNLEXER::Expecting(), FROM_UTF8(), DSNLEXER::FromUTF8(), GetChars(), m_netlist, name, DSNLEXER::NeedRIGHT(), NETLIST_LEXER::NeedSYMBOLorNUMBER(), NETLIST_LEXER::NextTok(), LIB_ID::Parse(), COMPONENT::SetLibrary(), COMPONENT::SetName(), skipCurrent(), DSN::T_footprint, DSN::T_LEFT, FP_LIB_TABLE_T::T_lib, NL_T::T_libsource, NL_T::T_part, NL_T::T_ref, DSN::T_RIGHT, NL_T::T_sheetpath, NL_T::T_tstamp, NL_T::T_tstamps, DSN::T_value, THROW_IO_ERROR, and token.

Referenced by Parse().

272 {
273  /* Parses a section like
274  * (comp (ref P1)
275  * (value DB25FEMELLE)
276  * (footprint DB25FC)
277  * (libsource (lib conn) (part DB25))
278  * (sheetpath (names /) (tstamps /))
279  * (tstamp 3256759C))
280  *
281  * other fields (unused) are skipped
282  * A component need a reference, value, footprint name and a full time stamp
283  * The full time stamp is the sheetpath time stamp + the component time stamp
284  */
285  LIB_ID fpid;
286  wxString footprint;
287  wxString ref;
288  wxString value;
289  wxString library;
290  wxString name;
291  wxString pathtimestamp, timestamp;
292 
293  // The token comp was read, so the next data is (ref P1)
294  while( (token = NextTok()) != T_RIGHT )
295  {
296  if( token == T_LEFT )
297  token = NextTok();
298 
299  switch( token )
300  {
301  case T_ref:
303  ref = FROM_UTF8( CurText() );
304  NeedRIGHT();
305  break;
306 
307  case T_value:
309  value = FROM_UTF8( CurText() );
310  NeedRIGHT();
311  break;
312 
313  case T_footprint:
315  footprint = FromUTF8();
316  NeedRIGHT();
317  break;
318 
319  case T_libsource:
320  // Read libsource
321  while( (token = NextTok()) != T_RIGHT )
322  {
323  if( token == T_LEFT )
324  token = NextTok();
325 
326  if( token == T_lib )
327  {
329  library = FROM_UTF8( CurText() );
330  NeedRIGHT();
331  }
332  else if( token == T_part )
333  {
335  name = FROM_UTF8( CurText() );
336  NeedRIGHT();
337  }
338  else
339  {
340  Expecting( "part or lib" );
341  }
342  }
343  break;
344 
345  case T_sheetpath:
346  while( ( token = NextTok() ) != T_tstamps );
348  pathtimestamp = FROM_UTF8( CurText() );
349  NeedRIGHT();
350  NeedRIGHT();
351  break;
352 
353  case T_tstamp:
355  timestamp = FROM_UTF8( CurText() );
356  NeedRIGHT();
357  break;
358 
359  default:
360  // Skip not used data (i.e all other tokens)
361  skipCurrent();
362  break;
363  }
364  }
365 
366  if( !footprint.IsEmpty() && fpid.Parse( footprint ) >= 0 )
367  {
368  wxString error;
369  error.Printf( _( "invalid footprint ID in\nfile: <%s>\nline: %d\noffset: %d" ),
371 
372  THROW_IO_ERROR( error );
373  }
374 
375  pathtimestamp += timestamp;
376  COMPONENT* component = new COMPONENT( fpid, ref, value, pathtimestamp );
377  component->SetName( name );
378  component->SetLibrary( library );
379  m_netlist->AddComponent( component );
380 }
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
void SetLibrary(const wxString &aLibrary)
Definition: pcb_netlist.h:146
NETLIST * m_netlist
The netlist to parse into. Not owned.
void skipCurrent()
Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes ...
int Parse(const UTF8 &aId)
Parse LIB_ID with the information from aId.
Definition: lib_id.cpp:122
A logical library item identifier and consists of various portions much like a URI.
Definition: lib_id.h:51
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
void AddComponent(COMPONENT *aComponent)
Function AddComponent adds aComponent to the NETLIST.
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
NL_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
NL_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void SetName(const wxString &aName)
Definition: pcb_netlist.h:143
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
const char * name
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:38
void KICAD_NETLIST_PARSER::parseLibPartList ( )
private

Function parseLibPartList reads the section "libparts" in the netlist: (libparts (libpart (lib device) (part C) (description "Condensateur non polarise") (footprints (fp SM*) (fp C?) (fp C1-1)) (fields (field (name Reference) C) (field (name Value) C)) (pins (pin (num 1) (name ~) (type passive)) (pin (num 2) (name ~) (type passive))))

And add the strings giving the footprint filter (subsection footprints) of the corresponding module info

This section is used by CvPcb, and is not useful in Pcbnew, therefore it it not always read

Definition at line 383 of file kicad_netlist_reader.cpp.

References DSNLEXER::CurText(), DSNLEXER::Expecting(), FROM_UTF8(), NETLIST::GetComponent(), NETLIST::GetCount(), COMPONENT::IsLibSource(), m_netlist, DSNLEXER::NeedRIGHT(), NETLIST_LEXER::NeedSYMBOLorNUMBER(), NETLIST_LEXER::NextTok(), COMPONENT::SetFootprintFilters(), skipCurrent(), NL_T::T_alias, NL_T::T_aliases, NL_T::T_footprints, NL_T::T_fp, DSN::T_LEFT, FP_LIB_TABLE_T::T_lib, NL_T::T_part, DSN::T_RIGHT, and token.

Referenced by Parse().

384 {
385  /* Parses a section like
386  * (libpart (lib device) (part C)
387  * (aliases
388  * (alias Cxx)
389  * (alias Cyy))
390  * (description "Condensateur non polarise")
391  * (footprints
392  * (fp SM*)
393  * (fp C?)
394  * (fp C1-1))
395  * (fields
396  * (field (name Reference) C)
397  * (field (name Value) C))
398  * (pins
399  * (pin (num 1) (name ~) (type passive))
400  * (pin (num 2) (name ~) (type passive))))
401  *
402  * Currently footprints section/fp are read and data stored
403  * other fields (unused) are skipped
404  */
405  COMPONENT* component = NULL;
406  wxString libName;
407  wxString libPartName;
408  wxArrayString footprintFilters;
409  wxArrayString aliases;
410 
411  // The last token read was libpart, so read the next token
412  while( (token = NextTok()) != T_RIGHT )
413  {
414  if( token == T_LEFT )
415  token = NextTok();
416 
417  switch( token )
418  {
419  case T_lib:
421  libName = FROM_UTF8( CurText() );
422  NeedRIGHT();
423  break;
424 
425  case T_part:
427  libPartName = FROM_UTF8( CurText() );
428  NeedRIGHT();
429  break;
430 
431  case T_footprints:
432  // Read all fp elements (footprint filter item)
433  while( (token = NextTok()) != T_RIGHT )
434  {
435  if( token == T_LEFT )
436  token = NextTok();
437 
438  if( token != T_fp )
439  Expecting( T_fp );
440 
442  footprintFilters.Add( FROM_UTF8( CurText() ) );
443  NeedRIGHT();
444  }
445 
446  break;
447 
448  case T_aliases:
449  while( (token = NextTok()) != T_RIGHT )
450  {
451  if( token == T_LEFT )
452  token = NextTok();
453 
454  if( token != T_alias )
455  Expecting( T_alias );
456 
458  aliases.Add( FROM_UTF8( CurText() ) );
459  NeedRIGHT();
460  }
461  break;
462  default:
463  // Skip not used data (i.e all other tokens)
464  skipCurrent();
465  break;
466  }
467  }
468 
469  // Find all of the components that reference this component library part definition.
470  for( unsigned i = 0; i < m_netlist->GetCount(); i++ )
471  {
472  component = m_netlist->GetComponent( i );
473 
474  if( component->IsLibSource( libName, libPartName ) )
475  component->SetFootprintFilters( footprintFilters );
476 
477  for( unsigned jj = 0; jj < aliases.GetCount(); jj++ )
478  {
479  if( component->IsLibSource( libName, aliases[jj] ) )
480  component->SetFootprintFilters( footprintFilters );
481  }
482 
483  }
484 }
bool IsLibSource(const wxString &aLibrary, const wxString &aName) const
Definition: pcb_netlist.h:184
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
NETLIST * m_netlist
The netlist to parse into. Not owned.
void skipCurrent()
Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes ...
NL_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
void SetFootprintFilters(const wxArrayString &aFilterList)
Definition: pcb_netlist.h:170
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:353
NL_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
COMPONENT * GetComponent(unsigned aIndex)
Function GetComponent returns the COMPONENT at aIndex.
Definition: pcb_netlist.h:256
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
unsigned GetCount() const
Function GetCount.
Definition: pcb_netlist.h:247
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void KICAD_NETLIST_PARSER::parseNet ( )
private

Function parseNet Parses a section like (net (code 20) (name /PC-A0) (node (ref BUS1) (pin 62)) (node (ref U3) (pin 3)) (node (ref U9) (pin M6)))

and set the corresponding pads netnames

Definition at line 180 of file kicad_netlist_reader.cpp.

References COMPONENT::AddNet(), DSNLEXER::CurText(), FROM_UTF8(), GetChars(), NETLIST::GetComponentByReference(), LINE_READER::GetSource(), LINE_READER::Length(), LINE_READER::Line(), LINE_READER::LineNumber(), m_lineReader, m_netlist, name, DSNLEXER::NeedRIGHT(), NETLIST_LEXER::NeedSYMBOLorNUMBER(), NETLIST_LEXER::NextTok(), skipCurrent(), NL_T::T_code, DSN::T_LEFT, TLIB_T::T_name, NL_T::T_node, DSN::T_pin, NL_T::T_ref, DSN::T_RIGHT, THROW_PARSE_ERROR, and token.

Referenced by Parse().

181 {
182  /* Parses a section like
183  * (net (code 20) (name /PC-A0)
184  * (node (ref BUS1) (pin 62))
185  * (node (ref U3) (pin 3))
186  * (node (ref U9) (pin M6)))
187  */
188 
189  COMPONENT* component = NULL;
190  wxString code;
191  wxString name;
192  wxString reference;
193  wxString pin;
194  int nodecount = 0;
195 
196  // The token net was read, so the next data is (code <number>)
197  while( (token = NextTok()) != T_RIGHT )
198  {
199  if( token == T_LEFT )
200  token = NextTok();
201 
202  switch( token )
203  {
204  case T_code:
206  code = FROM_UTF8( CurText() );
207  NeedRIGHT();
208  break;
209 
210  case T_name:
212  name = FROM_UTF8( CurText() );
213  NeedRIGHT();
214 
215  if( name.IsEmpty() ) // Give a dummy net name like N-000109
216  name = wxT("N-00000") + code;
217 
218  break;
219 
220  case T_node:
221  while( (token = NextTok()) != T_RIGHT )
222  {
223  if( token == T_LEFT )
224  token = NextTok();
225 
226  switch( token )
227  {
228  case T_ref:
230  reference = FROM_UTF8( CurText() );
231  NeedRIGHT();
232  break;
233 
234  case T_pin:
236  pin = FROM_UTF8( CurText() );
237  NeedRIGHT();
238  break;
239 
240  default:
241  skipCurrent();
242  break;
243  }
244  }
245 
246 
247  component = m_netlist->GetComponentByReference( reference );
248 
249  // Cannot happen if the netlist is valid.
250  if( component == NULL )
251  {
252  wxString msg;
253  msg.Printf( _( "Cannot find component with reference \"%s\" in netlist." ),
254  GetChars( reference ) );
257  }
258 
259  component->AddNet( pin, name );
260  nodecount++;
261  break;
262 
263  default:
264  skipCurrent();
265  break;
266  }
267  }
268 }
virtual unsigned LineNumber() const
Function Line Number returns the line number of the last line read from this LINE_READER.
Definition: richio.h:159
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes...
Definition: macros.h:53
NETLIST * m_netlist
The netlist to parse into. Not owned.
void skipCurrent()
Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes ...
NL_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
LINE_READER * m_lineReader
The line reader used to parse the netlist. Not owned.
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
NL_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
unsigned Length() const
Function Length returns the number of bytes in the last line read from this LINE_READER.
Definition: richio.h:168
Class COMPONENT is used to store components and all of their related information found in a netlist...
Definition: pcb_netlist.h:83
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
virtual const wxString & GetSource() const
Function GetSource returns the name of the source of the lines in an abstract sense.
Definition: richio.h:130
void AddNet(const wxString &aPinName, const wxString &aNetName)
Definition: pcb_netlist.h:130
const char * name
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:401
COMPONENT * GetComponentByReference(const wxString &aReference)
Function GetComponentByReference returns a COMPONENT by aReference.
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
LINE_READER * DSNLEXER::PopReader ( )
inherited

Function PopReader deletes 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
LINE_READER* - is the one 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 204 of file dsnlexer.cpp.

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

Referenced by DSN::SPECCTRA_DB::LoadPCB(), DSN::SPECCTRA_DB::LoadSESSION(), and PCB_PARSER::SetLineReader().

205 {
206  LINE_READER* ret = 0;
207 
208  if( readerStack.size() )
209  {
210  ret = reader;
211  readerStack.pop_back();
212 
213  if( readerStack.size() )
214  {
215  reader = readerStack.back();
216  start = reader->Line();
217 
218  // force a new readLine() as first thing.
219  limit = start;
220  next = start;
221  }
222  else
223  {
224  reader = 0;
225  start = dummy;
226  limit = dummy;
227  }
228  }
229  return ret;
230 }
Class LINE_READER is an abstract class from which implementation specific LINE_READERs may be derived...
Definition: richio.h:81
const char * next
Definition: dsnlexer.h:85
const char * limit
Definition: dsnlexer.h:86
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
READER_STACK readerStack
all the LINE_READERs by pointer.
Definition: dsnlexer.h:91
LINE_READER * reader
no ownership. ownership is via readerStack, maybe, if iOwnReaders
Definition: dsnlexer.h:92
const char * start
Definition: dsnlexer.h:84
char dummy[1]
when there is no reader.
Definition: dsnlexer.h:87
NL_T::T NETLIST_LEXER::PrevTok ( )
inlineinherited

Function PrevTok returns whatever NextTok() returned the 2nd to last time it was called.

Definition at line 200 of file netlist_lexer.h.

References DSNLEXER::PrevTok().

201  {
202  return (NL_T::T) DSNLEXER::PrevTok();
203  }
int PrevTok()
Function PrevTok returns whatever NextTok() returned the 2nd to last time it was called.
Definition: dsnlexer.h:329
T
enum T contains all this lexer's tokens.
Definition: netlist_lexer.h:26
void DSNLEXER::PushReader ( LINE_READER aLineReader)
inherited

Function PushReader manages 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 192 of file dsnlexer.cpp.

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

Referenced by DSNLEXER::DSNLEXER(), DSN::SPECCTRA_DB::LoadPCB(), DSN::SPECCTRA_DB::LoadSESSION(), and PCB_PARSER::SetLineReader().

193 {
194  readerStack.push_back( aLineReader );
195  reader = aLineReader;
196  start = (const char*) (*reader);
197 
198  // force a new readLine() as first thing.
199  limit = start;
200  next = start;
201 }
const char * next
Definition: dsnlexer.h:85
const char * limit
Definition: dsnlexer.h:86
READER_STACK readerStack
all the LINE_READERs by pointer.
Definition: dsnlexer.h:91
LINE_READER * reader
no ownership. ownership is via readerStack, maybe, if iOwnReaders
Definition: dsnlexer.h:92
const char * start
Definition: dsnlexer.h:84
wxArrayString * DSNLEXER::ReadCommentLines ( )
inherited

Function ReadCommentLines checks 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
wxArrayString* - heap allocated block of comments, or NULL if none; caller owns the allocation and must delete if not NULL.

Definition at line 811 of file dsnlexer.cpp.

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

812 {
813  wxArrayString* ret = 0;
814  bool cmt_setting = SetCommentsAreTokens( true );
815  int tok = NextTok();
816 
817  if( tok == DSN_COMMENT )
818  {
819  ret = new wxArrayString();
820 
821  do
822  {
823  ret->Add( FromUTF8() );
824  }
825  while( ( tok = NextTok() ) == DSN_COMMENT );
826  }
827 
828  SetCommentsAreTokens( cmt_setting );
829 
830  return ret;
831 }
bool SetCommentsAreTokens(bool val)
Function SetCommentsAreTokens changes the handling of comments.
Definition: dsnlexer.h:372
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
int NextTok()
Function NextTok returns the next token found in the input file or DSN_EOF when reaching the end of f...
Definition: dsnlexer.cpp:540
int DSNLEXER::readLine ( )
inlineprotectedinherited

Definition at line 117 of file dsnlexer.h.

References LINE_READER::Length(), LINE_READER::Line(), LINE_READER::ReadLine(), and DSNLEXER::start.

Referenced by DSNLEXER::NextTok().

118  {
119  if( reader )
120  {
121  reader->ReadLine();
122 
123  unsigned len = reader->Length();
124 
125  // start may have changed in ReadLine(), which can resize and
126  // relocate reader's line buffer.
127  start = reader->Line();
128 
129  next = start;
130  limit = next + len;
131 
132  return len;
133  }
134  return 0;
135  }
const char * next
Definition: dsnlexer.h:85
const char * limit
Definition: dsnlexer.h:86
char * Line() const
Function Line returns a pointer to the last line that was read in.
Definition: richio.h:139
unsigned Length() const
Function Length returns the number of bytes in the last line read from this LINE_READER.
Definition: richio.h:168
LINE_READER * reader
no ownership. ownership is via readerStack, maybe, if iOwnReaders
Definition: dsnlexer.h:92
const char * start
Definition: dsnlexer.h:84
virtual char * ReadLine()=0
Function ReadLine reads a line of text into the buffer and increments the line number counter...
bool DSNLEXER::SetCommentsAreTokens ( bool  val)
inlineinherited

Function SetCommentsAreTokens changes the handling of comments.

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

Definition at line 372 of file dsnlexer.h.

References DSNLEXER::commentsAreTokens.

Referenced by DSNLEXER::ReadCommentLines().

373  {
374  bool old = commentsAreTokens;
375  commentsAreTokens = val;
376  return old;
377  }
bool commentsAreTokens
true if should return comments as tokens
Definition: dsnlexer.h:103
void KICAD_NETLIST_PARSER::SetLineReader ( LINE_READER aLineReader)
void KICAD_NETLIST_PARSER::SetNetlist ( NETLIST aNetlist)
inline

Definition at line 362 of file netlist_reader.h.

362 { m_netlist = aNetlist; }
NETLIST * m_netlist
The netlist to parse into. Not owned.
bool DSNLEXER::SetSpaceInQuotedTokens ( bool  val)
inlineinherited

Function SetSpaceInQuotedTokens changes the setting controlling whether a space in a quoted string is a terminator.

Parameters
valIf true, means

Definition at line 358 of file dsnlexer.h.

References DSNLEXER::space_in_quoted_tokens.

Referenced by DSN::SPECCTRA_DB::doPARSER().

359  {
360  bool old = space_in_quoted_tokens;
361  if( specctraMode )
363  return old;
364  }
bool space_in_quoted_tokens
blank spaces within quoted strings
Definition: dsnlexer.h:101
bool specctraMode
if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_...
Definition: dsnlexer.h:94
void DSNLEXER::SetSpecctraMode ( bool  aMode)
inherited

Function SetSpecctraMode changes the behavior of this lexer into or out of "specctra mode".

If specctra mode, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_in_quoted_tokens is functional else none of the above are true. The default mode is non-specctra mode, meaning: 1) stringDelimiter cannot be changed 2) Kicad quoting protocol is in effect 3) space_in_quoted_tokens is not functional

Definition at line 153 of file dsnlexer.cpp.

References DSNLEXER::space_in_quoted_tokens, DSNLEXER::specctraMode, and DSNLEXER::stringDelimiter.

Referenced by DSN::SPECCTRA_DB::SPECCTRA_DB().

154 {
155  specctraMode = aMode;
156  if( aMode )
157  {
158  // specctra mode defaults, some of which can still be changed in this mode.
159  space_in_quoted_tokens = true;
160  }
161  else
162  {
163  space_in_quoted_tokens = false;
164  stringDelimiter = '"';
165  }
166 }
bool space_in_quoted_tokens
blank spaces within quoted strings
Definition: dsnlexer.h:101
bool specctraMode
if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_...
Definition: dsnlexer.h:94
char stringDelimiter
Definition: dsnlexer.h:100
char DSNLEXER::SetStringDelimiter ( char  aStringDelimiter)
inlineinherited

Function SetStringDelimiter changes the string delimiter from the default " to some other character and returns the old value.

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

Definition at line 344 of file dsnlexer.h.

References DSNLEXER::stringDelimiter.

Referenced by DSN::SPECCTRA_DB::doFROMTO(), and DSN::SPECCTRA_DB::doPARSER().

345  {
346  int old = stringDelimiter;
347  if( specctraMode )
348  stringDelimiter = aStringDelimiter;
349  return old;
350  }
bool specctraMode
if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_...
Definition: dsnlexer.h:94
char stringDelimiter
Definition: dsnlexer.h:100
void KICAD_NETLIST_PARSER::skipCurrent ( )
private

Function skipCurrent Skip the current token level, i.e search for the RIGHT parenthesis which closes the current description.

Definition at line 64 of file kicad_netlist_reader.cpp.

References NETLIST_LEXER::NextTok(), DSN::T_EOF, DSN::T_LEFT, DSN::T_RIGHT, and token.

Referenced by Parse(), parseComponent(), parseLibPartList(), and parseNet().

65 {
66  int curr_level = 0;
67 
68  while( ( token = NextTok() ) != T_EOF )
69  {
70  if( token == T_LEFT )
71  curr_level--;
72 
73  if( token == T_RIGHT )
74  {
75  curr_level++;
76 
77  if( curr_level > 0 )
78  return;
79  }
80  }
81 }
NL_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
bool DSNLEXER::SyncLineReaderWith ( DSNLEXER aLexer)
inherited

Useable only for DSN lexers which share the same LINE_READER Synchronizes the pointers handling the data read by the LINE_READER Allows 2 DNSLEXER to share the same current line, when switching from a DNSLEXER to an other DNSLEXER.

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

Definition at line 169 of file dsnlexer.cpp.

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

Referenced by PCB_PARSER::parseSetup().

170 {
171  // Synchronize the pointers handling the data read by the LINE_READER
172  // only if aLexer shares the same LINE_READER, because only in this case
173  // the char buffer is be common
174 
175  if( reader != aLexer.reader )
176  return false;
177 
178  // We can synchronize the pointers which handle the data currently read
179  start = aLexer.start;
180  next = aLexer.next;
181  limit = aLexer.limit;
182 
183  // Sync these parameters is not mandatory, but could help
184  // for instance in debug
185  curText = aLexer.curText;
186  curOffset = aLexer.curOffset;
187 
188  return true;
189 }
int curOffset
offset within current line of the current token
Definition: dsnlexer.h:106
const char * next
Definition: dsnlexer.h:85
const char * limit
Definition: dsnlexer.h:86
LINE_READER * reader
no ownership. ownership is via readerStack, maybe, if iOwnReaders
Definition: dsnlexer.h:92
const char * start
Definition: dsnlexer.h:84
std::string curText
the text of the current token
Definition: dsnlexer.h:109
const char * DSNLEXER::Syntax ( int  aTok)
staticinherited

Definition at line 271 of file dsnlexer.cpp.

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 DSNLEXER::GetTokenText(), DIALOG_BOM_CFG_LEXER::TokenName(), TEMPLATE_FIELDNAMES_LEXER::TokenName(), FP_LIB_TABLE_LEXER::TokenName(), LIB_TABLE_LEXER::TokenName(), PCB_PLOT_PARAMS_LEXER::TokenName(), CMP_LIBRARY_LEXER::TokenName(), NETLIST_LEXER::TokenName(), PAGE_LAYOUT_READER_LEXER::TokenName(), PCB_LEXER::TokenName(), and SPECCTRA_LEXER::TokenName().

272 {
273  const char* ret;
274 
275  switch( aTok )
276  {
277  case DSN_NONE:
278  ret = "NONE";
279  break;
280  case DSN_STRING_QUOTE:
281  ret = "string_quote"; // a special DSN syntax token, see specctra spec.
282  break;
283  case DSN_QUOTE_DEF:
284  ret = "quoted text delimiter";
285  break;
286  case DSN_DASH:
287  ret = "-";
288  break;
289  case DSN_SYMBOL:
290  ret = "symbol";
291  break;
292  case DSN_NUMBER:
293  ret = "number";
294  break;
295  case DSN_RIGHT:
296  ret = ")";
297  break;
298  case DSN_LEFT:
299  ret = "(";
300  break;
301  case DSN_STRING:
302  ret = "quoted string";
303  break;
304  case DSN_EOF:
305  ret = "end of input";
306  break;
307  default:
308  ret = "???";
309  }
310 
311  return ret;
312 }
const char * NETLIST_LEXER::TokenName ( NL_T::T  aTok)
staticinherited

Function TokenName returns the name of the token in ASCII form.

Definition at line 61 of file netlist_keywords.cpp.

References DSNLEXER::Syntax().

Referenced by getTokenName().

62 {
63  const char* ret;
64 
65  if( aTok < 0 )
66  ret = DSNLEXER::Syntax( aTok );
67  else if( (unsigned) aTok < keyword_count )
68  ret = keywords[aTok].name;
69  else
70  ret = "token too big";
71 
72  return ret;
73 }
static const unsigned keyword_count
Definition: netlist_lexer.h:96
const char * name
unique keyword.
Definition: dsnlexer.h:42
static const KEYWORD keywords[]
Auto generated lexer keywords table and length:
Definition: netlist_lexer.h:95
static const char * Syntax(int aTok)
Definition: dsnlexer.cpp:271
void DSNLEXER::Unexpected ( int  aTok)
inherited

Function Unexpected throws 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 369 of file dsnlexer.cpp.

References DSNLEXER::CurLine(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), Format(), GetChars(), DSNLEXER::GetTokenString(), and THROW_PARSE_ERROR.

Referenced by DSN::SPECCTRA_DB::doANCESTOR(), DSN::SPECCTRA_DB::doBOUNDARY(), DSN::SPECCTRA_DB::doCLASS(), DSN::SPECCTRA_DB::doCLASS_CLASS(), DSN::SPECCTRA_DB::doCOMPONENT(), DSN::SPECCTRA_DB::doCONNECT(), DSN::SPECCTRA_DB::doCONTROL(), DSN::SPECCTRA_DB::doFROMTO(), DSN::SPECCTRA_DB::doGRID(), DSN::SPECCTRA_DB::doHISTORY(), DSN::SPECCTRA_DB::doIMAGE(), DSN::SPECCTRA_DB::doKEEPOUT(), DSN::SPECCTRA_DB::doLAYER(), DSN::SPECCTRA_DB::doLIBRARY(), DSN::SPECCTRA_DB::doNET(), DSN::SPECCTRA_DB::doNET_OUT(), DSN::SPECCTRA_DB::doNETWORK(), DSN::SPECCTRA_DB::doPADSTACK(), DSN::SPECCTRA_DB::doPARSER(), DSN::SPECCTRA_DB::doPCB(), DSN::SPECCTRA_DB::doPLACE(), DSN::SPECCTRA_DB::doPLACEMENT(), DSN::SPECCTRA_DB::doREGION(), DSN::SPECCTRA_DB::doROUTE(), DSN::SPECCTRA_DB::doRULE(), DSN::SPECCTRA_DB::doSESSION(), DSN::SPECCTRA_DB::doSHAPE(), DSN::SPECCTRA_DB::doSTRUCTURE(), DSN::SPECCTRA_DB::doSTRUCTURE_OUT(), DSN::SPECCTRA_DB::doSUPPLY_PIN(), DSN::SPECCTRA_DB::doTOKPROP(), DSN::SPECCTRA_DB::doTOPOLOGY(), DSN::SPECCTRA_DB::doVIA(), DSN::SPECCTRA_DB::doWAS_IS(), DSN::SPECCTRA_DB::doWINDOW(), DSN::SPECCTRA_DB::doWIRE(), DSN::SPECCTRA_DB::doWIRE_VIA(), DSN::SPECCTRA_DB::doWIRING(), PCB_PLOT_PARAMS_PARSER::Parse(), PAGE_LAYOUT_READER_PARSER::Parse(), FP_LIB_TABLE::Parse(), SYMBOL_LIB_TABLE::Parse(), TEMPLATES::Parse(), LIB_TABLE_ROW::Parse(), PAGE_LAYOUT_READER_PARSER::parseBitmap(), PAGE_LAYOUT_READER_PARSER::parseCoordinate(), PAGE_LAYOUT_READER_PARSER::parseGraphic(), BOM_CFG_READER_PARSER::parsePlugin(), PAGE_LAYOUT_READER_PARSER::parsePolygon(), PAGE_LAYOUT_READER_PARSER::parsePolyOutline(), PAGE_LAYOUT_READER_PARSER::parseSetup(), PAGE_LAYOUT_READER_PARSER::parseText(), PAGE_LAYOUT_READER_PARSER::readOption(), PAGE_LAYOUT_READER_PARSER::readPngdata(), Scan(), and scanList().

370 {
371  wxString errText = wxString::Format(
372  _("Unexpected '%s'"), GetChars( GetTokenString( aTok ) ) );
374 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
wxString GetTokenString(int aTok)
Function GetTokenString returns a quote wrapped wxString representation of a token value...
Definition: dsnlexer.cpp:334
void DSNLEXER::Unexpected ( const char *  aToken)
inherited

Function Unexpected throws 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 385 of file dsnlexer.cpp.

References DSNLEXER::CurLine(), DSNLEXER::CurLineNumber(), DSNLEXER::CurOffset(), DSNLEXER::CurSource(), Format(), GetChars(), and THROW_PARSE_ERROR.

386 {
387  wxString errText = wxString::Format(
388  _("Unexpected '%s'"), GetChars( wxString::FromUTF8( text ) ) );
390 }
const wxString & CurSource()
Function CurFilename returns the current LINE_READER source.
Definition: dsnlexer.h:528
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:133
int CurOffset()
Function CurOffset returns the byte offset within the current line, using a 1 based index...
Definition: dsnlexer.h:538
const char * CurLine()
Function CurLine returns the current line of text, from which the CurText() would return its token...
Definition: dsnlexer.h:517
static const wxChar * GetChars(const wxString &s)
Function GetChars returns a wxChar* to the actual wxChar* data within a wxString, and is helpful for ...
Definition: macros.h:92
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, CPTREE &aTree)
Function Format outputs a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:205
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507

Member Data Documentation

bool DSNLEXER::commentsAreTokens
protectedinherited

true if should return comments as tokens

Definition at line 103 of file dsnlexer.h.

Referenced by DSNLEXER::init(), DSNLEXER::NextTok(), and DSNLEXER::SetCommentsAreTokens().

int DSNLEXER::curOffset
protectedinherited

offset within current line of the current token

Definition at line 106 of file dsnlexer.h.

Referenced by DSNLEXER::init(), DSNLEXER::NextTok(), and DSNLEXER::SyncLineReaderWith().

std::string DSNLEXER::curText
protectedinherited

the text of the current token

Definition at line 109 of file dsnlexer.h.

Referenced by DSNLEXER::CurStr(), DSNLEXER::NextTok(), and DSNLEXER::SyncLineReaderWith().

int DSNLEXER::curTok
protectedinherited

the current token obtained on last NextTok()

Definition at line 108 of file dsnlexer.h.

Referenced by DSNLEXER::CurTok(), DSNLEXER::init(), and DSNLEXER::NextTok().

char DSNLEXER::dummy[1]
protectedinherited

when there is no reader.

Definition at line 87 of file dsnlexer.h.

Referenced by DSNLEXER::PopReader().

bool DSNLEXER::iOwnReaders
protectedinherited

on readerStack, should I delete them?

Definition at line 83 of file dsnlexer.h.

Referenced by DSN::SPECCTRA_DB::SPECCTRA_DB(), and DSNLEXER::~DSNLEXER().

KEYWORD_MAP DSNLEXER::keyword_hash
protectedinherited

fast, specialized "C string" hashtable

Definition at line 113 of file dsnlexer.h.

Referenced by DSNLEXER::findToken(), and DSNLEXER::init().

unsigned DSNLEXER::keywordCount
protectedinherited

count of keywords table

Definition at line 112 of file dsnlexer.h.

Referenced by DSNLEXER::GetTokenText(), and DSNLEXER::init().

const char* DSNLEXER::limit
protectedinherited
LINE_READER* KICAD_NETLIST_PARSER::m_lineReader
private

The line reader used to parse the netlist. Not owned.

Definition at line 298 of file netlist_reader.h.

Referenced by KICAD_NETLIST_PARSER(), and parseNet().

NETLIST* KICAD_NETLIST_PARSER::m_netlist
private

The netlist to parse into. Not owned.

Definition at line 299 of file netlist_reader.h.

Referenced by KICAD_NETLIST_PARSER(), parseComponent(), parseLibPartList(), and parseNet().

const char* DSNLEXER::next
protectedinherited
int DSNLEXER::prevTok
protectedinherited

curTok from previous NextTok() call.

Definition at line 105 of file dsnlexer.h.

Referenced by DSNLEXER::init(), DSNLEXER::NextTok(), and DSNLEXER::PrevTok().

LINE_READER* DSNLEXER::reader
protectedinherited

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

Definition at line 92 of file dsnlexer.h.

Referenced by PCB_PLOT_PARAMS_PARSER::GetReader(), DSNLEXER::PopReader(), DSNLEXER::PushReader(), and DSNLEXER::SyncLineReaderWith().

READER_STACK DSNLEXER::readerStack
protectedinherited

all the LINE_READERs by pointer.

Definition at line 91 of file dsnlexer.h.

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

bool DSNLEXER::space_in_quoted_tokens
protectedinherited

blank spaces within quoted strings

Definition at line 101 of file dsnlexer.h.

Referenced by DSNLEXER::init(), DSNLEXER::SetSpaceInQuotedTokens(), and DSNLEXER::SetSpecctraMode().

bool DSNLEXER::specctraMode
protectedinherited

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 94 of file dsnlexer.h.

Referenced by DSNLEXER::init(), DSNLEXER::NextTok(), and DSNLEXER::SetSpecctraMode().

const char* DSNLEXER::start
protectedinherited
char DSNLEXER::stringDelimiter
protectedinherited
NL_T::T KICAD_NETLIST_PARSER::token
private

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