KiCad PCB EDA Suite
dsnlexer.cpp
Go to the documentation of this file.
1 
2 /*
3  * This program source code file is part of KiCad, a free EDA CAD application.
4  *
5  * Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
6  * Copyright (C) 2007-2020 KiCad Developers, see AUTHORS.txt for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
26 
27 #include <cstdarg>
28 #include <cstdio>
29 #include <cstdlib> // bsearch()
30 #include <cctype>
31 
32 #include <dsnlexer.h>
33 #include <wx/translation.h>
34 
35 #define FMT_CLIPBOARD _( "clipboard" )
36 
37 
38 //-----<DSNLEXER>-------------------------------------------------------------
39 
41 {
42  curTok = DSN_NONE;
43  prevTok = DSN_NONE;
44 
45  stringDelimiter = '"';
46 
47  specctraMode = false;
48  space_in_quoted_tokens = false;
49  commentsAreTokens = false;
50 
51  curOffset = 0;
52 
53 #if 1
54  if( keywordCount > 11 )
55  {
56  // resize the hashtable bucket count
57  keyword_hash.reserve( keywordCount );
58  }
59 
60  // fill the specialized "C string" hashtable from keywords[]
61  const KEYWORD* it = keywords;
62  const KEYWORD* end = it + keywordCount;
63 
64  for( ; it < end; ++it )
65  {
66  keyword_hash[it->name] = it->token;
67  }
68 #endif
69 }
70 
71 
72 DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
73  FILE* aFile, const wxString& aFilename ) :
74  iOwnReaders( true ),
75  start( nullptr ),
76  next( nullptr ),
77  limit( nullptr ),
78  reader( nullptr ),
79  keywords( aKeywordTable ),
80  keywordCount( aKeywordCount )
81 {
82  FILE_LINE_READER* fileReader = new FILE_LINE_READER( aFile, aFilename );
83  PushReader( fileReader );
84  init();
85 }
86 
87 
88 DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
89  const std::string& aClipboardTxt, const wxString& aSource ) :
90  iOwnReaders( true ),
91  start( nullptr ),
92  next( nullptr ),
93  limit( nullptr ),
94  reader( nullptr ),
95  keywords( aKeywordTable ),
96  keywordCount( aKeywordCount )
97 {
98  STRING_LINE_READER* stringReader = new STRING_LINE_READER( aClipboardTxt, aSource.IsEmpty() ?
99  wxString( FMT_CLIPBOARD ) : aSource );
100  PushReader( stringReader );
101  init();
102 }
103 
104 
105 DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
106  LINE_READER* aLineReader ) :
107  iOwnReaders( false ),
108  start( nullptr ),
109  next( nullptr ),
110  limit( nullptr ),
111  reader( nullptr ),
112  keywords( aKeywordTable ),
113  keywordCount( aKeywordCount )
114 {
115  if( aLineReader )
116  PushReader( aLineReader );
117  init();
118 }
119 
120 
121 static const KEYWORD empty_keywords[1] = {};
122 
123 DSNLEXER::DSNLEXER( const std::string& aSExpression, const wxString& aSource ) :
124  iOwnReaders( true ),
125  start( nullptr ),
126  next( nullptr ),
127  limit( nullptr ),
128  reader( nullptr ),
129  keywords( empty_keywords ),
130  keywordCount( 0 )
131 {
132  STRING_LINE_READER* stringReader = new STRING_LINE_READER( aSExpression, aSource.IsEmpty() ?
133  wxString( FMT_CLIPBOARD ) : aSource );
134  PushReader( stringReader );
135  init();
136 }
137 
138 
140 {
141  if( iOwnReaders )
142  {
143  // delete the LINE_READERs from the stack, since I own them.
144  for( READER_STACK::iterator it = readerStack.begin(); it!=readerStack.end(); ++it )
145  delete *it;
146  }
147 }
148 
149 void DSNLEXER::SetSpecctraMode( bool aMode )
150 {
151  specctraMode = aMode;
152  if( aMode )
153  {
154  // specctra mode defaults, some of which can still be changed in this mode.
155  space_in_quoted_tokens = true;
156  }
157  else
158  {
159  space_in_quoted_tokens = false;
160  stringDelimiter = '"';
161  }
162 }
163 
164 
166 {
167  // Synchronize the pointers handling the data read by the LINE_READER
168  // only if aLexer shares the same LINE_READER, because only in this case
169  // the char buffer is be common
170 
171  if( reader != aLexer.reader )
172  return false;
173 
174  // We can synchronize the pointers which handle the data currently read
175  start = aLexer.start;
176  next = aLexer.next;
177  limit = aLexer.limit;
178 
179  // Sync these parameters is not mandatory, but could help
180  // for instance in debug
181  curText = aLexer.curText;
182  curOffset = aLexer.curOffset;
183 
184  return true;
185 }
186 
187 
188 void DSNLEXER::PushReader( LINE_READER* aLineReader )
189 {
190  readerStack.push_back( aLineReader );
191  reader = aLineReader;
192  start = (const char*) (*reader);
193 
194  // force a new readLine() as first thing.
195  limit = start;
196  next = start;
197 }
198 
199 
201 {
202  LINE_READER* ret = nullptr;
203 
204  if( readerStack.size() )
205  {
206  ret = reader;
207  readerStack.pop_back();
208 
209  if( readerStack.size() )
210  {
211  reader = readerStack.back();
212  start = reader->Line();
213 
214  // force a new readLine() as first thing.
215  limit = start;
216  next = start;
217  }
218  else
219  {
220  reader = nullptr;
221  start = dummy;
222  limit = dummy;
223  }
224  }
225  return ret;
226 }
227 
228 
229 int DSNLEXER::findToken( const std::string& tok ) const
230 {
231  KEYWORD_MAP::const_iterator it = keyword_hash.find( tok.c_str() );
232 
233  if( it != keyword_hash.end() )
234  return it->second;
235 
236  return DSN_SYMBOL; // not a keyword, some arbitrary symbol.
237 }
238 
239 
240 const char* DSNLEXER::Syntax( int aTok )
241 {
242  const char* ret;
243 
244  switch( aTok )
245  {
246  case DSN_NONE:
247  ret = "NONE";
248  break;
249  case DSN_STRING_QUOTE:
250  ret = "string_quote"; // a special DSN syntax token, see specctra spec.
251  break;
252  case DSN_QUOTE_DEF:
253  ret = "quoted text delimiter";
254  break;
255  case DSN_DASH:
256  ret = "-";
257  break;
258  case DSN_SYMBOL:
259  ret = "symbol";
260  break;
261  case DSN_NUMBER:
262  ret = "number";
263  break;
264  case DSN_RIGHT:
265  ret = ")";
266  break;
267  case DSN_LEFT:
268  ret = "(";
269  break;
270  case DSN_STRING:
271  ret = "quoted string";
272  break;
273  case DSN_EOF:
274  ret = "end of input";
275  break;
276  default:
277  ret = "???";
278  }
279 
280  return ret;
281 }
282 
283 
284 const char* DSNLEXER::GetTokenText( int aTok ) const
285 {
286  const char* ret;
287 
288  if( aTok < 0 )
289  {
290  return Syntax( aTok );
291  }
292  else if( (unsigned) aTok < keywordCount )
293  {
294  ret = keywords[aTok].name;
295  }
296  else
297  ret = "token too big";
298 
299  return ret;
300 }
301 
302 
303 wxString DSNLEXER::GetTokenString( int aTok ) const
304 {
305  wxString ret;
306 
307  ret << wxT("'") << wxString::FromUTF8( GetTokenText(aTok) ) << wxT("'");
308 
309  return ret;
310 }
311 
312 
313 bool DSNLEXER::IsSymbol( int aTok )
314 {
315  // This is static and not inline to reduce code space.
316 
317  // if aTok is >= 0, then it is a coincidental match to a keyword.
318  return aTok == DSN_SYMBOL || aTok == DSN_STRING || aTok >= 0;
319 }
320 
321 
322 void DSNLEXER::Expecting( int aTok ) const
323 {
324  wxString errText = wxString::Format(
325  _( "Expecting %s" ), GetTokenString( aTok ) );
327 }
328 
329 
330 void DSNLEXER::Expecting( const char* text ) const
331 {
332  wxString errText = wxString::Format(
333  _( "Expecting '%s'" ), wxString::FromUTF8( text ) );
335 }
336 
337 
338 void DSNLEXER::Unexpected( int aTok ) const
339 {
340  wxString errText = wxString::Format(
341  _( "Unexpected %s" ), GetTokenString( aTok ) );
343 }
344 
345 
346 void DSNLEXER::Duplicate( int aTok )
347 {
348  wxString errText = wxString::Format(
349  _("%s is a duplicate"), GetTokenString( aTok ).GetData() );
351 }
352 
353 
354 void DSNLEXER::Unexpected( const char* text ) const
355 {
356  wxString errText = wxString::Format(
357  _( "Unexpected '%s'" ), wxString::FromUTF8( text ) );
359 }
360 
361 
363 {
364  int tok = NextTok();
365  if( tok != DSN_LEFT )
366  Expecting( DSN_LEFT );
367 }
368 
369 
371 {
372  int tok = NextTok();
373 
374  if( tok != DSN_RIGHT )
375  Expecting( DSN_RIGHT );
376 }
377 
378 
380 {
381  int tok = NextTok();
382 
383  if( !IsSymbol( tok ) )
385 
386  return tok;
387 }
388 
389 
391 {
392  int tok = NextTok();
393 
394  if( !IsSymbol( tok ) && tok!=DSN_NUMBER )
395  Expecting( "a symbol or number" );
396 
397  return tok;
398 }
399 
400 
401 int DSNLEXER::NeedNUMBER( const char* aExpectation )
402 {
403  int tok = NextTok();
404 
405  if( tok != DSN_NUMBER )
406  {
407  wxString errText = wxString::Format( _( "need a number for '%s'" ),
408  wxString::FromUTF8( aExpectation ).GetData() );
410  }
411 
412  return tok;
413 }
414 
415 
422 static bool isSpace( char cc )
423 {
424  // cc is signed, so it is often negative.
425  // Treat negative as large positive to exclude rapidly.
426  if( (unsigned char) cc <= ' ' )
427  {
428  switch( (unsigned char) cc )
429  {
430  case ' ':
431  case '\n':
432  case '\r':
433  case '\t':
434  case '\0': // PCAD s-expression files have this.
435  return true;
436  }
437  }
438 
439  return false;
440 }
441 
442 
443 inline bool isDigit( char cc )
444 {
445  return '0' <= cc && cc <= '9';
446 }
447 
448 
450 inline bool isSep( char cc )
451 {
452  return isSpace( cc ) || cc=='(' || cc==')';
453 }
454 
455 
465 static bool isNumber( const char* cp, const char* limit )
466 {
467  // regex for a float: "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?" i.e. any number,
468  // code traversal manually here:
469 
470  bool sawNumber = false;
471 
472  if( cp < limit && ( *cp=='-' || *cp=='+' ) )
473  ++cp;
474 
475  while( cp < limit && isDigit( *cp ) )
476  {
477  ++cp;
478  sawNumber = true;
479  }
480 
481  if( cp < limit && *cp == '.' )
482  {
483  ++cp;
484 
485  while( cp < limit && isDigit( *cp ) )
486  {
487  ++cp;
488  sawNumber = true;
489  }
490  }
491 
492  if( sawNumber )
493  {
494  if( cp < limit && ( *cp=='E' || *cp=='e' ) )
495  {
496  ++cp;
497 
498  sawNumber = false; // exponent mandates at least one digit thereafter.
499 
500  if( cp < limit && ( *cp=='-' || *cp=='+' ) )
501  ++cp;
502 
503  while( cp < limit && isDigit( *cp ) )
504  {
505  ++cp;
506  sawNumber = true;
507  }
508  }
509  }
510 
511  return sawNumber && cp==limit;
512 }
513 
514 
516 {
517  const char* cur = next;
518  const char* head = cur;
519 
520  prevTok = curTok;
521 
522  if( curTok == DSN_EOF )
523  goto exit;
524 
525  if( cur >= limit )
526  {
527 L_read:
528  // blank lines are returned as "\n" and will have a len of 1.
529  // EOF will have a len of 0 and so is detectable.
530  int len = readLine();
531 
532  if( len == 0 )
533  {
534  cur = start; // after readLine(), since start can change, set cur offset to start
535  curTok = DSN_EOF;
536  goto exit;
537  }
538 
539  cur = start; // after readLine() since start can change.
540 
541  // skip leading whitespace
542  while( cur < limit && isSpace( *cur ) )
543  ++cur;
544 
545  // If the first non-blank character is #, this line is a comment.
546  // Comments cannot follow any other token on the same line.
547  if( cur<limit && *cur=='#' )
548  {
549  if( commentsAreTokens )
550  {
551  // Grab the entire current line [excluding end of line char(s)] as the
552  // current token. The '#' character may not be at offset zero.
553 
554  while( limit[-1] == '\n' || limit[-1] == '\r' )
555  --limit;
556 
557  curText.clear();
558  curText.append( start, limit );
559 
560  cur = start; // ensure a good curOffset below
562  head = limit; // do a readLine() on next call in here.
563  goto exit;
564  }
565  else
566  {
567  goto L_read;
568  }
569  }
570  }
571  else
572  {
573  // skip leading whitespace
574  while( cur < limit && isSpace( *cur ) )
575  ++cur;
576  }
577 
578  if( cur >= limit )
579  goto L_read;
580 
581  if( *cur == '(' )
582  {
583  curText = *cur;
584  curTok = DSN_LEFT;
585  head = cur+1;
586  goto exit;
587  }
588 
589  if( *cur == ')' )
590  {
591  curText = *cur;
592  curTok = DSN_RIGHT;
593  head = cur+1;
594  goto exit;
595  }
596 
597  // Non-specctraMode, understands and deciphers escaped \, \r, \n, and \".
598  // Strips off leading and trailing double quotes
599  if( !specctraMode )
600  {
601  // a quoted string, will return DSN_STRING
602  if( *cur == stringDelimiter )
603  {
604  // copy the token, character by character so we can remove doubled up quotes.
605  curText.clear();
606 
607  ++cur; // skip over the leading delimiter, which is always " in non-specctraMode
608 
609  head = cur;
610 
611  while( head<limit )
612  {
613  // ESCAPE SEQUENCES:
614  if( *head =='\\' )
615  {
616  char tbuf[8];
617  char c;
618  int i;
619 
620  if( ++head >= limit )
621  break; // throw exception at L_unterminated
622 
623  switch( *head++ )
624  {
625  case '"':
626  case '\\': c = head[-1]; break;
627  case 'a': c = '\x07'; break;
628  case 'b': c = '\x08'; break;
629  case 'f': c = '\x0c'; break;
630  case 'n': c = '\n'; break;
631  case 'r': c = '\r'; break;
632  case 't': c = '\x09'; break;
633  case 'v': c = '\x0b'; break;
634 
635  case 'x': // 1 or 2 byte hex escape sequence
636  for( i = 0; i < 2; ++i )
637  {
638  if( !isxdigit( head[i] ) )
639  break;
640 
641  tbuf[i] = head[i];
642  }
643 
644  tbuf[i] = '\0';
645 
646  if( i > 0 )
647  c = (char) strtoul( tbuf, nullptr, 16 );
648  else
649  c = 'x'; // a goofed hex escape sequence, interpret as 'x'
650 
651  head += i;
652  break;
653 
654  default: // 1-3 byte octal escape sequence
655  --head;
656 
657  for( i=0; i<3; ++i )
658  {
659  if( head[i] < '0' || head[i] > '7' )
660  break;
661 
662  tbuf[i] = head[i];
663  }
664 
665  tbuf[i] = '\0';
666 
667  if( i > 0 )
668  c = (char) strtoul( tbuf, nullptr, 8 );
669  else
670  c = '\\'; // a goofed octal escape sequence, interpret as '\'
671 
672  head += i;
673  break;
674  }
675 
676  curText += c;
677  }
678 
679  else if( *head == '"' ) // end of the non-specctraMode DSN_STRING
680  {
681  curTok = DSN_STRING;
682  ++head; // omit this trailing double quote
683  goto exit;
684  }
685 
686  else
687  curText += *head++;
688 
689  } // while
690 
691  // L_unterminated:
692  wxString errtxt( _( "Un-terminated delimited string" ) );
694  cur - start + curText.length() );
695  }
696  }
697  else // is specctraMode, tests in this block should not occur in KiCad mode.
698  {
699  /* get the dash out of a <pin_reference> which is embedded for example
700  like: U2-14 or "U2"-"14"
701  This is detectable by a non-space immediately preceding the dash.
702  */
703  if( *cur == '-' && cur>start && !isSpace( cur[-1] ) )
704  {
705  curText = '-';
706  curTok = DSN_DASH;
707  head = cur+1;
708  goto exit;
709  }
710 
711  // switching the string_quote character
712  if( prevTok == DSN_STRING_QUOTE )
713  {
714  static const wxString errtxt( _("String delimiter must be a single character of "
715  "', \", or $") );
716 
717  char cc = *cur;
718  switch( cc )
719  {
720  case '\'':
721  case '$':
722  case '"':
723  break;
724  default:
726  }
727 
728  curText = cc;
729 
730  head = cur+1;
731 
732  if( head<limit && !isSep( *head ) )
733  {
735  }
736 
738  goto exit;
739  }
740 
741  // specctraMode DSN_STRING
742  if( *cur == stringDelimiter )
743  {
744  ++cur; // skip over the leading delimiter: ",', or $
745 
746  head = cur;
747 
748  while( head<limit && !isStringTerminator( *head ) )
749  ++head;
750 
751  if( head >= limit )
752  {
753  wxString errtxt( _( "Un-terminated delimited string" ) );
755  }
756 
757  curText.clear();
758  curText.append( cur, head );
759 
760  ++head; // skip over the trailing delimiter
761 
762  curTok = DSN_STRING;
763  goto exit;
764  }
765  } // specctraMode
766 
767  // non-quoted token, read it into curText.
768  curText.clear();
769 
770  head = cur;
771  while( head<limit && !isSep( *head ) )
772  curText += *head++;
773 
774  if( isNumber( curText.c_str(), curText.c_str() + curText.size() ) )
775  {
776  curTok = DSN_NUMBER;
777  goto exit;
778  }
779 
780  if( specctraMode && curText == "string_quote" )
781  {
783  goto exit;
784  }
785 
786  curTok = findToken( curText );
787 
788 exit: // single point of exit, no returns elsewhere please.
789 
790  curOffset = cur - start;
791 
792  next = head;
793 
794  return curTok;
795 }
796 
797 
799 {
800  wxArrayString* ret = nullptr;
801  bool cmt_setting = SetCommentsAreTokens( true );
802  int tok = NextTok();
803 
804  if( tok == DSN_COMMENT )
805  {
806  ret = new wxArrayString();
807 
808  do
809  {
810  ret->Add( FromUTF8() );
811  }
812  while( ( tok = NextTok() ) == DSN_COMMENT );
813  }
814 
815  SetCommentsAreTokens( cmt_setting );
816 
817  return ret;
818 }
int curOffset
offset within current line of the current token
Definition: dsnlexer.h:519
CITER next(CITER it)
Definition: ptree.cpp:126
int CurLineNumber() const
Return the current line number within my LINE_READER.
Definition: dsnlexer.h:416
int NeedNUMBER(const char *aExpectation)
Call NextTok() and then verifies that the token read is type DSN_NUMBER.
Definition: dsnlexer.cpp:401
bool commentsAreTokens
true if should return comments as tokens
Definition: dsnlexer.h:516
bool SetCommentsAreTokens(bool val)
Change the handling of comments.
Definition: dsnlexer.h:289
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:80
void PushReader(LINE_READER *aLineReader)
Manage a stack of LINE_READERs in order to handle nested file inclusion.
Definition: dsnlexer.cpp:188
bool isSep(char cc)
Definition: dsnlexer.cpp:450
bool isStringTerminator(char cc) const
Definition: dsnlexer.h:483
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:117
int NeedSYMBOLorNUMBER()
Call NextTok() and then verifies that the token read in satisfies bool IsSymbol() or the next token i...
Definition: dsnlexer.cpp:390
const KEYWORD * keywords
table sorted by CMake for bsearch()
Definition: dsnlexer.h:524
virtual ~DSNLEXER()
Definition: dsnlexer.cpp:139
const char * name
unique keyword.
Definition: dsnlexer.h:41
wxArrayString * ReadCommentLines()
Check the next sequence of tokens and reads them into a wxArrayString if they are comments.
Definition: dsnlexer.cpp:798
KEYWORD_MAP keyword_hash
fast, specialized "C string" hashtable
Definition: dsnlexer.h:526
static bool isNumber(const char *cp, const char *limit)
Return true if the next sequence of text is a number: either an integer, fixed point,...
Definition: dsnlexer.cpp:465
void SetSpecctraMode(bool aMode)
Change the behavior of this lexer into or out of "specctra mode".
Definition: dsnlexer.cpp:149
bool space_in_quoted_tokens
blank spaces within quoted strings
Definition: dsnlexer.h:514
int findToken(const std::string &aToken) const
Take aToken string and looks up the string in the keywords table.
Definition: dsnlexer.cpp:229
wxString GetTokenString(int aTok) const
Return a quote wrapped wxString representation of a token value.
Definition: dsnlexer.cpp:303
const char * next
Definition: dsnlexer.h:496
int NeedSYMBOL()
Call NextTok() and then verifies that the token read in satisfies IsSymbol().
Definition: dsnlexer.cpp:379
LINE_READER * PopReader()
Delete the top most LINE_READER from an internal stack of LINE_READERs and in the case of FILE_LINE_R...
Definition: dsnlexer.cpp:200
void NeedLEFT()
Call NextTok() and then verifies that the token read in is a DSN_LEFT.
Definition: dsnlexer.cpp:362
A LINE_READER that reads from an open file.
Definition: richio.h:172
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:164
const char * limit
Definition: dsnlexer.h:497
bool isDigit(char cc)
Definition: dsnlexer.cpp:443
static bool IsSymbol(int aTok)
Test a token to see if it is a symbol.
Definition: dsnlexer.cpp:313
static bool isSpace(char cc)
Test for whitespace.
Definition: dsnlexer.cpp:422
#define _(s)
const char * GetTokenText(int aTok) const
Return the C string representation of a DSN_T value.
Definition: dsnlexer.cpp:284
bool iOwnReaders
on readerStack, should I delete them?
Definition: dsnlexer.h:494
READER_STACK readerStack
all the LINE_READERs by pointer.
Definition: dsnlexer.h:502
static const KEYWORD empty_keywords[1]
Definition: dsnlexer.cpp:121
LINE_READER * reader
Definition: dsnlexer.h:505
bool specctraMode
if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_...
Definition: dsnlexer.h:507
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
int prevTok
curTok from previous NextTok() call.
Definition: dsnlexer.h:518
int readLine()
Definition: dsnlexer.h:454
int CurOffset() const
Return the byte offset within the current line, using a 1 based index.
Definition: dsnlexer.h:444
const char * start
Definition: dsnlexer.h:495
bool SyncLineReaderWith(DSNLEXER &aLexer)
Usable only for DSN lexers which share the same LINE_READER.
Definition: dsnlexer.cpp:165
void Duplicate(int aTok)
Throw an IO_ERROR exception with a message saying specifically that aTok is a duplicate of one alread...
Definition: dsnlexer.cpp:346
#define FMT_CLIPBOARD
Definition: dsnlexer.cpp:35
std::string curText
the text of the current token
Definition: dsnlexer.h:522
int NextTok()
Return the next token found in the input file or DSN_EOF when reaching the end of file.
Definition: dsnlexer.cpp:515
void Expecting(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
Definition: dsnlexer.cpp:322
const char * CurLine() const
Return the current line of text from which the CurText() would return its token.
Definition: dsnlexer.h:424
void NeedRIGHT()
Call NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:370
unsigned keywordCount
count of keywords table
Definition: dsnlexer.h:525
const wxString & CurSource() const
Return the current LINE_READER source.
Definition: dsnlexer.h:434
char dummy[1]
when there is no reader.
Definition: dsnlexer.h:498
int curTok
the current token obtained on last NextTok()
Definition: dsnlexer.h:521
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:240
void Unexpected(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
Definition: dsnlexer.cpp:338
Hold a keyword string and its unique integer token.
Definition: dsnlexer.h:39
void init()
Definition: dsnlexer.cpp:40
Implement a lexical analyzer for the SPECCTRA DSN file format.
Definition: dsnlexer.h:78
char stringDelimiter
Definition: dsnlexer.h:513
DSNLEXER(const KEYWORD *aKeywordTable, unsigned aKeywordCount, FILE *aFile, const wxString &aFileName)
Initialize a DSN lexer and prepares to read from aFile which is already open and has aFilename.
Definition: dsnlexer.cpp:72
wxString FromUTF8() const
Return the current token text as a wxString, assuming that the input byte stream is UTF8 encoded.
Definition: dsnlexer.h:408
int token
a zero based index into an array of KEYWORDs
Definition: dsnlexer.h:42
static const char * Syntax(int aTok)
Definition: dsnlexer.cpp:240