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 The 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, see <https://www.gnu.org/licenses/>.
19 */
20
21#include <fast_float/fast_float.h>
22#include <cstdarg>
23#include <cstdio>
24#include <cstdlib> // bsearch()
25#include <cctype>
26
27#include <dsnlexer.h>
28#include <wx/translation.h>
29
30#define FMT_CLIPBOARD _( "clipboard" )
31
32
33//-----<DSNLEXER>-------------------------------------------------------------
34
36{
39
40 stringDelimiter = '"';
41
42 specctraMode = false;
44 commentsAreTokens = false;
45 SetKnowsBar( true ); // default since version 20240706
46 curOffset = 0;
47}
48
49
50DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount, const KEYWORD_MAP* aKeywordMap,
51 FILE* aFile, const wxString& aFilename ) :
52 iOwnReaders( true ),
53 start( nullptr ),
54 next( nullptr ),
55 limit( nullptr ),
56 reader( nullptr ),
57 specctraMode( false ),
58 m_knowsBar( false ),
60 commentsAreTokens( false ),
61 keywords( aKeywordTable ),
62 keywordCount( aKeywordCount ),
63 keywordsLookup( aKeywordMap )
64{
65 PushReader( new FILE_LINE_READER( aFile, aFilename ) );
66 init();
67}
68
69
70DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount, const KEYWORD_MAP* aKeywordMap,
71 const std::string& aClipboardTxt, const wxString& aSource ) :
72 iOwnReaders( true ),
73 start( nullptr ),
74 next( nullptr ),
75 limit( nullptr ),
76 reader( nullptr ),
77 specctraMode( false ),
78 m_knowsBar( false ),
80 commentsAreTokens( false ),
81 keywords( aKeywordTable ),
82 keywordCount( aKeywordCount ),
83 keywordsLookup( aKeywordMap )
84{
85 PushReader( new STRING_LINE_READER( aClipboardTxt, aSource.IsEmpty() ? wxString( FMT_CLIPBOARD )
86 : aSource ) );
87 init();
88}
89
90
91DSNLEXER::DSNLEXER( const KEYWORD* aKeywordTable, unsigned aKeywordCount, const KEYWORD_MAP* aKeywordMap,
92 LINE_READER* aLineReader ) :
93 iOwnReaders( false ),
94 start( nullptr ),
95 next( nullptr ),
96 limit( nullptr ),
97 reader( nullptr ),
98 specctraMode( false ),
99 m_knowsBar( false ),
100 space_in_quoted_tokens( false ),
101 commentsAreTokens( false ),
102 keywords( aKeywordTable ),
103 keywordCount( aKeywordCount ),
104 keywordsLookup( aKeywordMap )
105{
106 if( aLineReader )
107 PushReader( aLineReader );
108
109 init();
110}
111
112
113static const KEYWORD empty_keywords[1] = {};
114
115DSNLEXER::DSNLEXER( const std::string& aSExpression, const wxString& aSource ) :
116 iOwnReaders( true ),
117 start( nullptr ),
118 next( nullptr ),
119 limit( nullptr ),
120 reader( nullptr ),
121 specctraMode( false ),
122 m_knowsBar( false ),
123 space_in_quoted_tokens( false ),
124 commentsAreTokens( false ),
126 keywordCount( 0 ),
127 keywordsLookup( nullptr )
128{
129 PushReader( new STRING_LINE_READER( aSExpression, aSource.IsEmpty() ? wxString( FMT_CLIPBOARD )
130 : aSource ) );
131 init();
132}
133
134
136{
137 if( iOwnReaders )
138 {
139 // delete the LINE_READERs from the stack, since I own them.
140 for( READER_STACK::iterator it = readerStack.begin(); it!=readerStack.end(); ++it )
141 delete *it;
142 }
143}
144
145
147{
148 specctraMode = aMode;
149
150 if( aMode )
151 {
152 // specctra mode defaults, some of which can still be changed in this mode.
154 }
155 else
156 {
158 stringDelimiter = '"';
159 }
160}
161
162
164{
167 commentsAreTokens = false;
168
169 curOffset = 0;
170}
171
172
174{
175 // Synchronize the pointers handling the data read by the LINE_READER
176 // only if aLexer shares the same LINE_READER, because only in this case
177 // the char buffer is be common
178
179 if( reader != aLexer.reader )
180 return false;
181
182 // We can synchronize the pointers which handle the data currently read
183 start = aLexer.start;
184 next = aLexer.next;
185 limit = aLexer.limit;
186
187 // Sync these parameters is not mandatory, but could help
188 // for instance in debug
189 curText = aLexer.curText;
190 curOffset = aLexer.curOffset;
191
192 return true;
193}
194
195
197{
198 readerStack.push_back( aLineReader );
199 reader = aLineReader;
200 start = (const char*) (*reader);
201
202 // force a new readLine() as first thing.
203 limit = start;
204 next = start;
205}
206
207
209{
210 LINE_READER* ret = nullptr;
211
212 if( readerStack.size() )
213 {
214 ret = reader;
215 readerStack.pop_back();
216
217 if( readerStack.size() )
218 {
219 reader = readerStack.back();
220 start = reader->Line();
221
222 // force a new readLine() as first thing.
223 limit = start;
224 next = start;
225 }
226 else
227 {
228 reader = nullptr;
229 start = dummy;
230 limit = dummy;
231 }
232 }
233 return ret;
234}
235
236
237int DSNLEXER::findToken( const std::string& tok ) const
238{
239 if( keywordsLookup != nullptr )
240 {
241 KEYWORD_MAP::const_iterator it = keywordsLookup->find( tok.c_str() );
242
243 if( it != keywordsLookup->end() )
244 return it->second;
245 }
246
247 return DSN_SYMBOL; // not a keyword, some arbitrary symbol.
248}
249
250
251const char* DSNLEXER::Syntax( int aTok )
252{
253 const char* ret;
254
255 switch( aTok )
256 {
257 case DSN_NONE:
258 ret = "NONE";
259 break;
260 case DSN_STRING_QUOTE:
261 ret = "string_quote"; // a special DSN syntax token, see specctra spec.
262 break;
263 case DSN_QUOTE_DEF:
264 ret = "quoted text delimiter";
265 break;
266 case DSN_DASH:
267 ret = "-";
268 break;
269 case DSN_SYMBOL:
270 ret = "symbol";
271 break;
272 case DSN_NUMBER:
273 ret = "number";
274 break;
275 case DSN_RIGHT:
276 ret = ")";
277 break;
278 case DSN_LEFT:
279 ret = "(";
280 break;
281 case DSN_STRING:
282 ret = "quoted string";
283 break;
284 case DSN_EOF:
285 ret = "end of input";
286 break;
287 case DSN_BAR:
288 ret = "|";
289 break;
290 default:
291 ret = "???";
292 }
293
294 return ret;
295}
296
297
298const char* DSNLEXER::GetTokenText( int aTok ) const
299{
300 const char* ret;
301
302 if( aTok < 0 )
303 return Syntax( aTok );
304 else if( (unsigned) aTok < keywordCount )
305 ret = keywords[aTok].name;
306 else
307 ret = "token too big";
308
309 return ret;
310}
311
312
313wxString DSNLEXER::GetTokenString( int aTok ) const
314{
315 wxString ret;
316
317 ret << wxT("'") << wxString::FromUTF8( GetTokenText(aTok) ) << wxT("'");
318
319 return ret;
320}
321
322
323bool DSNLEXER::IsSymbol( int aTok )
324{
325 // This is static and not inline to reduce code space.
326
327 // if aTok is >= 0, then it is a coincidental match to a keyword.
328 return aTok == DSN_SYMBOL || aTok == DSN_STRING || aTok >= 0;
329}
330
331
332bool DSNLEXER::IsNumber( int aTok )
333{
334 return aTok == DSN_NUMBER;
335}
336
337
338void DSNLEXER::Expecting( int aTok ) const
339{
340 wxString errText = wxString::Format( _( "Expecting '%s'" ), GetTokenString( aTok ) );
342}
343
344
345void DSNLEXER::Expecting( const char* text ) const
346{
347 wxString errText =
348 wxString::Format( _( "Expecting %s. Got '%s'" ), wxString::FromUTF8( text ), GetTokenString( CurTok() ) );
350}
351
352
353void DSNLEXER::Unexpected( int aTok ) const
354{
355 wxString errText = wxString::Format( _( "Unexpected '%s'" ), GetTokenString( aTok ) );
357}
358
359
360void DSNLEXER::Duplicate( int aTok )
361{
362 wxString errText = wxString::Format( _( "%s is a duplicate" ), GetTokenString( aTok ).GetData() );
364}
365
366
367void DSNLEXER::Unexpected( const char* text ) const
368{
369 wxString errText = wxString::Format( _( "Unexpected %s" ), wxString::FromUTF8( text ) );
371}
372
373
375{
376 int tok = NextTok();
377
378 if( tok != DSN_LEFT )
380}
381
382
384{
385 int tok = NextTok();
386
387 if( tok != DSN_RIGHT )
389}
390
391
393{
394 int tok = NextTok();
395
396 if( tok != DSN_BAR )
398}
399
400
402{
403 int tok = NextTok();
404
405 if( !IsSymbol( tok ) )
407
408 return tok;
409}
410
411
413{
414 int tok = NextTok();
415
416 if( !IsSymbol( tok ) && !IsNumber( tok ) )
417 Expecting( "a symbol or number" );
418
419 return tok;
420}
421
422
423int DSNLEXER::NeedNUMBER( const char* aExpectation )
424{
425 int tok = NextTok();
426
427 if( !IsNumber( tok ) )
428 {
429 wxString errText = wxString::Format( _( "need a number for '%s'" ),
430 wxString::FromUTF8( aExpectation ).GetData() );
432 }
433
434 return tok;
435}
436
437
444static bool isSpace( char cc )
445{
446 // cc is signed, so it is often negative.
447 // Treat negative as large positive to exclude rapidly.
448 if( (unsigned char) cc <= ' ' )
449 {
450 switch( (unsigned char) cc )
451 {
452 case ' ':
453 case '\n':
454 case '\r':
455 case '\t':
456 case '\0': // PCAD s-expression files have this.
457 return true;
458 }
459 }
460
461 return false;
462}
463
464
465inline bool isDigit( char cc )
466{
467 return '0' <= cc && cc <= '9';
468}
469
470
472inline bool DSNLEXER::isSep( char cc )
473{
474 return isSpace( cc ) || cc == '(' || cc == ')' || ( m_knowsBar && cc == '|' );
475}
476
477
487static bool isNumber( const char* cp, const char* limit )
488{
489 // regex for a float: "^[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?" i.e. any number,
490 // code traversal manually here:
491
492 bool sawNumber = false;
493
494 if( cp < limit && ( *cp=='-' || *cp=='+' ) )
495 ++cp;
496
497 while( cp < limit && isDigit( *cp ) )
498 {
499 ++cp;
500 sawNumber = true;
501 }
502
503 if( cp < limit && *cp == '.' )
504 {
505 ++cp;
506
507 while( cp < limit && isDigit( *cp ) )
508 {
509 ++cp;
510 sawNumber = true;
511 }
512 }
513
514 if( sawNumber )
515 {
516 if( cp < limit && ( *cp=='E' || *cp=='e' ) )
517 {
518 ++cp;
519
520 sawNumber = false; // exponent mandates at least one digit thereafter.
521
522 if( cp < limit && ( *cp=='-' || *cp=='+' ) )
523 ++cp;
524
525 while( cp < limit && isDigit( *cp ) )
526 {
527 ++cp;
528 sawNumber = true;
529 }
530 }
531 }
532
533 return sawNumber && cp==limit;
534}
535
536
538{
539 const char* cur = next;
540 const char* head = cur;
541
542 prevTok = curTok;
543 curSeparator.clear();
544
545 if( curTok == DSN_EOF )
546 goto exit;
547
548 if( cur >= limit )
549 {
550L_read:
551 // blank lines are returned as "\n" and will have a len of 1.
552 // EOF will have a len of 0 and so is detectable.
553 int len = readLine();
554
555 if( len == 0 )
556 {
557 cur = start; // after readLine(), since start can change, set cur offset to start
558 curTok = DSN_EOF;
559 goto exit;
560 }
561
562 cur = start; // after readLine() since start can change.
563
564 // skip leading whitespace
565 while( cur < limit && isSpace( *cur ) )
566 {
567 curSeparator += *cur;
568 ++cur;
569 }
570
571 // If the first non-blank character is #, this line is a comment.
572 // Comments cannot follow any other token on the same line.
573 if( cur<limit && *cur=='#' )
574 {
576 {
577 // Grab the entire current line [excluding end of line char(s)] as the
578 // current token. The '#' character may not be at offset zero.
579
580 while( limit[-1] == '\n' || limit[-1] == '\r' )
581 --limit;
582
583 curText.clear();
584 curText.append( start, limit );
585
586 cur = start; // ensure a good curOffset below
588 head = limit; // do a readLine() on next call in here.
589 goto exit;
590 }
591 else
592 {
593 goto L_read;
594 }
595 }
596 }
597 else
598 {
599 // skip leading whitespace
600 while( cur < limit && isSpace( *cur ) )
601 {
602 curSeparator += *cur;
603 ++cur;
604 }
605 }
606
607 if( cur >= limit )
608 goto L_read;
609
610 if( *cur == '(' )
611 {
612 curText = *cur;
614 head = cur+1;
615 goto exit;
616 }
617
618 if( *cur == ')' )
619 {
620 curText = *cur;
622 head = cur+1;
623 goto exit;
624 }
625
626 if( m_knowsBar && *cur == '|' )
627 {
628 curText = *cur;
629 curTok = DSN_BAR;
630 head = cur+1;
631 goto exit;
632 }
633
634 // Non-specctraMode, understands and deciphers escaped \, \r, \n, and \".
635 // Strips off leading and trailing double quotes
636 if( !specctraMode )
637 {
638 // a quoted string, will return DSN_STRING
639 if( *cur == stringDelimiter )
640 {
641 // copy the token, character by character so we can remove doubled up quotes.
642 curText.clear();
643
644 ++cur; // skip over the leading delimiter, which is always " in non-specctraMode
645
646 head = cur;
647
648 while( head<limit )
649 {
650 // ESCAPE SEQUENCES:
651 if( *head =='\\' )
652 {
653 char tbuf[8];
654 char c;
655 int i;
656
657 if( ++head >= limit )
658 break; // throw exception at L_unterminated
659
660 switch( *head++ )
661 {
662 case '"':
663 case '\\': c = head[-1]; break;
664 case 'a': c = '\x07'; break;
665 case 'b': c = '\x08'; break;
666 case 'f': c = '\x0c'; break;
667 case 'n': c = '\n'; break;
668 case 'r': c = '\r'; break;
669 case 't': c = '\x09'; break;
670 case 'v': c = '\x0b'; break;
671
672 case 'x': // 1 or 2 byte hex escape sequence
673 for( i = 0; i < 2; ++i )
674 {
675 if( !isxdigit( head[i] ) )
676 break;
677
678 tbuf[i] = head[i];
679 }
680
681 tbuf[i] = '\0';
682
683 if( i > 0 )
684 c = (char) strtoul( tbuf, nullptr, 16 );
685 else
686 c = 'x'; // a goofed hex escape sequence, interpret as 'x'
687
688 head += i;
689 break;
690
691 default: // 1-3 byte octal escape sequence
692 --head;
693
694 for( i=0; i<3; ++i )
695 {
696 if( head[i] < '0' || head[i] > '7' )
697 break;
698
699 tbuf[i] = head[i];
700 }
701
702 tbuf[i] = '\0';
703
704 if( i > 0 )
705 c = (char) strtoul( tbuf, nullptr, 8 );
706 else
707 c = '\\'; // a goofed octal escape sequence, interpret as '\'
708
709 head += i;
710 break;
711 }
712
713 curText += c;
714 }
715
716 else if( *head == '"' ) // end of the non-specctraMode DSN_STRING
717 {
719 ++head; // omit this trailing double quote
720 goto exit;
721 }
722
723 else
724 curText += *head++;
725
726 } // while
727
728 // L_unterminated:
729 wxString errtxt( _( "Unterminated delimited string" ) );
731 cur - start + curText.length() );
732 }
733 }
734 else // is specctraMode, tests in this block should not occur in KiCad mode.
735 {
736 /* get the dash out of a <pin_reference> which is embedded for example
737 like: U2-14 or "U2"-"14"
738 This is detectable by a non-space immediately preceding the dash.
739 */
740 if( *cur == '-' && cur>start && !isSpace( cur[-1] ) )
741 {
742 curText = '-';
744 head = cur+1;
745 goto exit;
746 }
747
748 // switching the string_quote character
750 {
751 static const wxString errtxt( _("String delimiter must be a single character of "
752 "', \", or $") );
753
754 char cc = *cur;
755 switch( cc )
756 {
757 case '\'':
758 case '$':
759 case '"':
760 break;
761 default:
763 }
764
765 curText = cc;
766
767 head = cur+1;
768
769 if( head<limit && !isSep( *head ) )
770 {
772 }
773
775 goto exit;
776 }
777
778 // specctraMode DSN_STRING
779 if( *cur == stringDelimiter )
780 {
781 ++cur; // skip over the leading delimiter: ",', or $
782
783 head = cur;
784
785 while( head<limit && !isStringTerminator( *head ) )
786 ++head;
787
788 if( head >= limit )
789 {
790 wxString errtxt( _( "Un-terminated delimited string" ) );
792 }
793
794 curText.clear();
795 curText.append( cur, head );
796
797 ++head; // skip over the trailing delimiter
798
800 goto exit;
801 }
802 } // specctraMode
803
804 // non-quoted token, read it into curText.
805 curText.clear();
806
807 head = cur;
808 while( head<limit && !isSep( *head ) )
809 curText += *head++;
810
811 if( isNumber( curText.c_str(), curText.c_str() + curText.size() ) )
812 {
814 goto exit;
815 }
816
817 if( specctraMode && curText == "string_quote" )
818 {
820 goto exit;
821 }
822
824
825exit: // single point of exit, no returns elsewhere please.
826
827 curOffset = cur - start;
828
829 next = head;
830
831 return curTok;
832}
833
834
836{
837 wxArrayString* ret = nullptr;
838 bool cmt_setting = SetCommentsAreTokens( true );
839 int tok = NextTok();
840
841 if( tok == DSN_COMMENT )
842 {
843 ret = new wxArrayString();
844
845 do
846 {
847 ret->Add( FromUTF8() );
848 }
849 while( ( tok = NextTok() ) == DSN_COMMENT );
850 }
851
852 SetCommentsAreTokens( cmt_setting );
853
854 return ret;
855}
856
857// Skip the white space and also accept both normal numbers and scientfic notation
858#define FROM_CHARS_FLAGS ( fast_float::chars_format::skip_white_space | fast_float::chars_format::general )
859
861{
862 // Use fast_float::from_chars which is designed to be locale independent and significantly
863 // faster than strtod and std::from_chars
864 const std::string& str = CurStr();
865
866 double dval{};
867 fast_float::from_chars_result res = fast_float::from_chars( str.data(), str.data() + str.size(), dval,
869
870 if( res.ec != std::errc() )
871 {
872 THROW_PARSE_ERROR( _( "Invalid floating point number" ), CurSource(), CurLine(),
874 }
875
876 return dval;
877}
int NeedSYMBOLorNUMBER()
Call NextTok() and then verifies that the token read in satisfies bool IsSymbol() or the next token i...
Definition dsnlexer.cpp:412
virtual ~DSNLEXER()
Definition dsnlexer.cpp:135
void NeedLEFT()
Call NextTok() and then verifies that the token read in is a DSN_LEFT.
Definition dsnlexer.cpp:374
const char * next
Definition dsnlexer.h:543
std::string curText
The text of the current token.
Definition dsnlexer.h:571
unsigned keywordCount
Count of keywords table.
Definition dsnlexer.h:575
void NeedBAR()
Call NextTok() and then verifies that the token read in is a DSN_BAR.
Definition dsnlexer.cpp:392
int NeedNUMBER(const char *aExpectation)
Call NextTok() and then verifies that the token read is type DSN_NUMBER.
Definition dsnlexer.cpp:423
bool commentsAreTokens
True if should return comments as tokens.
Definition dsnlexer.h:565
int findToken(const std::string &aToken) const
Take aToken string and looks up the string in the keywords table.
Definition dsnlexer.cpp:237
static bool IsSymbol(int aTok)
Test a token to see if it is a symbol.
Definition dsnlexer.cpp:323
void init()
Definition dsnlexer.cpp:35
const char * start
Definition dsnlexer.h:542
const char * GetTokenText(int aTok) const
Return the C string representation of a DSN_T value.
Definition dsnlexer.cpp:298
wxArrayString * ReadCommentLines()
Check the next sequence of tokens and reads them into a wxArrayString if they are comments.
Definition dsnlexer.cpp:835
int curTok
The current token obtained on last NextTok().
Definition dsnlexer.h:570
std::string curSeparator
The text of the separator preceeding the current text.
Definition dsnlexer.h:572
bool space_in_quoted_tokens
Blank spaces within quoted strings.
Definition dsnlexer.h:563
bool specctraMode
if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_...
Definition dsnlexer.h:554
int NextTok()
Return the next token found in the input file or DSN_EOF when reaching the end of file.
Definition dsnlexer.cpp:537
int NeedSYMBOL()
Call NextTok() and then verifies that the token read in satisfies IsSymbol().
Definition dsnlexer.cpp:401
int curOffset
Offset within current line of the current token.
Definition dsnlexer.h:568
char stringDelimiter
Definition dsnlexer.h:562
LINE_READER * reader
No ownership. ownership is via readerStack, maybe, if iOwnReaders.
Definition dsnlexer.h:552
const char * limit
Definition dsnlexer.h:544
bool isStringTerminator(char cc) const
Definition dsnlexer.h:508
const KEYWORD * keywords
Table sorted by CMake for bsearch().
Definition dsnlexer.h:574
void NeedRIGHT()
Call NextTok() and then verifies that the token read in is a DSN_RIGHT.
Definition dsnlexer.cpp:383
static bool IsNumber(int aTok)
Definition dsnlexer.cpp:332
int readLine()
Definition dsnlexer.h:479
READER_STACK readerStack
all the LINE_READERs by pointer.
Definition dsnlexer.h:549
char dummy[1]
When there is no reader.
Definition dsnlexer.h:545
double parseDouble()
Parse the current token as an ASCII numeric string with possible leading whitespace into a double pre...
Definition dsnlexer.cpp:860
void SetSpecctraMode(bool aMode)
Change the behavior of this lexer into or out of "specctra mode".
Definition dsnlexer.cpp:146
wxString FromUTF8() const
Return the current token text as a wxString, assuming that the input byte stream is UTF8 encoded.
Definition dsnlexer.h:433
void Expecting(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
Definition dsnlexer.cpp:338
const wxString & CurSource() const
Return the current LINE_READER source.
Definition dsnlexer.h:459
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:208
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:360
const std::string & CurStr() const
Return a reference to current token in std::string form.
Definition dsnlexer.h:419
void SetKnowsBar(bool knowsBar=true)
Definition dsnlexer.h:285
const char * CurLine() const
Return the current line of text from which the CurText() would return its token.
Definition dsnlexer.h:449
bool SetCommentsAreTokens(bool val)
Change the handling of comments.
Definition dsnlexer.h:300
wxString GetTokenString(int aTok) const
Return a quote wrapped wxString representation of a token value.
Definition dsnlexer.cpp:313
int CurTok() const
Return whatever NextTok() returned the last time it was called.
Definition dsnlexer.h:232
bool isSep(char cc)
Definition dsnlexer.cpp:472
int CurOffset() const
Return the byte offset within the current line, using a 1 based index.
Definition dsnlexer.h:469
void InitParserState()
Reinit variables used during parsing, to ensure od states are not used in a new parsing must be calle...
Definition dsnlexer.cpp:163
int prevTok
curTok from previous NextTok() call.
Definition dsnlexer.h:567
const KEYWORD_MAP * keywordsLookup
Fast, specialized "C string" hashtable.
Definition dsnlexer.h:576
static const char * Syntax(int aTok)
Definition dsnlexer.cpp:251
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:50
bool SyncLineReaderWith(DSNLEXER &aLexer)
Usable only for DSN lexers which share the same LINE_READER.
Definition dsnlexer.cpp:173
bool m_knowsBar
True if the lexer knows about the bar token.
Definition dsnlexer.h:559
void Unexpected(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
Definition dsnlexer.cpp:353
int CurLineNumber() const
Return the current line number within my LINE_READER.
Definition dsnlexer.h:441
bool iOwnReaders
On readerStack, should I delete them?
Definition dsnlexer.h:541
void PushReader(LINE_READER *aLineReader)
Manage a stack of LINE_READERs in order to handle nested file inclusion.
Definition dsnlexer.cpp:196
A LINE_READER that reads from an open file.
Definition richio.h:154
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Definition richio.h:62
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition richio.h:222
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:487
bool isDigit(char cc)
Definition dsnlexer.cpp:465
static bool isSpace(char cc)
Test for whitespace.
Definition dsnlexer.cpp:444
static const KEYWORD empty_keywords[1]
Definition dsnlexer.cpp:113
#define FROM_CHARS_FLAGS
Definition dsnlexer.cpp:858
#define FMT_CLIPBOARD
Definition dsnlexer.cpp:30
@ DSN_QUOTE_DEF
Definition dsnlexer.h:58
@ DSN_STRING_QUOTE
Definition dsnlexer.h:57
@ DSN_LEFT
Definition dsnlexer.h:63
@ DSN_RIGHT
Definition dsnlexer.h:62
@ DSN_NUMBER
Definition dsnlexer.h:61
@ DSN_NONE
Definition dsnlexer.h:54
@ DSN_BAR
Definition dsnlexer.h:55
@ DSN_DASH
Definition dsnlexer.h:59
@ DSN_SYMBOL
Definition dsnlexer.h:60
@ DSN_COMMENT
Definition dsnlexer.h:56
@ DSN_STRING
Definition dsnlexer.h:64
@ DSN_EOF
Definition dsnlexer.h:65
#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:93
#define THROW_PARSE_ERROR(aProblem, aSource, aInputLine, aLineNumber, aByteIndex)
Hold a keyword string and its unique integer token.
Definition dsnlexer.h:36
VECTOR3I res