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