KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dsnlexer.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2007-2013 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright (C) 2007-2024 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#include <charconv>
26#include <cstdarg>
27#include <cstdio>
28#include <cstdlib> // bsearch()
29#include <cctype>
30
31#include <dsnlexer.h>
32#include <wx/translation.h>
33
34#define FMT_CLIPBOARD _( "clipboard" )
35
36
37//-----<DSNLEXER>-------------------------------------------------------------
38
40{
43
44 stringDelimiter = '"';
45
46 specctraMode = false;
48 commentsAreTokens = false;
49
50 curOffset = 0;
51}
52
53
54DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
55 const KEYWORD_MAP* aKeywordMap,
56 FILE* aFile, const wxString& aFilename ) :
57 iOwnReaders( true ),
58 start( nullptr ),
59 next( nullptr ),
60 limit( nullptr ),
61 reader( nullptr ),
62 keywords( aKeywordTable ),
63 keywordCount( aKeywordCount ),
64 keywordsLookup( aKeywordMap )
65{
66 FILE_LINE_READER* fileReader = new FILE_LINE_READER( aFile, aFilename );
67 PushReader( fileReader );
68 init();
69}
70
71
72DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
73 const KEYWORD_MAP* aKeywordMap,
74 const std::string& aClipboardTxt, const wxString& aSource ) :
75 iOwnReaders( true ),
76 start( nullptr ),
77 next( nullptr ),
78 limit( nullptr ),
79 reader( nullptr ),
80 keywords( aKeywordTable ),
81 keywordCount( aKeywordCount ),
82 keywordsLookup( aKeywordMap )
83{
84 STRING_LINE_READER* stringReader = new STRING_LINE_READER( aClipboardTxt, aSource.IsEmpty() ?
85 wxString( FMT_CLIPBOARD ) : aSource );
86 PushReader( stringReader );
87 init();
88}
89
90
91DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount,
92 const KEYWORD_MAP* aKeywordMap,
93 LINE_READER* aLineReader ) :
94 iOwnReaders( false ),
95 start( nullptr ),
96 next( nullptr ),
97 limit( nullptr ),
98 reader( nullptr ),
99 keywords( aKeywordTable ),
100 keywordCount( aKeywordCount ),
101 keywordsLookup( aKeywordMap )
102{
103 if( aLineReader )
104 PushReader( aLineReader );
105 init();
106}
107
108
109static const KEYWORD empty_keywords[1] = {};
110
111DSNLEXER::DSNLEXER( const std::string& aSExpression, const wxString& aSource ) :
112 iOwnReaders( true ),
113 start( nullptr ),
114 next( nullptr ),
115 limit( nullptr ),
116 reader( nullptr ),
117 keywords( empty_keywords ),
118 keywordCount( 0 ),
119 keywordsLookup( nullptr )
120{
121 STRING_LINE_READER* stringReader = new STRING_LINE_READER( aSExpression, aSource.IsEmpty() ?
122 wxString( FMT_CLIPBOARD ) : aSource );
123 PushReader( stringReader );
124 init();
125}
126
127
129{
130 if( iOwnReaders )
131 {
132 // delete the LINE_READERs from the stack, since I own them.
133 for( READER_STACK::iterator it = readerStack.begin(); it!=readerStack.end(); ++it )
134 delete *it;
135 }
136}
137
138
140{
141 specctraMode = aMode;
142 if( aMode )
143 {
144 // specctra mode defaults, some of which can still be changed in this mode.
146 }
147 else
148 {
150 stringDelimiter = '"';
151 }
152}
153
154
156{
159 commentsAreTokens = false;
160
161 curOffset = 0;
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
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
229int DSNLEXER::findToken( const std::string& tok ) const
230{
231 if( keywordsLookup != nullptr )
232 {
233 KEYWORD_MAP::const_iterator it = keywordsLookup->find( tok.c_str() );
234
235 if( it != keywordsLookup->end() )
236 return it->second;
237 }
238
239 return DSN_SYMBOL; // not a keyword, some arbitrary symbol.
240}
241
242
243const char* DSNLEXER::Syntax( int aTok )
244{
245 const char* ret;
246
247 switch( aTok )
248 {
249 case DSN_NONE:
250 ret = "NONE";
251 break;
252 case DSN_STRING_QUOTE:
253 ret = "string_quote"; // a special DSN syntax token, see specctra spec.
254 break;
255 case DSN_QUOTE_DEF:
256 ret = "quoted text delimiter";
257 break;
258 case DSN_DASH:
259 ret = "-";
260 break;
261 case DSN_SYMBOL:
262 ret = "symbol";
263 break;
264 case DSN_NUMBER:
265 ret = "number";
266 break;
267 case DSN_RIGHT:
268 ret = ")";
269 break;
270 case DSN_LEFT:
271 ret = "(";
272 break;
273 case DSN_STRING:
274 ret = "quoted string";
275 break;
276 case DSN_EOF:
277 ret = "end of input";
278 break;
279 case DSN_BAR:
280 ret = "|";
281 break;
282 default:
283 ret = "???";
284 }
285
286 return ret;
287}
288
289
290const char* DSNLEXER::GetTokenText( int aTok ) const
291{
292 const char* ret;
293
294 if( aTok < 0 )
295 {
296 return Syntax( aTok );
297 }
298 else if( (unsigned) aTok < keywordCount )
299 {
300 ret = keywords[aTok].name;
301 }
302 else
303 ret = "token too big";
304
305 return ret;
306}
307
308
309wxString DSNLEXER::GetTokenString( int aTok ) const
310{
311 wxString ret;
312
313 ret << wxT("'") << wxString::FromUTF8( GetTokenText(aTok) ) << wxT("'");
314
315 return ret;
316}
317
318
319bool DSNLEXER::IsSymbol( int aTok )
320{
321 // This is static and not inline to reduce code space.
322
323 // if aTok is >= 0, then it is a coincidental match to a keyword.
324 return aTok == DSN_SYMBOL || aTok == DSN_STRING || aTok >= 0;
325}
326
327
328void DSNLEXER::Expecting( int aTok ) const
329{
330 wxString errText = wxString::Format(
331 _( "Expecting %s" ), GetTokenString( aTok ) );
333}
334
335
336void DSNLEXER::Expecting( const char* text ) const
337{
338 wxString errText = wxString::Format(
339 _( "Expecting '%s'" ), wxString::FromUTF8( text ) );
341}
342
343
344void DSNLEXER::Unexpected( int aTok ) const
345{
346 wxString errText = wxString::Format(
347 _( "Unexpected %s" ), GetTokenString( aTok ) );
349}
350
351
352void DSNLEXER::Duplicate( int aTok )
353{
354 wxString errText = wxString::Format(
355 _("%s is a duplicate"), GetTokenString( aTok ).GetData() );
357}
358
359
360void DSNLEXER::Unexpected( const char* text ) const
361{
362 wxString errText = wxString::Format(
363 _( "Unexpected '%s'" ), wxString::FromUTF8( text ) );
365}
366
367
369{
370 int tok = NextTok();
371 if( tok != DSN_LEFT )
373}
374
375
377{
378 int tok = NextTok();
379
380 if( tok != DSN_RIGHT )
382}
383
384
386{
387 int tok = NextTok();
388
389 if( tok != DSN_BAR )
391}
392
393
395{
396 int tok = NextTok();
397
398 if( !IsSymbol( tok ) )
400
401 return tok;
402}
403
404
406{
407 int tok = NextTok();
408
409 if( !IsSymbol( tok ) && tok!=DSN_NUMBER )
410 Expecting( "a symbol or number" );
411
412 return tok;
413}
414
415
416int DSNLEXER::NeedNUMBER( const char* aExpectation )
417{
418 int tok = NextTok();
419
420 if( tok != DSN_NUMBER )
421 {
422 wxString errText = wxString::Format( _( "need a number for '%s'" ),
423 wxString::FromUTF8( aExpectation ).GetData() );
425 }
426
427 return tok;
428}
429
430
437static bool isSpace( char cc )
438{
439 // cc is signed, so it is often negative.
440 // Treat negative as large positive to exclude rapidly.
441 if( (unsigned char) cc <= ' ' )
442 {
443 switch( (unsigned char) cc )
444 {
445 case ' ':
446 case '\n':
447 case '\r':
448 case '\t':
449 case '\0': // PCAD s-expression files have this.
450 return true;
451 }
452 }
453
454 return false;
455}
456
457
458inline bool isDigit( char cc )
459{
460 return '0' <= cc && cc <= '9';
461}
462
463
465inline bool isSep( char cc )
466{
467 return isSpace( cc ) || cc == '(' || cc == ')' || cc == '|';
468}
469
470
480static bool isNumber( const char* cp, const char* limit )
481{
482 // regex for a float: "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?" i.e. any number,
483 // code traversal manually here:
484
485 bool sawNumber = false;
486
487 if( cp < limit && ( *cp=='-' || *cp=='+' ) )
488 ++cp;
489
490 while( cp < limit && isDigit( *cp ) )
491 {
492 ++cp;
493 sawNumber = true;
494 }
495
496 if( cp < limit && *cp == '.' )
497 {
498 ++cp;
499
500 while( cp < limit && isDigit( *cp ) )
501 {
502 ++cp;
503 sawNumber = true;
504 }
505 }
506
507 if( sawNumber )
508 {
509 if( cp < limit && ( *cp=='E' || *cp=='e' ) )
510 {
511 ++cp;
512
513 sawNumber = false; // exponent mandates at least one digit thereafter.
514
515 if( cp < limit && ( *cp=='-' || *cp=='+' ) )
516 ++cp;
517
518 while( cp < limit && isDigit( *cp ) )
519 {
520 ++cp;
521 sawNumber = true;
522 }
523 }
524 }
525
526 return sawNumber && cp==limit;
527}
528
529
531{
532 const char* cur = next;
533 const char* head = cur;
534
535 prevTok = curTok;
536
537 if( curTok == DSN_EOF )
538 goto exit;
539
540 if( cur >= limit )
541 {
542L_read:
543 // blank lines are returned as "\n" and will have a len of 1.
544 // EOF will have a len of 0 and so is detectable.
545 int len = readLine();
546
547 if( len == 0 )
548 {
549 cur = start; // after readLine(), since start can change, set cur offset to start
550 curTok = DSN_EOF;
551 goto exit;
552 }
553
554 cur = start; // after readLine() since start can change.
555
556 // skip leading whitespace
557 while( cur < limit && isSpace( *cur ) )
558 ++cur;
559
560 // If the first non-blank character is #, this line is a comment.
561 // Comments cannot follow any other token on the same line.
562 if( cur<limit && *cur=='#' )
563 {
565 {
566 // Grab the entire current line [excluding end of line char(s)] as the
567 // current token. The '#' character may not be at offset zero.
568
569 while( limit[-1] == '\n' || limit[-1] == '\r' )
570 --limit;
571
572 curText.clear();
573 curText.append( start, limit );
574
575 cur = start; // ensure a good curOffset below
577 head = limit; // do a readLine() on next call in here.
578 goto exit;
579 }
580 else
581 {
582 goto L_read;
583 }
584 }
585 }
586 else
587 {
588 // skip leading whitespace
589 while( cur < limit && isSpace( *cur ) )
590 ++cur;
591 }
592
593 if( cur >= limit )
594 goto L_read;
595
596 if( *cur == '(' )
597 {
598 curText = *cur;
600 head = cur+1;
601 goto exit;
602 }
603
604 if( *cur == ')' )
605 {
606 curText = *cur;
608 head = cur+1;
609 goto exit;
610 }
611
612 if( *cur == '|' )
613 {
614 curText = *cur;
615 curTok = DSN_BAR;
616 head = cur+1;
617 goto exit;
618 }
619
620 // Non-specctraMode, understands and deciphers escaped \, \r, \n, and \".
621 // Strips off leading and trailing double quotes
622 if( !specctraMode )
623 {
624 // a quoted string, will return DSN_STRING
625 if( *cur == stringDelimiter )
626 {
627 // copy the token, character by character so we can remove doubled up quotes.
628 curText.clear();
629
630 ++cur; // skip over the leading delimiter, which is always " in non-specctraMode
631
632 head = cur;
633
634 while( head<limit )
635 {
636 // ESCAPE SEQUENCES:
637 if( *head =='\\' )
638 {
639 char tbuf[8];
640 char c;
641 int i;
642
643 if( ++head >= limit )
644 break; // throw exception at L_unterminated
645
646 switch( *head++ )
647 {
648 case '"':
649 case '\\': c = head[-1]; break;
650 case 'a': c = '\x07'; break;
651 case 'b': c = '\x08'; break;
652 case 'f': c = '\x0c'; break;
653 case 'n': c = '\n'; break;
654 case 'r': c = '\r'; break;
655 case 't': c = '\x09'; break;
656 case 'v': c = '\x0b'; break;
657
658 case 'x': // 1 or 2 byte hex escape sequence
659 for( i = 0; i < 2; ++i )
660 {
661 if( !isxdigit( head[i] ) )
662 break;
663
664 tbuf[i] = head[i];
665 }
666
667 tbuf[i] = '\0';
668
669 if( i > 0 )
670 c = (char) strtoul( tbuf, nullptr, 16 );
671 else
672 c = 'x'; // a goofed hex escape sequence, interpret as 'x'
673
674 head += i;
675 break;
676
677 default: // 1-3 byte octal escape sequence
678 --head;
679
680 for( i=0; i<3; ++i )
681 {
682 if( head[i] < '0' || head[i] > '7' )
683 break;
684
685 tbuf[i] = head[i];
686 }
687
688 tbuf[i] = '\0';
689
690 if( i > 0 )
691 c = (char) strtoul( tbuf, nullptr, 8 );
692 else
693 c = '\\'; // a goofed octal escape sequence, interpret as '\'
694
695 head += i;
696 break;
697 }
698
699 curText += c;
700 }
701
702 else if( *head == '"' ) // end of the non-specctraMode DSN_STRING
703 {
705 ++head; // omit this trailing double quote
706 goto exit;
707 }
708
709 else
710 curText += *head++;
711
712 } // while
713
714 // L_unterminated:
715 wxString errtxt( _( "Un-terminated delimited string" ) );
717 cur - start + curText.length() );
718 }
719 }
720 else // is specctraMode, tests in this block should not occur in KiCad mode.
721 {
722 /* get the dash out of a <pin_reference> which is embedded for example
723 like: U2-14 or "U2"-"14"
724 This is detectable by a non-space immediately preceding the dash.
725 */
726 if( *cur == '-' && cur>start && !isSpace( cur[-1] ) )
727 {
728 curText = '-';
730 head = cur+1;
731 goto exit;
732 }
733
734 // switching the string_quote character
736 {
737 static const wxString errtxt( _("String delimiter must be a single character of "
738 "', \", or $") );
739
740 char cc = *cur;
741 switch( cc )
742 {
743 case '\'':
744 case '$':
745 case '"':
746 break;
747 default:
749 }
750
751 curText = cc;
752
753 head = cur+1;
754
755 if( head<limit && !isSep( *head ) )
756 {
758 }
759
761 goto exit;
762 }
763
764 // specctraMode DSN_STRING
765 if( *cur == stringDelimiter )
766 {
767 ++cur; // skip over the leading delimiter: ",', or $
768
769 head = cur;
770
771 while( head<limit && !isStringTerminator( *head ) )
772 ++head;
773
774 if( head >= limit )
775 {
776 wxString errtxt( _( "Un-terminated delimited string" ) );
778 }
779
780 curText.clear();
781 curText.append( cur, head );
782
783 ++head; // skip over the trailing delimiter
784
786 goto exit;
787 }
788 } // specctraMode
789
790 // non-quoted token, read it into curText.
791 curText.clear();
792
793 head = cur;
794 while( head<limit && !isSep( *head ) )
795 curText += *head++;
796
797 if( isNumber( curText.c_str(), curText.c_str() + curText.size() ) )
798 {
800 goto exit;
801 }
802
803 if( specctraMode && curText == "string_quote" )
804 {
806 goto exit;
807 }
808
810
811exit: // single point of exit, no returns elsewhere please.
812
813 curOffset = cur - start;
814
815 next = head;
816
817 return curTok;
818}
819
820
822{
823 wxArrayString* ret = nullptr;
824 bool cmt_setting = SetCommentsAreTokens( true );
825 int tok = NextTok();
826
827 if( tok == DSN_COMMENT )
828 {
829 ret = new wxArrayString();
830
831 do
832 {
833 ret->Add( FromUTF8() );
834 }
835 while( ( tok = NextTok() ) == DSN_COMMENT );
836 }
837
838 SetCommentsAreTokens( cmt_setting );
839
840 return ret;
841}
842
843
845{
846#if ( defined( __GNUC__ ) && __GNUC__ < 11 ) || ( defined( __clang__ ) && __clang_major__ < 13 )
847 // GCC older than 11 "supports" C++17 without supporting the C++17 std::from_chars for doubles
848 // clang is similar
849
850 char* tmp;
851
852 errno = 0;
853
854 double fval = strtod( CurText(), &tmp );
855
856 if( errno )
857 {
858 wxString error;
859 error.Printf( _( "Invalid floating point number in\nfile: '%s'\nline: %d\noffset: %d" ),
861
862 THROW_IO_ERROR( error );
863 }
864
865 if( CurText() == tmp )
866 {
867 wxString error;
868 error.Printf( _( "Missing floating point number in\nfile: '%s'\nline: %d\noffset: %d" ),
870
871 THROW_IO_ERROR( error );
872 }
873
874 return fval;
875#else
876 // Use std::from_chars which is designed to be locale independent and performance oriented for data interchange
877
878 const std::string& str = CurStr();
879
880 // Offset any leading whitespace, this is one thing from_chars does not handle
881 size_t woff = 0;
882 while( std::isspace( str[woff] ) && woff < str.length() )
883 {
884 woff++;
885 }
886
887 double dval{};
888 std::from_chars_result res =
889 std::from_chars( str.data() + woff, str.data() + str.size(), dval );
890
891 if( res.ec != std::errc() )
892 {
893 THROW_PARSE_ERROR( _( "Invalid floating point number" ), CurSource(), CurLine(),
895 }
896
897 return dval;
898#endif
899}
Implement a lexical analyzer for the SPECCTRA DSN file format.
Definition: dsnlexer.h:81
int NeedSYMBOLorNUMBER()
Call NextTok() and then verifies that the token read in satisfies bool IsSymbol() or the next token i...
Definition: dsnlexer.cpp:405
virtual ~DSNLEXER()
Definition: dsnlexer.cpp:128
void NeedLEFT()
Call NextTok() and then verifies that the token read in is a DSN_LEFT.
Definition: dsnlexer.cpp:368
const char * next
Definition: dsnlexer.h:533
std::string curText
the text of the current token
Definition: dsnlexer.h:559
unsigned keywordCount
count of keywords table
Definition: dsnlexer.h:562
void NeedBAR()
Call NextTok() and then verifies that the token read in is a DSN_BAR.
Definition: dsnlexer.cpp:385
int NeedNUMBER(const char *aExpectation)
Call NextTok() and then verifies that the token read is type DSN_NUMBER.
Definition: dsnlexer.cpp:416
bool commentsAreTokens
true if should return comments as tokens
Definition: dsnlexer.h:553
int findToken(const std::string &aToken) const
Take aToken string and looks up the string in the keywords table.
Definition: dsnlexer.cpp:229
const char * CurText() const
Return a pointer to the current token's text.
Definition: dsnlexer.h:407
static bool IsSymbol(int aTok)
Test a token to see if it is a symbol.
Definition: dsnlexer.cpp:319
void init()
Definition: dsnlexer.cpp:39
const char * start
Definition: dsnlexer.h:532
const char * GetTokenText(int aTok) const
Return the C string representation of a DSN_T value.
Definition: dsnlexer.cpp:290
wxArrayString * ReadCommentLines()
Check the next sequence of tokens and reads them into a wxArrayString if they are comments.
Definition: dsnlexer.cpp:821
int curTok
the current token obtained on last NextTok()
Definition: dsnlexer.h:558
bool space_in_quoted_tokens
blank spaces within quoted strings
Definition: dsnlexer.h:551
bool specctraMode
if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_...
Definition: dsnlexer.h:544
int NextTok()
Return the next token found in the input file or DSN_EOF when reaching the end of file.
Definition: dsnlexer.cpp:530
int NeedSYMBOL()
Call NextTok() and then verifies that the token read in satisfies IsSymbol().
Definition: dsnlexer.cpp:394
int curOffset
offset within current line of the current token
Definition: dsnlexer.h:556
char stringDelimiter
Definition: dsnlexer.h:550
LINE_READER * reader
Definition: dsnlexer.h:542
const char * limit
Definition: dsnlexer.h:534
bool isStringTerminator(char cc) const
Definition: dsnlexer.h:499
const KEYWORD * keywords
table sorted by CMake for bsearch()
Definition: dsnlexer.h:561
void NeedRIGHT()
Call NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition: dsnlexer.cpp:376
int readLine()
Definition: dsnlexer.h:470
READER_STACK readerStack
all the LINE_READERs by pointer.
Definition: dsnlexer.h:539
char dummy[1]
when there is no reader.
Definition: dsnlexer.h:535
double parseDouble()
Parse the current token as an ASCII numeric string with possible leading whitespace into a double pre...
Definition: dsnlexer.cpp:844
void SetSpecctraMode(bool aMode)
Change the behavior of this lexer into or out of "specctra mode".
Definition: dsnlexer.cpp:139
wxString FromUTF8() const
Return the current token text as a wxString, assuming that the input byte stream is UTF8 encoded.
Definition: dsnlexer.h:424
void Expecting(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
Definition: dsnlexer.cpp:328
const wxString & CurSource() const
Return the current LINE_READER source.
Definition: dsnlexer.h:450
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 Duplicate(int aTok)
Throw an IO_ERROR exception with a message saying specifically that aTok is a duplicate of one alread...
Definition: dsnlexer.cpp:352
const std::string & CurStr() const
Return a reference to current token in std::string form.
Definition: dsnlexer.h:415
const char * CurLine() const
Return the current line of text from which the CurText() would return its token.
Definition: dsnlexer.h:440
bool SetCommentsAreTokens(bool val)
Change the handling of comments.
Definition: dsnlexer.h:298
wxString GetTokenString(int aTok) const
Return a quote wrapped wxString representation of a token value.
Definition: dsnlexer.cpp:309
int CurOffset() const
Return the byte offset within the current line, using a 1 based index.
Definition: dsnlexer.h:460
void InitParserState()
Reinit variables used during parsing, to ensure od states are not used in a new parsing must be calle...
Definition: dsnlexer.cpp:155
int prevTok
curTok from previous NextTok() call.
Definition: dsnlexer.h:555
const KEYWORD_MAP * keywordsLookup
fast, specialized "C string" hashtable
Definition: dsnlexer.h:563
static const char * Syntax(int aTok)
Definition: dsnlexer.cpp:243
DSNLEXER(const KEYWORD *aKeywordTable, unsigned aKeywordCount, const KEYWORD_MAP *aKeywordMap, FILE *aFile, const wxString &aFileName)
Initialize a DSN lexer and prepares to read from aFile which is already open and has aFilename.
Definition: dsnlexer.cpp:54
bool SyncLineReaderWith(DSNLEXER &aLexer)
Usable only for DSN lexers which share the same LINE_READER.
Definition: dsnlexer.cpp:165
void Unexpected(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
Definition: dsnlexer.cpp:344
int CurLineNumber() const
Return the current line number within my LINE_READER.
Definition: dsnlexer.h:432
bool iOwnReaders
on readerStack, should I delete them?
Definition: dsnlexer.h:531
void PushReader(LINE_READER *aLineReader)
Manage a stack of LINE_READERs in order to handle nested file inclusion.
Definition: dsnlexer.cpp:188
A LINE_READER that reads from an open file.
Definition: richio.h:185
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition: richio.h:93
char * Line() const
Return a pointer to the last line that was read in.
Definition: richio.h:129
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:253
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:480
bool isDigit(char cc)
Definition: dsnlexer.cpp:458
static bool isSpace(char cc)
Test for whitespace.
Definition: dsnlexer.cpp:437
static const KEYWORD empty_keywords[1]
Definition: dsnlexer.cpp:109
#define FMT_CLIPBOARD
Definition: dsnlexer.cpp:34
bool isSep(char cc)
Definition: dsnlexer.cpp:465
@ DSN_QUOTE_DEF
Definition: dsnlexer.h:64
@ DSN_STRING_QUOTE
Definition: dsnlexer.h:63
@ DSN_LEFT
Definition: dsnlexer.h:69
@ DSN_RIGHT
Definition: dsnlexer.h:68
@ DSN_NUMBER
Definition: dsnlexer.h:67
@ DSN_NONE
Definition: dsnlexer.h:60
@ DSN_BAR
Definition: dsnlexer.h:61
@ DSN_DASH
Definition: dsnlexer.h:65
@ DSN_SYMBOL
Definition: dsnlexer.h:66
@ DSN_COMMENT
Definition: dsnlexer.h:62
@ DSN_STRING
Definition: dsnlexer.h:70
@ DSN_EOF
Definition: dsnlexer.h:71
#define _(s)
std::unordered_map< const char *, int, fnv_1a, iequal_to > KEYWORD_MAP
A hashtable made of a const char* and an int.
Definition: hashtables.h:95
#define THROW_IO_ERROR(msg)
Definition: ki_exception.h:39
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Definition: ki_exception.h:165
CITER next(CITER it)
Definition: ptree.cpp:126
Hold a keyword string and its unique integer token.
Definition: dsnlexer.h:41
const char * name
unique keyword.
Definition: dsnlexer.h:42
VECTOR3I res