16
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-07-18 00:49:19 +02:00

build 200630. parser include support enhancement

This commit is contained in:
tmj-fstate
2020-06-30 15:57:20 +02:00
parent fc1f770186
commit 92379deff5
8 changed files with 37 additions and 18 deletions

View File

@@ -9099,7 +9099,7 @@ bool TMoverParameters::LoadFIZ(std::string chkpath)
*/ */
while( fizparser.ok() ) { while( fizparser.ok() ) {
inputline = fizparser.getToken<std::string>( false, "\n" ); inputline = fizparser.getToken<std::string>( false, "\n\r" );
bool comment = ( ( inputline.find('#') != std::string::npos ) bool comment = ( ( inputline.find('#') != std::string::npos )
|| ( inputline.compare( 0, 2, "//" ) == 0 ) ); || ( inputline.compare( 0, 2, "//" ) == 0 ) );

View File

@@ -194,7 +194,7 @@ drivermouse_input::recall_bindings() {
} }
// NOTE: to simplify things we expect one entry per line, and whole entry in one line // NOTE: to simplify things we expect one entry per line, and whole entry in one line
while( true == bindingparser.getTokens( 1, true, "\n" ) ) { while( true == bindingparser.getTokens( 1, true, "\n\r" ) ) {
std::string bindingentry; std::string bindingentry;
bindingparser >> bindingentry; bindingparser >> bindingentry;

View File

@@ -174,7 +174,7 @@ gamepad_input::recall_bindings() {
{ "value_invert", input_type::value_invert } }; { "value_invert", input_type::value_invert } };
// NOTE: to simplify things we expect one entry per line, and whole entry in one line // NOTE: to simplify things we expect one entry per line, and whole entry in one line
while( true == bindingparser.getTokens( 1, true, "\n" ) ) { while( true == bindingparser.getTokens( 1, true, "\n\r" ) ) {
std::string bindingentry; std::string bindingentry;
bindingparser >> bindingentry; bindingparser >> bindingentry;

View File

@@ -63,7 +63,7 @@ keyboard_input::recall_bindings() {
}; };
// NOTE: to simplify things we expect one entry per line, and whole entry in one line // NOTE: to simplify things we expect one entry per line, and whole entry in one line
while( true == bindingparser.getTokens( 1, true, "\n" ) ) { while( true == bindingparser.getTokens( 1, true, "\n\r" ) ) {
std::string bindingentry; std::string bindingentry;
bindingparser >> bindingentry; bindingparser >> bindingentry;

View File

@@ -230,23 +230,14 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
token.insert( pos, "none" ); // zabezpieczenie przed brakiem parametru token.insert( pos, "none" ); // zabezpieczenie przed brakiem parametru
} }
} }
// launch child parser if include directive found.
// NOTE: parameter collecting uses default set of token separators.
if( token == "include" ) { if( token == "include" ) {
// launch child parser if include directive found.
// NOTE: parameter collecting uses default set of token separators.
std::string includefile = readToken(ToLower); // nazwa pliku std::string includefile = readToken(ToLower); // nazwa pliku
if( ( true == LoadTraction ) if( ( true == LoadTraction )
|| ( ( includefile.find( "tr/" ) == std::string::npos ) || ( ( includefile.find( "tr/" ) == std::string::npos )
&& ( includefile.find( "tra/" ) == std::string::npos ) ) ) { && ( includefile.find( "tra/" ) == std::string::npos ) ) ) {
// get parameter list for the child parser mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( *this ) );
std::vector<std::string> includeparameters;
std::string parameter = readToken( false ); // w parametrach nie zmniejszamy
while( ( parameter.empty() == false )
&& ( parameter != "end" ) ) {
includeparameters.emplace_back( parameter );
parameter = readToken( false );
}
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, includeparameters );
mIncludeParser->autoclear( m_autoclear ); mIncludeParser->autoclear( m_autoclear );
if( mIncludeParser->mSize <= 0 ) { if( mIncludeParser->mSize <= 0 ) {
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" ); ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
@@ -259,10 +250,37 @@ std::string cParser::readToken( bool ToLower, const char *Break ) {
} }
token = readToken(ToLower, Break); token = readToken(ToLower, Break);
} }
else if( ( std::strcmp( Break, "\n\r" ) == 0 ) && ( token.compare( 0, 7, "include" ) == 0 ) ) {
// HACK: if the parser reads full lines we expect this line to contain entire include directive, to make parsing easier
cParser includeparser( token.substr( 7 ) );
std::string includefile = includeparser.readToken( ToLower ); // nazwa pliku
if( ( true == LoadTraction )
|| ( ( includefile.find( "tr/" ) == std::string::npos )
&& ( includefile.find( "tra/" ) == std::string::npos ) ) ) {
mIncludeParser = std::make_shared<cParser>( includefile, buffer_FILE, mPath, LoadTraction, readParameters( includeparser ) );
mIncludeParser->autoclear( m_autoclear );
if( mIncludeParser->mSize <= 0 ) {
ErrorLog( "Bad include: can't open file \"" + includefile + "\"" );
}
}
token = readToken( ToLower, Break );
}
// all done // all done
return token; return token;
} }
std::vector<std::string> cParser::readParameters( cParser &Input ) {
std::vector<std::string> includeparameters;
std::string parameter = Input.readToken( false ); // w parametrach nie zmniejszamy
while( ( parameter.empty() == false )
&& ( parameter != "end" ) ) {
includeparameters.emplace_back( parameter );
parameter = Input.readToken( false );
}
return includeparameters;
}
std::string cParser::readQuotes(char const Quote) { // read the stream until specified char or stream end std::string cParser::readQuotes(char const Quote) { // read the stream until specified char or stream end
std::string token = ""; std::string token = "";
char c { 0 }; char c { 0 };

View File

@@ -89,6 +89,7 @@ class cParser //: public std::stringstream
private: private:
// methods: // methods:
std::string readToken(bool ToLower = true, const char *Break = "\n\r\t ;"); std::string readToken(bool ToLower = true, const char *Break = "\n\r\t ;");
std::vector<std::string> readParameters( cParser &Input );
std::string readQuotes( char const Quote = '\"' ); std::string readQuotes( char const Quote = '\"' );
void skipComment( std::string const &Endmark ); void skipComment( std::string const &Endmark );
bool findQuotes( std::string &String ); bool findQuotes( std::string &String );

View File

@@ -105,7 +105,7 @@ uart_input::recall_bindings() {
{ "value", input_type_t::value } }; { "value", input_type_t::value } };
// NOTE: to simplify things we expect one entry per line, and whole entry in one line // NOTE: to simplify things we expect one entry per line, and whole entry in one line
while( true == bindingparser.getTokens( 1, true, "\n" ) ) { while( true == bindingparser.getTokens( 1, true, "\n\r" ) ) {
std::string bindingentry; std::string bindingentry;
bindingparser >> bindingentry; bindingparser >> bindingentry;

View File

@@ -1,5 +1,5 @@
#pragma once #pragma once
#define VERSION_MAJOR 20 #define VERSION_MAJOR 20
#define VERSION_MINOR 615 #define VERSION_MINOR 630
#define VERSION_REVISION 0 #define VERSION_REVISION 0