KiCad PCB EDA Suite
PAGE_LAYOUT_READER_PARSER Class Reference

Class PAGE_LAYOUT_READER_PARSER holds data and functions pertinent to parsing a S-expression file for a WORKSHEET_LAYOUT. More...

Inheritance diagram for PAGE_LAYOUT_READER_PARSER:
PAGE_LAYOUT_READER_LEXER DSNLEXER

Public Member Functions

 PAGE_LAYOUT_READER_PARSER (const char *aLine, const wxString &aSource)
 
void Parse (WORKSHEET_LAYOUT *aLayout) throw ( PARSE_ERROR, IO_ERROR )
 
TB_READER_T::T NextTok () throw ( IO_ERROR )
 Function NextTok returns the next token found in the input file or T_EOF when reaching the end of file. More...
 
TB_READER_T::T NeedSYMBOL () throw ( IO_ERROR )
 Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(). More...
 
TB_READER_T::T NeedSYMBOLorNUMBER () throw ( IO_ERROR )
 Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool IsSymbol() or tok==T_NUMBER. More...
 
TB_READER_T::T CurTok ()
 Function CurTok returns whatever NextTok() returned the last time it was called. More...
 
TB_READER_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) throw ( IO_ERROR )
 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 () throw ( IO_ERROR )
 Function ReadCommentLines checks the next sequence of tokens and reads them into a wxArrayString if they are comments. More...
 
void Expecting (int aTok) throw ( IO_ERROR )
 Function Expecting throws an IO_ERROR exception with an input file specific error message. More...
 
void Expecting (const char *aTokenList) throw ( IO_ERROR )
 Function Expecting throws an IO_ERROR exception with an input file specific error message. More...
 
void Unexpected (int aTok) throw ( IO_ERROR )
 Function Unexpected throws an IO_ERROR exception with an input file specific error message. More...
 
void Unexpected (const char *aToken) throw ( IO_ERROR )
 Function Unexpected throws an IO_ERROR exception with an input file specific error message. More...
 
void Duplicate (int aTok) throw ( IO_ERROR )
 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 () throw ( IO_ERROR )
 Function NeedLEFT calls NextTok() and then verifies that the token read in is a DSN_LEFT. More...
 
void NeedRIGHT () throw ( IO_ERROR )
 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 (TB_READER_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 () throw ( IO_ERROR )
 
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

int parseInt (int aMin, int aMax)
 Function parseInt parses an integer and constrains it between two values. More...
 
double parseDouble ()
 Function parseDouble parses a double. More...
 
void parseSetup (WORKSHEET_LAYOUT *aLayout) throw ( IO_ERROR, PARSE_ERROR )
 
void parseGraphic (WORKSHEET_DATAITEM *aItem) throw ( IO_ERROR, PARSE_ERROR )
 parse a graphic item starting by "(line" or "(rect" and read parameters. More...
 
void parseText (WORKSHEET_DATAITEM_TEXT *aItem) throw ( IO_ERROR, PARSE_ERROR )
 parse a text item starting by "(tbtext" and read parameters. More...
 
void parsePolygon (WORKSHEET_DATAITEM_POLYPOLYGON *aItem) throw ( IO_ERROR, PARSE_ERROR )
 parse a polygon item starting by "( polygon" and read parameters. More...
 
void parsePolyOutline (WORKSHEET_DATAITEM_POLYPOLYGON *aItem) throw ( IO_ERROR, PARSE_ERROR )
 parse a list of corners starting by "( pts" and read coordinates. More...
 
void parseBitmap (WORKSHEET_DATAITEM_BITMAP *aItem) throw ( IO_ERROR, PARSE_ERROR )
 parse a bitmap item starting by "( bitmap" and read parameters. More...
 
void parseCoordinate (POINT_COORD &aCoord) throw ( IO_ERROR, PARSE_ERROR )
 
void readOption (WORKSHEET_DATAITEM *aItem) throw ( IO_ERROR, PARSE_ERROR )
 
void readPngdata (WORKSHEET_DATAITEM_BITMAP *aItem) throw ( IO_ERROR, PARSE_ERROR )
 

Detailed Description

Class PAGE_LAYOUT_READER_PARSER holds data and functions pertinent to parsing a S-expression file for a WORKSHEET_LAYOUT.

Definition at line 47 of file page_layout_reader.cpp.

Member Typedef Documentation

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

Definition at line 89 of file dsnlexer.h.

Constructor & Destructor Documentation

PAGE_LAYOUT_READER_PARSER::PAGE_LAYOUT_READER_PARSER ( const char *  aLine,
const wxString &  aSource 
)

Definition at line 111 of file page_layout_reader.cpp.

111  :
112  PAGE_LAYOUT_READER_LEXER( aLine, aSource )
113 {
114 }
PAGE_LAYOUT_READER_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 PCB_IO::Load(), DSNLEXER::NextTok(), SYMBOL_LIB_TABLE::Parse(), and FP_LIB_TABLE::Parse().

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 PCB_IO::Load(), DSNLEXER::NextTok(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), and KICAD_NETLIST_PARSER::parseComponent().

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 PCB_IO::Load(), DSNLEXER::NextTok(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), and KICAD_NETLIST_PARSER::parseComponent().

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 PCB_IO::Load(), DSNLEXER::NextTok(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), and KICAD_NETLIST_PARSER::parseComponent().

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.

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 PCAD2KICAD::LoadInputFile(), KICAD_NETLIST_PARSER::parseComponent(), PCB_PLOT_PARAMS_PARSER::parseDouble(), parseDouble(), PCB_PARSER::parseHex(), PCB_PLOT_PARAMS_PARSER::parseInt(), parseInt(), PCB_PARSER::parseInt(), KICAD_NETLIST_PARSER::parseLibPartList(), KICAD_NETLIST_PARSER::parseNet(), scanAtom(), and scanList().

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

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

Definition at line 199 of file page_layout_reader_lexer.h.

References DSNLEXER::CurTok().

200  {
201  return (TB_READER_T::T) DSNLEXER::CurTok();
202  }
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.
void DSNLEXER::Duplicate ( int  aTok)
throw (IO_ERROR
)
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 378 of file dsnlexer.cpp.

References Format(), and THROW_PARSE_ERROR.

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

379 {
380  wxString errText = wxString::Format(
381  _("%s is a duplicate"), GetTokenString( aTok ).GetData() );
383 }
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:335
void DSNLEXER::Expecting ( int  aTok)
throw (IO_ERROR
)
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 354 of file dsnlexer.cpp.

References Format(), GetChars(), and THROW_PARSE_ERROR.

Referenced by DSNLEXER::NeedLEFT(), DSNLEXER::NeedRIGHT(), DSNLEXER::NeedSYMBOL(), DSNLEXER::NeedSYMBOLorNUMBER(), SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), LIB_TABLE_ROW::Parse(), PCB_PLOT_PARAMS_PARSER::parseBool(), KICAD_NETLIST_PARSER::parseComponent(), PCB_PLOT_PARAMS_PARSER::parseDouble(), parseDouble(), PCB_PLOT_PARAMS_PARSER::parseInt(), parseInt(), and KICAD_NETLIST_PARSER::parseLibPartList().

