21#include <fast_float/fast_float.h>
29#include <wx/translation.h>
31#define FMT_CLIPBOARD _( "clipboard" )
52 FILE* aFile,
const wxString& aFilename ) :
72 const std::string& aClipboardTxt,
const wxString& aSource ) :
242 KEYWORD_MAP::const_iterator it =
keywordsLookup->find( tok.c_str() );
252 lower.reserve( tok.size() );
255 lower += std::tolower( cc );
278 ret =
"string_quote";
281 ret =
"quoted text delimiter";
299 ret =
"quoted string";
302 ret =
"end of input";
324 ret =
"token too big";
334 ret << wxT(
"'") << wxString::FromUTF8(
GetTokenText(aTok) ) << wxT(
"'");
357 wxString errText = wxString::Format(
_(
"Expecting '%s'" ),
GetTokenString( aTok ) );
372 wxString errText = wxString::Format(
_(
"Unexpected '%s'" ),
GetTokenString( aTok ) );
379 wxString errText = wxString::Format(
_(
"%s is a duplicate" ),
GetTokenString( aTok ).GetData() );
386 wxString errText = wxString::Format(
_(
"Unexpected %s" ), wxString::FromUTF8(
text ) );
446 wxString errText = wxString::Format(
_(
"need a number for '%s'" ),
447 wxString::FromUTF8( aExpectation ).GetData() );
465 if( (
unsigned char) cc <=
' ' )
467 switch( (
unsigned char) cc )
484 return '0' <= cc && cc <=
'9';
500 bool sawNumber =
false;
502 if( cp <
limit && ( *cp==
'-' || *cp==
'+' ) )
511 if( cp <
limit && *cp ==
'.' )
524 if( cp <
limit && ( *cp==
'E' || *cp==
'e' ) )
530 if( cp <
limit && ( *cp==
'-' || *cp==
'+' ) )
541 return sawNumber && cp==
limit;
547 const char* cur =
next;
548 const char* head = cur;
581 if( cur<
limit && *cur==
'#' )
588 while(
limit[-1] ==
'\n' ||
limit[-1] ==
'\r' )
665 if( ++head >=
limit )
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;
681 for( i = 0; i < 2; ++i )
683 if( !isxdigit( head[i] ) )
692 c = (char) strtoul( tbuf,
nullptr, 16 );
704 if( head[i] <
'0' || head[i] >
'7' )
713 c = (char) strtoul( tbuf,
nullptr, 8 );
724 else if( *head ==
'"' )
737 wxString errtxt(
_(
"Unterminated delimited string" ) );
759 static const wxString errtxt(
_(
"String delimiter must be a single character of "
798 wxString errtxt(
_(
"Un-terminated delimited string" ) );
845 std::unique_ptr<wxArrayString> ret;
851 ret = std::make_unique<wxArrayString>();
862 return ret.release();
866#define FROM_CHARS_FLAGS ( fast_float::chars_format::skip_white_space | fast_float::chars_format::general )
872 const std::string& str =
CurStr();
875 fast_float::from_chars_result
res = fast_float::from_chars( str.data(), str.data() + str.size(), dval,
878 if(
res.ec != std::errc() )
int NeedSYMBOLorNUMBER()
Call NextTok() and then verifies that the token read in satisfies bool IsSymbol() or the next token i...
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,...
void NeedLEFT()
Call NextTok() and then verifies that the token read in is a DSN_LEFT.
std::string curText
The text of the current token.
unsigned keywordCount
Count of keywords table.
void NeedBAR()
Call NextTok() and then verifies that the token read in is a DSN_BAR.
int NeedNUMBER(const char *aExpectation)
Call NextTok() and then verifies that the token read is type DSN_NUMBER.
bool commentsAreTokens
True if should return comments as tokens.
int findToken(const std::string &aToken) const
Take aToken string and looks up the string in the keywords table.
static bool IsSymbol(int aTok)
Test a token to see if it is a symbol.
const char * GetTokenText(int aTok) const
Return the C string representation of a DSN_T value.
wxArrayString * ReadCommentLines()
Check the next sequence of tokens and reads them into a wxArrayString if they are comments.
int curTok
The current token obtained on last NextTok().
std::string curSeparator
The text of the separator preceeding the current text.
bool space_in_quoted_tokens
Blank spaces within quoted strings.
bool specctraMode
if true, then: 1) stringDelimiter can be changed 2) Kicad quoting protocol is not in effect 3) space_...
int NextTok()
Return the next token found in the input file or DSN_EOF when reaching the end of file.
int NeedSYMBOL()
Call NextTok() and then verifies that the token read in satisfies IsSymbol().
int curOffset
Offset within current line of the current token.
LINE_READER * reader
No ownership. ownership is via readerStack, maybe, if iOwnReaders.
bool isStringTerminator(char cc) const
const KEYWORD * keywords
Table sorted by CMake for bsearch().
void NeedRIGHT()
Call NextTok() and then verifies that the token read in is a DSN_RIGHT.
static bool IsNumber(int aTok)
READER_STACK readerStack
all the LINE_READERs by pointer.
char dummy[1]
When there is no reader.
double parseDouble()
Parse the current token as an ASCII numeric string with possible leading whitespace into a double pre...
void SetSpecctraMode(bool aMode)
Change the behavior of this lexer into or out of "specctra mode".
wxString FromUTF8() const
Return the current token text as a wxString, assuming that the input byte stream is UTF8 encoded.
void Expecting(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
const wxString & CurSource() const
Return the current LINE_READER source.
LINE_READER * PopReader()
Delete the top most LINE_READER from an internal stack of LINE_READERs and in the case of FILE_LINE_R...
void Duplicate(int aTok)
Throw an IO_ERROR exception with a message saying specifically that aTok is a duplicate of one alread...
const std::string & CurStr() const
Return a reference to current token in std::string form.
void SetKnowsBar(bool knowsBar=true)
const char * CurLine() const
Return the current line of text from which the CurText() would return its token.
bool SetCommentsAreTokens(bool val)
Change the handling of comments.
wxString GetTokenString(int aTok) const
Return a quote wrapped wxString representation of a token value.
int CurTok() const
Return whatever NextTok() returned the last time it was called.
int CurOffset() const
Return the byte offset within the current line, using a 1 based index.
void InitParserState()
Reinit variables used during parsing, to ensure od states are not used in a new parsing must be calle...
int prevTok
curTok from previous NextTok() call.
const KEYWORD_MAP * keywordsLookup
Fast, specialized "C string" hashtable.
static const char * Syntax(int aTok)
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.
bool SyncLineReaderWith(DSNLEXER &aLexer)
Usable only for DSN lexers which share the same LINE_READER.
bool m_knowsBar
True if the lexer knows about the bar token.
void Unexpected(int aTok) const
Throw an IO_ERROR exception with an input file specific error message.
int CurLineNumber() const
Return the current line number within my LINE_READER.
bool iOwnReaders
On readerStack, should I delete them?
void PushReader(LINE_READER *aLineReader)
Manage a stack of LINE_READERs in order to handle nested file inclusion.
A LINE_READER that reads from an open file.
An abstract class from which implementation specific LINE_READERs may be derived to read single lines...
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
static bool isSpace(char cc)
Test for whitespace.
static const KEYWORD empty_keywords[1]
#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.
Hold a keyword string and its unique integer token.