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