openddl-parser: latest greatest.
Contains fix for https://github.com/kimkulling/openddl-parser/issues/10 and https://github.com/kimkulling/openddl-parser/issues/13pull/511/head
parent
23b3728254
commit
d19a677f88
|
@ -190,6 +190,8 @@ bool OpenDDLParser::parse() {
|
|||
|
||||
normalizeBuffer( m_buffer );
|
||||
|
||||
std::cout << &m_buffer[0] << std::endl;
|
||||
|
||||
m_context = new Context;
|
||||
m_context->m_root = DDLNode::create( "root", "", ddl_nullptr );
|
||||
pushNode( m_context->m_root );
|
||||
|
@ -230,7 +232,7 @@ char *OpenDDLParser::parseHeader( char *in, char *end ) {
|
|||
dumpId( id );
|
||||
#endif // DEBUG_HEADER_NAME
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
Property *first( ddl_nullptr );
|
||||
if( ddl_nullptr != id ) {
|
||||
if( *in == '(' ) {
|
||||
|
@ -238,7 +240,7 @@ char *OpenDDLParser::parseHeader( char *in, char *end ) {
|
|||
Property *prop( ddl_nullptr ), *prev( ddl_nullptr );
|
||||
while( *in != ')' && in != end ) {
|
||||
in = OpenDDLParser::parseProperty( in, end, &prop );
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
|
||||
if( *in != ',' && *in != ')' ) {
|
||||
logInvalidTokenError( in, ")", m_logCallback );
|
||||
|
@ -288,21 +290,20 @@ char *OpenDDLParser::parseStructure( char *in, char *end ) {
|
|||
}
|
||||
|
||||
bool error( false );
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in == '{' ) {
|
||||
// loop over all children ( data and nodes )
|
||||
do {
|
||||
in = parseStructureBody( in, end, error );
|
||||
} while ( *in != '}' );
|
||||
in++;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
in++;
|
||||
logInvalidTokenError( in, std::string( Grammar::OpenBracketToken ), m_logCallback );
|
||||
error = true;
|
||||
return in;
|
||||
}
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
|
||||
// pop node from stack after successful parsing
|
||||
if( !error ) {
|
||||
|
@ -341,12 +342,13 @@ char *OpenDDLParser::parseStructureBody( char *in, char *end, bool &error ) {
|
|||
in++;
|
||||
}
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
Value::ValueType type( Value::ddl_none );
|
||||
size_t arrayLen( 0 );
|
||||
in = OpenDDLParser::parsePrimitiveDataType( in, end, type, arrayLen );
|
||||
if( Value::ddl_none != type ) {
|
||||
in = getNextToken( in, end );
|
||||
// parse a primitive data type
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in == '{' ) {
|
||||
Reference *refs( ddl_nullptr );
|
||||
DataArrayList *dtArrayList( ddl_nullptr );
|
||||
|
@ -365,13 +367,14 @@ char *OpenDDLParser::parseStructureBody( char *in, char *end, bool &error ) {
|
|||
}
|
||||
}
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in != '}' ) {
|
||||
logInvalidTokenError( in, std::string( Grammar::CloseBracketToken ), m_logCallback );
|
||||
} else {
|
||||
//in++;
|
||||
}
|
||||
} else {
|
||||
// parse a complex data type
|
||||
in = parseNextNode( in, end );
|
||||
}
|
||||
|
||||
|
@ -429,15 +432,16 @@ void OpenDDLParser::normalizeBuffer( std::vector<char> &buffer) {
|
|||
for( size_t readIdx = 0; readIdx<len; ++readIdx ) {
|
||||
char *c( &buffer[readIdx] );
|
||||
// check for a comment
|
||||
if( !isComment<char>( c, end ) ) {
|
||||
if( !isComment<char>( c, end ) && !isNewLine( *c ) ) {
|
||||
newBuffer.push_back( buffer[ readIdx ] );
|
||||
} else {
|
||||
readIdx++;
|
||||
// skip the comment and the rest of the line
|
||||
while( !isEndofLine( buffer[ readIdx ] ) ) {
|
||||
if( isComment<char>( c, end ) ) {
|
||||
readIdx++;
|
||||
// skip the comment and the rest of the line
|
||||
while( !isEndofLine( buffer[ readIdx ] ) ) {
|
||||
readIdx++;
|
||||
}
|
||||
}
|
||||
newBuffer.push_back( '\n' );
|
||||
}
|
||||
}
|
||||
buffer = newBuffer;
|
||||
|
@ -450,7 +454,7 @@ char *OpenDDLParser::parseName( char *in, char *end, Name **name ) {
|
|||
}
|
||||
|
||||
// ignore blanks
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in != '$' && *in != '%' ) {
|
||||
return in;
|
||||
}
|
||||
|
@ -480,7 +484,7 @@ char *OpenDDLParser::parseIdentifier( char *in, char *end, Identifier **id ) {
|
|||
}
|
||||
|
||||
// ignore blanks
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
|
||||
// staring with a number is forbidden
|
||||
if( isNumeric<const char>( *in ) ) {
|
||||
|
@ -521,7 +525,7 @@ char *OpenDDLParser::parsePrimitiveDataType( char *in, char *end, Value::ValueTy
|
|||
}
|
||||
|
||||
if( Value::ddl_none == type ) {
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
return in;
|
||||
} else {
|
||||
in += prim_len;
|
||||
|
@ -582,7 +586,7 @@ char *OpenDDLParser::parseBooleanLiteral( char *in, char *end, Value **boolean )
|
|||
return in;
|
||||
}
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
char *start( in );
|
||||
size_t len( 0 );
|
||||
while( !isSeparator( *in ) && in != end ) {
|
||||
|
@ -617,7 +621,7 @@ char *OpenDDLParser::parseIntegerLiteral( char *in, char *end, Value **integer,
|
|||
return in;
|
||||
}
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
char *start( in );
|
||||
while( !isSeparator( *in ) && in != end ) {
|
||||
in++;
|
||||
|
@ -653,7 +657,7 @@ char *OpenDDLParser::parseFloatingLiteral( char *in, char *end, Value **floating
|
|||
return in;
|
||||
}
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
char *start( in );
|
||||
while( !isSeparator( *in ) && in != end ) {
|
||||
in++;
|
||||
|
@ -686,7 +690,7 @@ char *OpenDDLParser::parseStringLiteral( char *in, char *end, Value **stringData
|
|||
return in;
|
||||
}
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
size_t len( 0 );
|
||||
char *start( in );
|
||||
if( *start == '\"' ) {
|
||||
|
@ -719,7 +723,7 @@ char *OpenDDLParser::parseHexaLiteral( char *in, char *end, Value **data ) {
|
|||
return in;
|
||||
}
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in != '0' ) {
|
||||
return in;
|
||||
}
|
||||
|
@ -765,11 +769,11 @@ char *OpenDDLParser::parseProperty( char *in, char *end, Property **prop ) {
|
|||
return in;
|
||||
}
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
Identifier *id( ddl_nullptr );
|
||||
in = parseIdentifier( in, end, &id );
|
||||
if( ddl_nullptr != id ) {
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in == '=' ) {
|
||||
in++;
|
||||
in = getNextToken( in, end );
|
||||
|
@ -805,13 +809,13 @@ char *OpenDDLParser::parseDataList( char *in, char *end, Value **data, size_t &n
|
|||
return in;
|
||||
}
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in == '{' ) {
|
||||
in++;
|
||||
Value *current( ddl_nullptr ), *prev( ddl_nullptr );
|
||||
while( '}' != *in ) {
|
||||
current = ddl_nullptr;
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
if( isInteger( in, end ) ) {
|
||||
in = parseIntegerLiteral( in, end, ¤t );
|
||||
} else if( isFloat( in, end ) ) {
|
||||
|
@ -858,7 +862,7 @@ char *OpenDDLParser::parseDataArrayList( char *in, char *end, DataArrayList **da
|
|||
return in;
|
||||
}
|
||||
|
||||
in = getNextToken( in, end );
|
||||
in = lookForNextToken( in, end );
|
||||
if( *in == Grammar::OpenBracketToken[ 0 ] ) {
|
||||
in++;
|
||||
Value *current( ddl_nullptr );
|
||||
|
@ -882,6 +886,8 @@ char *OpenDDLParser::parseDataArrayList( char *in, char *end, DataArrayList **da
|
|||
}
|
||||
}
|
||||
} while( ',' == *in && in != end );
|
||||
in = lookForNextToken( in, end );
|
||||
in++;
|
||||
}
|
||||
|
||||
return in;
|
||||
|
|
|
@ -43,13 +43,26 @@ struct Property;
|
|||
|
||||
template<class T>
|
||||
inline
|
||||
T *getNextToken( T *in, T *end ) {
|
||||
T *lookForNextToken( T *in, T *end ) {
|
||||
while( ( isSpace( *in ) || isNewLine( *in ) || ',' == *in ) && ( in != end ) ) {
|
||||
in++;
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
inline
|
||||
T *getNextToken( T *in, T *end ) {
|
||||
T *tmp( in );
|
||||
while( ( isSpace( *in ) || isNewLine( *in ) || ',' == *in ) && ( in != end ) ) {
|
||||
in++;
|
||||
}
|
||||
if( tmp == in ) {
|
||||
in++;
|
||||
}
|
||||
return in;
|
||||
}
|
||||
|
||||
/// @brief Defines the log severity.
|
||||
enum LogSeverity {
|
||||
ddl_debug_msg = 0, ///< Debug message, for debugging
|
||||
|
|
Loading…
Reference in New Issue