355 {
356  wxString errText = wxString::Format(
357  _("Expecting '%s'"), GetChars( GetTokenString( aTok ) ) );
359 }
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:335
void DSNLEXER::Expecting ( const char *  aTokenList)
throw (IO_ERROR
)
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 362 of file dsnlexer.cpp.

References Format(), GetChars(), and THROW_PARSE_ERROR.

363 {
364  wxString errText = wxString::Format(
365  _("Expecting '%s'"), GetChars( wxString::FromUTF8( text ) ) );
367 }
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 261 of file dsnlexer.cpp.

References DSN_SYMBOL, and DSNLEXER::keyword_hash.

Referenced by DSNLEXER::NextTok().

262 {
263  KEYWORD_MAP::const_iterator it = keyword_hash.find( tok.c_str() );
264  if( it != keyword_hash.end() )
265  return it->second;
266 
267  return DSN_SYMBOL; // not a keyword, some arbitrary symbol.
268 }
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 SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), LIB_TABLE_ROW::Parse(), KICAD_NETLIST_PARSER::parseComponent(), 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
wxString DSNLEXER::GetTokenString ( int  aTok)
inherited

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

Definition at line 335 of file dsnlexer.cpp.

References DSNLEXER::GetTokenText().

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

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

Definition at line 316 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().

317 {
318  const char* ret;
319 
320  if( aTok < 0 )
321  {
322  return Syntax( aTok );
323  }
324  else if( (unsigned) aTok < keywordCount )
325  {
326  ret = keywords[aTok].name;
327  }
328  else
329  ret = "token too big";
330 
331  return ret;
332 }
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:272
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 345 of file dsnlexer.cpp.

References DSN_STRING, and DSN_SYMBOL.

Referenced by DSNLEXER::NeedSYMBOL(), and DSNLEXER::NeedSYMBOLorNUMBER().

346 {
347  // This is static and not inline to reduce code space.
348 
349  // if aTok is >= 0, then it is a coincidental match to a keyword.
350  return aTok==DSN_SYMBOL || aTok==DSN_STRING || aTok>=0;
351 }
void DSNLEXER::NeedLEFT ( )
throw (IO_ERROR
)
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 394 of file dsnlexer.cpp.

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

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

395 {
396  int tok = NextTok();
397  if( tok != DSN_LEFT )
398  Expecting( DSN_LEFT );
399 }
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:354
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:541
int DSNLEXER::NeedNUMBER ( const char *  aExpectation)
throw (IO_ERROR
)
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 428 of file dsnlexer.cpp.

References DSN_NUMBER, Format(), and THROW_PARSE_ERROR.

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

429 {
430  int tok = NextTok();
431  if( tok != DSN_NUMBER )
432  {
433  wxString errText = wxString::Format(
434  _("need a NUMBER for '%s'"), wxString::FromUTF8( aExpectation ).GetData() );
436  }
437  return tok;
438 }
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:541
int CurLineNumber()
Function CurLineNumber returns the current line number within my LINE_READER.
Definition: dsnlexer.h:507
void DSNLEXER::NeedRIGHT ( )
throw (IO_ERROR
)
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 402 of file dsnlexer.cpp.

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

