Be more flexible with user input; more multibyte safety.

This commit is contained in:
Jeff Young 2020-08-06 12:54:15 +01:00
parent dd7d8218f0
commit f27661fa39
6 changed files with 20 additions and 52 deletions

View File

@ -230,42 +230,15 @@ LINE_READER* DSNLEXER::PopReader()
} }
#if 0
static int compare( const void* a1, const void* a2 )
{
const KEYWORD* k1 = (const KEYWORD*) a1;
const KEYWORD* k2 = (const KEYWORD*) a2;
int ret = strcmp( k1->name, k2->name );
return ret;
}
int DSNLEXER::findToken( const std::string& tok )
{
KEYWORD search;
search.name = tok.c_str();
const KEYWORD* findings = (const KEYWORD*) bsearch( &search,
keywords, keywordCount,
sizeof(KEYWORD), compare );
if( findings )
return findings->token;
else
return DSN_SYMBOL; // not a keyword, some arbitrary symbol.
}
#else
inline int DSNLEXER::findToken( const std::string& tok ) inline int DSNLEXER::findToken( const std::string& tok )
{ {
KEYWORD_MAP::const_iterator it = keyword_hash.find( tok.c_str() ); KEYWORD_MAP::const_iterator it = keyword_hash.find( tok.c_str() );
if( it != keyword_hash.end() ) if( it != keyword_hash.end() )
return it->second; return it->second;
return DSN_SYMBOL; // not a keyword, some arbitrary symbol. return DSN_SYMBOL; // not a keyword, some arbitrary symbol.
} }
#endif
const char* DSNLEXER::Syntax( int aTok ) const char* DSNLEXER::Syntax( int aTok )

View File

@ -490,6 +490,15 @@ public:
return curText; return curText;
} }
/**
* Function GetCurStrAsToken
* Used to support "loose" matches (quoted tokens)
*/
int GetCurStrAsToken()
{
return findToken( curText );
}
/** /**
* Function FromUTF8 * Function FromUTF8
* returns the current token text as a wxString, assuming that the input * returns the current token text as a wxString, assuming that the input

View File

@ -56,23 +56,6 @@ namespace LIBEVAL
class COMPILER; class COMPILER;
struct ERROR_STATUS
{
bool pendingError = false;
enum STAGE
{
CST_PARSE = 0,
CST_CODEGEN,
CST_RUNTIME
};
STAGE stage;
wxString message; // Note: use wxString for GUI-related strings
int srcPos;
};
enum VAR_TYPE_T enum VAR_TYPE_T
{ {
VT_STRING = 1, VT_STRING = 1,

View File

@ -151,6 +151,9 @@ void DRC_RULES_PARSER::Parse( std::vector<DRC_RULE*>& aRules, REPORTER* aReporte
} }
} }
if( !m_reporter->HasMessage() )
m_reporter->Report( _( "No errors found." ), RPT_SEVERITY_INFO );
m_reporter = nullptr; m_reporter = nullptr;
} }
@ -184,6 +187,10 @@ DRC_RULE* DRC_RULES_PARSER::parseDRC_RULE()
"'blind_via', 'pad', 'zone', 'text', 'graphic' or 'hole'." ) ); "'blind_via', 'pad', 'zone', 'text', 'graphic' or 'hole'." ) );
break; break;
} }
else if( (int) token == DSN_STRING )
{
token = GetCurStrAsToken();
}
switch( token ) switch( token )
{ {

View File

@ -23,7 +23,6 @@
#include <cstdio> #include <cstdio>
#include <boost/algorithm/string/case_conv.hpp>
#include <memory> #include <memory>
#include <reporter.h> #include <reporter.h>
#include <class_board.h> #include <class_board.h>
@ -207,10 +206,7 @@ LIBEVAL::UCODE::FUNC_PTR PCB_EXPR_UCODE::CreateFuncCall( const char* aName )
{ {
PCB_EXPR_BUILTIN_FUNCTIONS& registry = PCB_EXPR_BUILTIN_FUNCTIONS::Instance(); PCB_EXPR_BUILTIN_FUNCTIONS& registry = PCB_EXPR_BUILTIN_FUNCTIONS::Instance();
std::string lowerName( aName ); return registry.Get( wxString::FromUTF8( aName ).Lower() );
boost::to_lower( lowerName );
return registry.Get( lowerName );
} }

View File

@ -121,7 +121,7 @@ public:
return self; return self;
} }
LIBEVAL::UCODE::FUNC_PTR Get( const std::string &name ) LIBEVAL::UCODE::FUNC_PTR Get( const wxString &name )
{ {
return m_funcs[ name ]; return m_funcs[ name ];
} }
@ -132,7 +132,7 @@ public:
} }
private: private:
std::map<std::string, LIBEVAL::UCODE::FUNC_PTR> m_funcs; std::map<wxString, LIBEVAL::UCODE::FUNC_PTR> m_funcs;
wxArrayString m_funcSigs; wxArrayString m_funcSigs;
}; };