Referenced by SYMBOL_LIB_TABLE::Parse(), FP_LIB_TABLE::Parse(), LIB_TABLE_ROW::Parse(), KICAD_NETLIST_PARSER::Parse(), KICAD_NETLIST_PARSER::parseComponent(), KICAD_NETLIST_PARSER::parseLibPartList(), and KICAD_NETLIST_PARSER::parseNet().

403 {
404  int tok = NextTok();
405  if( tok != DSN_RIGHT )
406  Expecting( DSN_RIGHT );
407 }
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:354
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:541
TB_READER_T::T PAGE_LAYOUT_READER_LEXER::NeedSYMBOL ( )
throw (IO_ERROR
)
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 177 of file page_layout_reader_lexer.h.

References DSNLEXER::NeedSYMBOL().

178  {
180  }
int NeedSYMBOL()
Function NeedSYMBOL calls NextTok() and then verifies that the token read in satisfies bool IsSymbol(...
Definition: dsnlexer.cpp:410
T
enum T contains all this lexer's tokens.
TB_READER_T::T PAGE_LAYOUT_READER_LEXER::NeedSYMBOLorNUMBER ( )
throw (IO_ERROR
)
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 190 of file page_layout_reader_lexer.h.

References DSNLEXER::NeedSYMBOLorNUMBER().

191  {
193  }
int NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
Definition: dsnlexer.cpp:419
T
enum T contains all this lexer's tokens.
TB_READER_T::T PAGE_LAYOUT_READER_LEXER::NextTok ( )
throw (IO_ERROR
)
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
TB_READER_T::T - the type of token found next.
Exceptions
IO_ERROR- only if the LINE_READER throws it.

Definition at line 164 of file page_layout_reader_lexer.h.

References DSNLEXER::NextTok().

Referenced by parseDouble(), and parseInt().

165  {
167  }
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:541
T
enum T contains all this lexer's tokens.
void PAGE_LAYOUT_READER_PARSER::Parse ( WORKSHEET_LAYOUT aLayout)
throw ( PARSE_ERROR,
IO_ERROR
)

Definition at line 117 of file page_layout_reader.cpp.

References TB_READER_T::T_bitmap, DSN::T_EOF, DSN::T_LEFT, TB_READER_T::T_line, TB_READER_T::T_page_layout, DSN::T_polygon, DSN::T_rect, DSN::T_RIGHT, TB_READER_T::T_setup, TB_READER_T::T_tbtext, WORKSHEET_DATAITEM::WS_RECT, and WORKSHEET_DATAITEM::WS_SEGMENT.

Referenced by WORKSHEET_LAYOUT::SetDefaultLayout(), and WORKSHEET_LAYOUT::SetPageLayout().

119 {
120  T token;
121  WORKSHEET_DATAITEM * item;
122 
123  LOCALE_IO toggle;
124 
125  while( ( token = NextTok() ) != T_RIGHT )
126  {
127  if( token == T_EOF)
128  break;
129 
130  if( token == T_LEFT )
131  token = NextTok();
132 
133  if( token == T_page_layout )
134  continue;
135 
136  switch( token )
137  {
138  case T_setup: // Defines default values for graphic items
139  parseSetup( aLayout );
140  break;
141 
142  case T_line:
144  parseGraphic( item );
145  aLayout->Append( item );
146  break;
147 
148  case T_rect:
150  parseGraphic( item );
151  aLayout->Append( item );
152  break;
153 
154  case T_polygon:
155  item = new WORKSHEET_DATAITEM_POLYPOLYGON();
157  aLayout->Append( item );
158  break;
159 
160  case T_bitmap:
161  item = new WORKSHEET_DATAITEM_BITMAP( NULL );
163  aLayout->Append( item );
164  break;
165 
166  case T_tbtext:
168  item = new WORKSHEET_DATAITEM_TEXT( FromUTF8() );
170  aLayout->Append( item );
171  break;
172 
173  default:
174  Unexpected( CurText() );
175  break;
176  }
177  }
178 }
Class LOCALE_IO is a class that can be instantiated within a scope in which you are expecting excepti...
Definition: common.h:166
void parseText(WORKSHEET_DATAITEM_TEXT *aItem)
parse a text item starting by "(tbtext" and read parameters.
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:370
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
void Append(WORKSHEET_DATAITEM *aItem)
Add an item to the list of items.
void parseBitmap(WORKSHEET_DATAITEM_BITMAP *aItem)
parse a bitmap item starting by "( bitmap" and read parameters.
TB_READER_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
void parseGraphic(WORKSHEET_DATAITEM *aItem)
parse a graphic item starting by "(line" or "(rect" and read parameters.
T
enum T contains all this lexer's tokens.
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void parsePolygon(WORKSHEET_DATAITEM_POLYPOLYGON *aItem)
parse a polygon item starting by "( polygon" and read parameters.
void parseSetup(WORKSHEET_LAYOUT *aLayout)
void PAGE_LAYOUT_READER_PARSER::parseBitmap ( WORKSHEET_DATAITEM_BITMAP aItem)
throw ( IO_ERROR,
PARSE_ERROR
)
private

parse a bitmap item starting by "( bitmap" and read parameters.

Definition at line 342 of file page_layout_reader.cpp.

References parseDouble(), parseInt(), DSN::T_EOF, TB_READER_T::T_incrx, TB_READER_T::T_incry, DSN::T_LEFT, TB_READER_T::T_linewidth, TLIB_T::T_name, TB_READER_T::T_option, TB_READER_T::T_pngdata, TB_READER_T::T_pos, TB_READER_T::T_repeat, DSN::T_RIGHT, and TB_READER_T::T_scale.

344 {
345  T token;
346  BITMAP_BASE* image = new BITMAP_BASE;
347  aItem->m_ImageBitmap = image;
348 
349  while( ( token = NextTok() ) != T_RIGHT )
350  {
351  if( token == T_EOF)
352  break;
353 
354  if( token == T_LEFT )
355  token = NextTok();
356 
357  switch( token )
358  {
359  case T_name:
361  aItem->m_Name = FromUTF8();
362  NeedRIGHT();
363  break;
364 
365  case T_pos:
366  parseCoordinate( aItem->m_Pos );
367  break;
368 
369  case T_repeat:
370  aItem->m_RepeatCount = parseInt( -1, 100 );
371  NeedRIGHT();
372  break;
373 
374  case T_incrx:
375  aItem->m_IncrementVector.x = parseDouble();
376  NeedRIGHT();
377  break;
378 
379  case T_incry:
380  aItem->m_IncrementVector.y = parseDouble();
381  NeedRIGHT();
382  break;
383 
384  case T_linewidth:
385  aItem->m_LineWidth = parseDouble();
386  NeedRIGHT();
387  break;
388 
389  case T_scale:
390  aItem->m_ImageBitmap->SetScale( parseDouble() );
391  NeedRIGHT();
392  break;
393 
394  case T_pngdata:
395  readPngdata( aItem );
396  break;
397 
398  case T_option:
399  readOption( aItem );
400  break;
401 
402  default:
403  Unexpected( CurText() );
404  break;
405  }
406  }
407 }
void parseCoordinate(POINT_COORD &aCoord)
int parseInt(int aMin, int aMax)
Function parseInt parses an integer and constrains it between two values.
void SetScale(double aScale)
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:370
void readPngdata(WORKSHEET_DATAITEM_BITMAP *aItem)
double parseDouble()
Function parseDouble parses a double.
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
This class handle bitmap images in KiCad.
TB_READER_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
T
enum T contains all this lexer's tokens.
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:402
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void readOption(WORKSHEET_DATAITEM *aItem)
void PAGE_LAYOUT_READER_PARSER::parseCoordinate ( POINT_COORD aCoord)
throw ( IO_ERROR,
PARSE_ERROR
)
private

Definition at line 705 of file page_layout_reader.cpp.

References LB_CORNER, LT_CORNER, parseDouble(), RB_CORNER, RT_CORNER, TB_READER_T::T_lbcorner, TB_READER_T::T_ltcorner, TB_READER_T::T_rbcorner, DSN::T_RIGHT, and TB_READER_T::T_rtcorner.

707 {
708  T token;
709 
710  aCoord.m_Pos.x = parseDouble();
711  aCoord.m_Pos.y = parseDouble();
712 
713  while( ( token = NextTok() ) != T_RIGHT )
714  {
715  switch( token )
716  {
717  case T_ltcorner:
718  aCoord.m_Anchor = LT_CORNER; // left top corner
719  break;
720 
721  case T_lbcorner:
722  aCoord.m_Anchor = LB_CORNER; // left bottom corner
723  break;
724 
725  case T_rbcorner:
726  aCoord.m_Anchor = RB_CORNER; // right bottom corner
727  break;
728 
729  case T_rtcorner:
730  aCoord.m_Anchor = RT_CORNER; // right top corner
731  break;
732 
733  default:
734  Unexpected( CurText() );
735  break;
736  }
737  }
738 }
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:370
double parseDouble()
Function parseDouble parses a double.
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
T
enum T contains all this lexer's tokens.
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
double PAGE_LAYOUT_READER_PARSER::parseDouble ( )
private

Function parseDouble parses a double.

Returns
double - the parsed double.

Definition at line 758 of file page_layout_reader.cpp.

References DSNLEXER::CurText(), DSNLEXER::Expecting(), PAGE_LAYOUT_READER_LEXER::NextTok(), and DSN::T_NUMBER.

759 {
760  T token = NextTok();
761 
762  if( token != T_NUMBER )
763  Expecting( T_NUMBER );
764 
765  double val = strtod( CurText(), NULL );
766 
767  return val;
768 }
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:354
T
enum T contains all this lexer's tokens.
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void PAGE_LAYOUT_READER_PARSER::parseGraphic ( WORKSHEET_DATAITEM aItem)
throw ( IO_ERROR,
PARSE_ERROR
)
private

parse a graphic item starting by "(line" or "(rect" and read parameters.

Definition at line 478 of file page_layout_reader.cpp.

References parseDouble(), parseInt(), DSN::T_comment, TLIB_T::T_end, DSN::T_EOF, TB_READER_T::T_incrx, TB_READER_T::T_incry, DSN::T_LEFT, TB_READER_T::T_linewidth, TLIB_T::T_name, TB_READER_T::T_option, TB_READER_T::T_repeat, DSN::T_RIGHT, and TLIB_T::T_start.

480 {
481  T token;
482 
483  while( ( token = NextTok() ) != T_RIGHT )
484  {
485  if( token == T_EOF)
486  break;
487 
488  if( token == T_LEFT )
489  token = NextTok();
490  else
491  {
492  // If an other token than T_LEFT is read here, this is an error
493  // however, due to a old bug in kicad, the token T_end can be found
494  // without T_LEFT in a very few .wks files (perhaps only one in a demo).
495  // So this ugly hack disables the error detection.
496  if( token != T_end )
497  Unexpected( CurText() );
498  }
499 
500  switch( token )
501  {
502  case T_comment:
504  aItem->m_Info = FromUTF8();
505  NeedRIGHT();
506  break;
507 
508  case T_option:
509  readOption( aItem );
510  break;
511 
512  case T_name:
514  aItem->m_Name = FromUTF8();
515  NeedRIGHT();
516  break;
517 
518  case T_start:
519  parseCoordinate( aItem->m_Pos );
520  break;
521 
522  case T_end:
523  parseCoordinate( aItem->m_End );
524  break;
525 
526  case T_repeat:
527  aItem->m_RepeatCount = parseInt( -1, 100 );
528  NeedRIGHT();
529  break;
530 
531  case T_incrx:
532  aItem->m_IncrementVector.x = parseDouble();
533  NeedRIGHT();
534  break;
535 
536  case T_incry:
537  aItem->m_IncrementVector.y = parseDouble();
538  NeedRIGHT();
539  break;
540 
541  case T_linewidth:
542  aItem->m_LineWidth = parseDouble();
543  NeedRIGHT();
544  break;
545 
546  default:
547  Unexpected( CurText() );
548  break;
549  }
550  }
551 }
void parseCoordinate(POINT_COORD &aCoord)
int parseInt(int aMin, int aMax)
Function parseInt parses an integer and constrains it between two values.
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:370
double parseDouble()
Function parseDouble parses a double.
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
TB_READER_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
T
enum T contains all this lexer's tokens.
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:402
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void readOption(WORKSHEET_DATAITEM *aItem)
int PAGE_LAYOUT_READER_PARSER::parseInt ( int  aMin,
int  aMax 
)
private

Function parseInt parses an integer and constrains it between two values.

Parameters
aMinis the smallest return value.
aMaxis the largest return value.
Returns
int - the parsed integer.

Definition at line 740 of file page_layout_reader.cpp.

References DSNLEXER::CurText(), DSNLEXER::Expecting(), PAGE_LAYOUT_READER_LEXER::NextTok(), and DSN::T_NUMBER.

741 {
742  T token = NextTok();
743 
744  if( token != T_NUMBER )
745  Expecting( T_NUMBER );
746 
747  int val = atoi( CurText() );
748 
749  if( val < aMin )
750  val = aMin;
751  else if( val > aMax )
752  val = aMax;
753 
754  return val;
755 }
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
void Expecting(int aTok)
Function Expecting throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:354
T
enum T contains all this lexer's tokens.
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void PAGE_LAYOUT_READER_PARSER::parsePolygon ( WORKSHEET_DATAITEM_POLYPOLYGON aItem)
throw ( IO_ERROR,
PARSE_ERROR
)
private

parse a polygon item starting by "( polygon" and read parameters.

the list of corners included in this description is read by parsePolyOutline

Definition at line 237 of file page_layout_reader.cpp.

References parseDouble(), parseInt(), DSN::T_comment, DSN::T_EOF, TB_READER_T::T_incrx, TB_READER_T::T_incry, DSN::T_LEFT, TB_READER_T::T_linewidth, TLIB_T::T_name, TB_READER_T::T_option, TB_READER_T::T_pos, TB_READER_T::T_pts, TB_READER_T::T_repeat, DSN::T_RIGHT, and DSN::T_rotate.

239 {
240  T token;
241 
242  while( ( token = NextTok() ) != T_RIGHT )
243  {
244  if( token == T_EOF)
245  break;
246 
247  if( token == T_LEFT )
248  token = NextTok();
249 
250  switch( token )
251  {
252  case T_comment:
254  aItem->m_Info = FromUTF8();
255  NeedRIGHT();
256  break;
257 
258  case T_pos:
259  parseCoordinate( aItem->m_Pos );
260  break;
261 
262  case T_name:
264  aItem->m_Name = FromUTF8();
265  NeedRIGHT();
266  break;
267 
268  case T_option:
269  readOption( aItem );
270  break;
271 
272  case T_pts:
273  parsePolyOutline( aItem );
274  aItem->CloseContour();
275  break;
276 
277  case T_rotate:
278  aItem->m_Orient = parseDouble();
279  NeedRIGHT();
280  break;
281 
282  case T_repeat:
283  aItem->m_RepeatCount = parseInt( -1, 100 );
284  NeedRIGHT();
285  break;
286 
287  case T_incrx:
288  aItem->m_IncrementVector.x = parseDouble();
289  NeedRIGHT();
290  break;
291 
292  case T_incry:
293  aItem->m_IncrementVector.y = parseDouble();
294  NeedRIGHT();
295  break;
296 
297  case T_linewidth:
298  aItem->m_LineWidth = parseDouble();
299  NeedRIGHT();
300  break;
301 
302  default:
303  Unexpected( CurText() );
304  break;
305  }
306  }
307 
308  aItem->SetBoundingBox();
309 }
void parseCoordinate(POINT_COORD &aCoord)
int parseInt(int aMin, int aMax)
Function parseInt parses an integer and constrains it between two values.
void SetBoundingBox()
calculate the bounding box of the set polygons
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:370
double parseDouble()
Function parseDouble parses a double.
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
TB_READER_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
void parsePolyOutline(WORKSHEET_DATAITEM_POLYPOLYGON *aItem)
parse a list of corners starting by "( pts" and read coordinates.
T
enum T contains all this lexer's tokens.
void CloseContour()
Closes the current contour, by storing the index of the last corner of the current polygon in m_polyI...
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:402
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void readOption(WORKSHEET_DATAITEM *aItem)
void PAGE_LAYOUT_READER_PARSER::parsePolyOutline ( WORKSHEET_DATAITEM_POLYPOLYGON aItem)
throw ( IO_ERROR,
PARSE_ERROR
)
private

parse a list of corners starting by "( pts" and read coordinates.

Definition at line 311 of file page_layout_reader.cpp.

References parseDouble(), DSN::T_EOF, DSN::T_LEFT, DSN::T_RIGHT, DSN::T_xy, VECTOR2< T >::x, and VECTOR2< T >::y.

313 {
314  DPOINT corner;
315  T token;
316 
317  while( ( token = NextTok() ) != T_RIGHT )
318  {
319  if( token == T_EOF)
320  break;
321 
322  if( token == T_LEFT )
323  token = NextTok();
324 
325  switch( token )
326  {
327  case T_xy:
328  corner.x = parseDouble();
329  corner.y = parseDouble();
330  aItem->AppendCorner( corner );
331  NeedRIGHT();
332  break;
333 
334  default:
335  Unexpected( CurText() );
336  break;
337  }
338  }
339 }
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:370
void AppendCorner(const DPOINT &aCorner)
add a corner in corner list
double parseDouble()
Function parseDouble parses a double.
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
T
enum T contains all this lexer's tokens.
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:402
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void PAGE_LAYOUT_READER_PARSER::parseSetup ( WORKSHEET_LAYOUT aLayout)
throw ( IO_ERROR,
PARSE_ERROR
)
private

Definition at line 180 of file page_layout_reader.cpp.

References WORKSHEET_DATAITEM::m_DefaultLineWidth, WORKSHEET_DATAITEM::m_DefaultTextSize, WORKSHEET_DATAITEM::m_DefaultTextThickness, parseDouble(), TB_READER_T::T_bottom_margin, DSN::T_EOF, DSN::T_LEFT, TB_READER_T::T_left_margin, TB_READER_T::T_linewidth, DSN::T_RIGHT, TB_READER_T::T_right_margin, TB_READER_T::T_textlinewidth, TB_READER_T::T_textsize, TB_READER_T::T_top_margin, VECTOR2< T >::x, and VECTOR2< T >::y.

182 {
183  T token;
184  while( ( token = NextTok() ) != T_RIGHT )
185  {
186  if( token == T_EOF)
187  break;
188 
189  switch( token )
190  {
191  case T_LEFT:
192  break;
193 
194  case T_linewidth:
196  NeedRIGHT();
197  break;
198 
199  case T_textsize:
202  NeedRIGHT();
203  break;
204 
205  case T_textlinewidth:
207  NeedRIGHT();
208  break;
209 
210  case T_left_margin:
211  aLayout->SetLeftMargin( parseDouble() );
212  NeedRIGHT();
213  break;
214 
215  case T_right_margin:
216  aLayout->SetRightMargin( parseDouble() );
217  NeedRIGHT();
218  break;
219 
220  case T_top_margin:
221  aLayout->SetTopMargin( parseDouble() );
222  NeedRIGHT();
223  break;
224 
225  case T_bottom_margin:
226  aLayout->SetBottomMargin( parseDouble() );
227  NeedRIGHT();
228  break;
229 
230  default:
231  Unexpected( CurText() );
232  break;
233  }
234  }
235 }
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:370
double parseDouble()
Function parseDouble parses a double.
void SetLeftMargin(double aMargin)
void SetTopMargin(double aMargin)
void SetBottomMargin(double aMargin)
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
static double m_DefaultTextThickness
T
enum T contains all this lexer's tokens.
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:402
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void SetRightMargin(double aMargin)
void PAGE_LAYOUT_READER_PARSER::parseText ( WORKSHEET_DATAITEM_TEXT aItem)
throw ( IO_ERROR,
PARSE_ERROR
)
private

parse a text item starting by "(tbtext" and read parameters.

Definition at line 554 of file page_layout_reader.cpp.

References GR_TEXT_HJUSTIFY_CENTER, GR_TEXT_HJUSTIFY_LEFT, GR_TEXT_HJUSTIFY_RIGHT, GR_TEXT_VJUSTIFY_BOTTOM, GR_TEXT_VJUSTIFY_CENTER, GR_TEXT_VJUSTIFY_TOP, parseDouble(), parseInt(), TB_READER_T::T_bold, DSN::T_bottom, TLIB_T::T_center, DSN::T_comment, DSN::T_EOF, TB_READER_T::T_font, TB_READER_T::T_incrlabel, TB_READER_T::T_incrx, TB_READER_T::T_incry, TB_READER_T::T_italic, TB_READER_T::T_justify, DSN::T_LEFT, TB_READER_T::T_left, TB_READER_T::T_linewidth, TB_READER_T::T_maxheight, TB_READER_T::T_maxlen, TLIB_T::T_name, TB_READER_T::T_option, TB_READER_T::T_pos, TB_READER_T::T_repeat, DSN::T_RIGHT, TB_READER_T::T_right, DSN::T_rotate, TB_READER_T::T_size, and DSN::T_top.

556 {
557  T token;
558 
559  while( ( token = NextTok() ) != T_RIGHT )
560  {
561  if( token == T_EOF)
562  break;
563 
564  if( token == T_LEFT )
565  token = NextTok();
566 
567  switch( token )
568  {
569  case T_comment:
571  aItem->m_Info = FromUTF8();
572  NeedRIGHT();
573  break;
574 
575  case T_option:
576  readOption( aItem );
577  break;
578 
579  case T_name:
581  aItem->m_Name = FromUTF8();
582  NeedRIGHT();
583  break;
584 
585  case T_pos:
586  parseCoordinate( aItem->m_Pos );
587  break;
588 
589  case T_repeat:
590  aItem->m_RepeatCount = parseInt( -1, 100 );
591  NeedRIGHT();
592  break;
593 
594  case T_incrx:
595  aItem->m_IncrementVector.x = parseDouble();
596  NeedRIGHT();
597  break;
598 
599  case T_incry:
600  aItem->m_IncrementVector.y = parseDouble();
601  NeedRIGHT();
602  break;
603 
604  case T_incrlabel:
605  aItem->m_IncrementLabel = parseInt(INT_MIN, INT_MAX);
606  NeedRIGHT();
607  break;
608 
609  case T_maxlen:
610  aItem->m_BoundingBoxSize.x = parseDouble();
611  NeedRIGHT();
612  break;
613 
614  case T_maxheight:
615  aItem->m_BoundingBoxSize.y = parseDouble();
616  NeedRIGHT();
617  break;
618 
619  case T_font:
620  while( ( token = NextTok() ) != T_RIGHT )
621  {
622  if( token == T_EOF)
623  break;
624 
625  switch( token )
626  {
627  case T_LEFT:
628  break;
629 
630  case T_bold:
631  aItem->SetBold( true );
632  break;
633 
634  case T_italic:
635  aItem->SetItalic( true );
636  break;
637 
638  case T_size:
639  aItem->m_TextSize.x = parseDouble();
640  aItem->m_TextSize.y = parseDouble();
641  NeedRIGHT();
642  break;
643 
644  case T_linewidth:
645  aItem->m_LineWidth = parseDouble();
646  NeedRIGHT();
647  break;
648 
649  default:
650  Unexpected( CurText() );
651  break;
652  }
653  }
654  break;
655 
656  case T_justify:
657  while( ( token = NextTok() ) != T_RIGHT )
658  {
659  if( token == T_EOF)
660  break;
661 
662  switch( token )
663  {
664  case T_center:
667  break;
668 
669  case T_left:
671  break;
672 
673  case T_right:
675  break;
676 
677  case T_top:
679  break;
680 
681  case T_bottom:
683  break;
684 
685  default:
686  Unexpected( CurText() );
687  break;
688  }
689  }
690  break;
691 
692  case T_rotate:
693  aItem->m_Orient = parseDouble();
694  NeedRIGHT();
695  break;
696 
697  default:
698  Unexpected( CurText() );
699  break;
700  }
701  }
702 }
void parseCoordinate(POINT_COORD &aCoord)
int parseInt(int aMin, int aMax)
Function parseInt parses an integer and constrains it between two values.
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:370
double parseDouble()
Function parseDouble parses a double.
wxString FromUTF8()
Function FromUTF8 returns the current token text as a wxString, assuming that the input byte stream i...
Definition: dsnlexer.h:498
void SetItalic(bool aState)
Function SetItalic Toggles on/off the italic option flag.
TB_READER_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
T
enum T contains all this lexer's tokens.
void SetBold(bool aState)
Function SetBold Toggles on/off the bold option flag.
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:402
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void readOption(WORKSHEET_DATAITEM *aItem)
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 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  limit = dummy;
228  }
229  }
230  return ret;
231 }
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
TB_READER_T::T PAGE_LAYOUT_READER_LEXER::PrevTok ( )
inlineinherited

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

Definition at line 208 of file page_layout_reader_lexer.h.

References DSNLEXER::PrevTok().

209  {
211  }
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.
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(), 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 ( )
throw (IO_ERROR
)
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 812 of file dsnlexer.cpp.

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

813 {
814  wxArrayString* ret = 0;
815  bool cmt_setting = SetCommentsAreTokens( true );
816  int tok = NextTok();
817 
818  if( tok == DSN_COMMENT )
819  {
820  ret = new wxArrayString();
821 
822  do
823  {
824  ret->Add( FromUTF8() );
825  }
826  while( ( tok = NextTok() ) == DSN_COMMENT );
827  }
828 
829  SetCommentsAreTokens( cmt_setting );
830 
831  return ret;
832 }
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:541
int DSNLEXER::readLine ( )
throw (IO_ERROR
)
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...
void PAGE_LAYOUT_READER_PARSER::readOption ( WORKSHEET_DATAITEM aItem)
throw ( IO_ERROR,
PARSE_ERROR
)
private

Definition at line 450 of file page_layout_reader.cpp.

References DSN::T_EOF, TB_READER_T::T_notonpage1, TB_READER_T::T_page1only, and DSN::T_RIGHT.

452 {
453  T token;
454 
455  while( ( token = NextTok() ) != T_RIGHT )
456  {
457  if( token == T_EOF)
458  break;
459 
460  switch( token )
461  {
462  case T_page1only:
463  aItem->SetPage1Option( 1 );
464  break;
465 
466  case T_notonpage1:
467  aItem->SetPage1Option( -1 );
468  break;
469 
470  default:
471  Unexpected( CurText() );
472  break;
473  }
474  }
475 }
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:370
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
T
enum T contains all this lexer's tokens.
void SetPage1Option(int aChoice)
Set the option for page 1.
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
void PAGE_LAYOUT_READER_PARSER::readPngdata ( WORKSHEET_DATAITEM_BITMAP aItem)
throw ( IO_ERROR,
PARSE_ERROR
)
private

Definition at line 409 of file page_layout_reader.cpp.

References TB_READER_T::T_data, DSN::T_EOF, DSN::T_LEFT, and DSN::T_RIGHT.

411 {
412  std::string tmp;
413  T token;
414 
415  while( ( token = NextTok() ) != T_RIGHT )
416  {
417  if( token == T_EOF)
418  break;
419 
420  if( token == T_LEFT )
421  token = NextTok();
422 
423  switch( token )
424  {
425  case T_data:
427  tmp += CurStr();
428  tmp += "\n";
429  NeedRIGHT();
430  break;
431 
432  default:
433  Unexpected( CurText() );
434  break;
435  }
436  }
437 
438  tmp += "EndData";
439 
440  wxString msg;
441  STRING_LINE_READER str_reader( tmp, wxT("Png kicad_wks data") );
442 
443  if( ! aItem->m_ImageBitmap->LoadData( str_reader, msg ) )
444  {
445  wxLogMessage(msg);
446  }
447 }
void Unexpected(int aTok)
Function Unexpected throws an IO_ERROR exception with an input file specific error message...
Definition: dsnlexer.cpp:370
const std::string & CurStr()
Function CurStr returns a reference to current token in std::string form.
Definition: dsnlexer.h:488
TB_READER_T::T NeedSYMBOLorNUMBER()
Function NeedSYMBOLorNUMBER calls NextTok() and then verifies that the token read in satisfies bool I...
TB_READER_T::T NextTok()
Function NextTok returns the next token found in the input file or T_EOF when reaching the end of fil...
bool LoadData(LINE_READER &aLine, wxString &aErrorMsg)
Load an image data saved by SaveData (png, in Hexadecimal form)
T
enum T contains all this lexer's tokens.
void NeedRIGHT()
Function NeedRIGHT calls NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:402
Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
const char * CurText()
Function CurText returns a pointer to the current token's text.
Definition: dsnlexer.h:479
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
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.

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.

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
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 272 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().

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

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

Definition at line 69 of file page_layout_reader_keywords.cpp.

References DSNLEXER::Syntax().

Referenced by getTokenName().

70 {
71  const char* ret;
72 
73  if( aTok < 0 )
74  ret = DSNLEXER::Syntax( aTok );
75  else if( (unsigned) aTok < keyword_count )
76  ret = keywords[aTok].name;
77  else
78  ret = "token too big";
79 
80  return ret;
81 }
static const KEYWORD keywords[]
Auto generated lexer keywords table and length:
static const unsigned keyword_count
const char * name
unique keyword.
Definition: dsnlexer.h:42
static const char * Syntax(int aTok)
Definition: dsnlexer.cpp:272
void DSNLEXER::Unexpected ( int  aTok)
throw (IO_ERROR
)
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 370 of file dsnlexer.cpp.

References Format(), GetChars(), and THROW_PARSE_ERROR.

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

371 {
372  wxString errText = wxString::Format(
373  _("Unexpected '%s'"), GetChars( GetTokenString( aTok ) ) );
375 }
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:335
void DSNLEXER::Unexpected ( const char *  aToken)
throw (IO_ERROR
)
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 386 of file dsnlexer.cpp.

References Format(), GetChars(), and THROW_PARSE_ERROR.

387 {
388  wxString errText = wxString::Format(
389  _("Unexpected '%s'"), GetChars( wxString::FromUTF8( text ) ) );
391 }
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
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

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