2015-01-31 10:07:48 +00:00
|
|
|
/*-----------------------------------------------------------------------------------------------
|
|
|
|
The MIT License (MIT)
|
|
|
|
|
2015-04-16 09:09:54 +00:00
|
|
|
Copyright (c) 2014-2015 Kim Kulling
|
2015-01-31 10:07:48 +00:00
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
this software and associated documentation files (the "Software"), to deal in
|
|
|
|
the Software without restriction, including without limitation the rights to
|
|
|
|
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in all
|
|
|
|
copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
-----------------------------------------------------------------------------------------------*/
|
|
|
|
#include <openddlparser/OpenDDLParser.h>
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <algorithm>
|
2015-03-19 11:34:11 +00:00
|
|
|
#include <math.h>
|
2015-01-31 10:07:48 +00:00
|
|
|
|
|
|
|
#ifdef _WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
#endif // _WIN32
|
|
|
|
|
|
|
|
#define DEBUG_HEADER_NAME
|
|
|
|
|
|
|
|
BEGIN_ODDLPARSER_NS
|
|
|
|
|
|
|
|
static const char *Version = "0.1.0";
|
|
|
|
|
2015-03-09 09:17:23 +00:00
|
|
|
namespace Grammar {
|
|
|
|
static const char *OpenBracketToken = "{";
|
|
|
|
static const char *CloseBracketToken = "}";
|
|
|
|
static const char *OpenPropertyToken = "(";
|
|
|
|
static const char *ClosePropertyToken = ")";
|
|
|
|
static const char *BoolTrue = "true";
|
|
|
|
static const char *BoolFalse = "false";
|
|
|
|
static const char *RefToken = "ref";
|
2015-04-14 10:04:39 +00:00
|
|
|
static const char *CommaSeparator = ",";
|
2015-03-09 09:17:23 +00:00
|
|
|
|
|
|
|
static const char* PrimitiveTypeToken[ Value::ddl_types_max ] = {
|
|
|
|
"bool",
|
|
|
|
"int8",
|
|
|
|
"int16",
|
|
|
|
"int32",
|
|
|
|
"int64",
|
|
|
|
"unsigned_int8",
|
|
|
|
"unsigned_int16",
|
|
|
|
"unsigned_int32",
|
|
|
|
"unsigned_int64",
|
|
|
|
"half",
|
|
|
|
"float",
|
|
|
|
"double",
|
|
|
|
"string",
|
|
|
|
"ref"
|
|
|
|
};
|
|
|
|
} // Namespace Grammar
|
|
|
|
|
2015-01-31 10:07:48 +00:00
|
|
|
|
2015-03-16 19:34:42 +00:00
|
|
|
static void logInvalidTokenError( char *in, const std::string &exp, OpenDDLParser::logCallback callback ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
std::stringstream stream;
|
|
|
|
stream << "Invalid token " << *in << ", " << exp << " expected." << std::endl;
|
|
|
|
callback( ddl_error_msg, stream.str() );
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isIntegerType( Value::ValueType integerType ) {
|
2015-03-09 09:17:23 +00:00
|
|
|
if( integerType != Value::ddl_int8 && integerType != Value::ddl_int16 &&
|
|
|
|
integerType != Value::ddl_int32 && integerType != Value::ddl_int64 ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-01-31 20:23:50 +00:00
|
|
|
static DDLNode *createDDLNode( Identifier *id, OpenDDLParser *parser ) {
|
2015-03-19 11:07:16 +00:00
|
|
|
if( ddl_nullptr == id || ddl_nullptr == parser ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
return ddl_nullptr;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const std::string type( id->m_buffer );
|
|
|
|
DDLNode *parent( parser->top() );
|
|
|
|
DDLNode *node = DDLNode::create( type, "", parent );
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void logMessage( LogSeverity severity, const std::string &msg ) {
|
|
|
|
std::string log;
|
|
|
|
if( ddl_debug_msg == severity ) {
|
|
|
|
log += "Debug:";
|
|
|
|
} else if( ddl_info_msg == severity ) {
|
|
|
|
log += "Info :";
|
|
|
|
} else if( ddl_warn_msg == severity ) {
|
|
|
|
log += "Warn :";
|
|
|
|
} else if( ddl_error_msg == severity ) {
|
|
|
|
log += "Error:";
|
|
|
|
} else {
|
|
|
|
log += "None :";
|
|
|
|
}
|
|
|
|
|
|
|
|
log += msg;
|
|
|
|
std::cout << log;
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenDDLParser::OpenDDLParser()
|
|
|
|
: m_logCallback( logMessage )
|
2015-02-07 11:47:53 +00:00
|
|
|
, m_buffer()
|
2015-01-31 10:07:48 +00:00
|
|
|
, m_stack()
|
2015-01-31 10:46:13 +00:00
|
|
|
, m_context( ddl_nullptr ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
// empty
|
|
|
|
}
|
|
|
|
|
2015-02-07 11:47:53 +00:00
|
|
|
OpenDDLParser::OpenDDLParser( char *buffer, size_t len )
|
2015-01-31 10:07:48 +00:00
|
|
|
: m_logCallback( &logMessage )
|
2015-02-07 11:47:53 +00:00
|
|
|
, m_buffer()
|
2015-01-31 10:46:13 +00:00
|
|
|
, m_context( ddl_nullptr ) {
|
2015-02-07 11:47:53 +00:00
|
|
|
if( 0 != len ) {
|
|
|
|
setBuffer( buffer, len );
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenDDLParser::~OpenDDLParser() {
|
|
|
|
clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenDDLParser::setLogCallback( logCallback callback ) {
|
2015-03-19 11:07:16 +00:00
|
|
|
if( ddl_nullptr != callback ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
// install user-specific log callback
|
|
|
|
m_logCallback = callback;
|
|
|
|
} else {
|
|
|
|
// install default log callback
|
|
|
|
m_logCallback = &logMessage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
OpenDDLParser::logCallback OpenDDLParser::getLogCallback() const {
|
|
|
|
return m_logCallback;
|
|
|
|
}
|
|
|
|
|
2015-02-07 11:47:53 +00:00
|
|
|
void OpenDDLParser::setBuffer( char *buffer, size_t len ) {
|
|
|
|
clear();
|
|
|
|
if( 0 == len ) {
|
|
|
|
return;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2015-02-07 11:47:53 +00:00
|
|
|
m_buffer.resize( len );
|
|
|
|
::memcpy(&m_buffer[ 0 ], buffer, len );
|
|
|
|
}
|
|
|
|
|
|
|
|
void OpenDDLParser::setBuffer( const std::vector<char> &buffer ) {
|
|
|
|
clear();
|
|
|
|
m_buffer.resize( buffer.size() );
|
|
|
|
std::copy( buffer.begin(), buffer.end(), m_buffer.begin() );
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2015-02-07 11:47:53 +00:00
|
|
|
const char *OpenDDLParser::getBuffer() const {
|
|
|
|
if( m_buffer.empty() ) {
|
|
|
|
return ddl_nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return &m_buffer[ 0 ];
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t OpenDDLParser::getBufferSize() const {
|
2015-02-07 11:47:53 +00:00
|
|
|
return m_buffer.size();
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void OpenDDLParser::clear() {
|
2015-02-07 11:47:53 +00:00
|
|
|
m_buffer.resize( 0 );
|
2015-01-31 10:07:48 +00:00
|
|
|
if( m_context ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
m_context->m_root = ddl_nullptr;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DDLNode::releaseNodes();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OpenDDLParser::parse() {
|
2015-02-07 11:47:53 +00:00
|
|
|
if( m_buffer.empty() ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-02-07 11:47:53 +00:00
|
|
|
normalizeBuffer( m_buffer );
|
2015-01-31 10:07:48 +00:00
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
std::cout << &m_buffer[0] << std::endl;
|
|
|
|
|
2015-01-31 10:07:48 +00:00
|
|
|
m_context = new Context;
|
2015-01-31 10:46:13 +00:00
|
|
|
m_context->m_root = DDLNode::create( "root", "", ddl_nullptr );
|
2015-01-31 10:07:48 +00:00
|
|
|
pushNode( m_context->m_root );
|
|
|
|
|
|
|
|
// do the main parsing
|
|
|
|
char *current( &m_buffer[ 0 ] );
|
2015-02-07 11:47:53 +00:00
|
|
|
char *end( &m_buffer[ m_buffer.size() - 1 ] + 1 );
|
|
|
|
size_t pos( current - &m_buffer[ 0 ] );
|
|
|
|
while( pos < m_buffer.size() ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
current = parseNextNode( current, end );
|
2015-02-07 11:47:53 +00:00
|
|
|
pos = current - &m_buffer[ 0 ];
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseNextNode( char *in, char *end ) {
|
|
|
|
in = parseHeader( in, end );
|
|
|
|
in = parseStructure( in, end );
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-09 09:17:23 +00:00
|
|
|
static void dumpId( Identifier *id ) {
|
|
|
|
if( ddl_nullptr != id ) {
|
|
|
|
std::cout << id->m_buffer << std::endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-31 10:07:48 +00:00
|
|
|
char *OpenDDLParser::parseHeader( char *in, char *end ) {
|
2015-03-19 11:14:17 +00:00
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-01-31 10:46:13 +00:00
|
|
|
Identifier *id( ddl_nullptr );
|
2015-01-31 10:07:48 +00:00
|
|
|
in = OpenDDLParser::parseIdentifier( in, end, &id );
|
|
|
|
|
|
|
|
#ifdef DEBUG_HEADER_NAME
|
2015-03-09 09:17:23 +00:00
|
|
|
dumpId( id );
|
2015-01-31 10:07:48 +00:00
|
|
|
#endif // DEBUG_HEADER_NAME
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:46:13 +00:00
|
|
|
Property *first( ddl_nullptr );
|
|
|
|
if( ddl_nullptr != id ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
if( *in == '(' ) {
|
|
|
|
in++;
|
2015-01-31 10:46:13 +00:00
|
|
|
Property *prop( ddl_nullptr ), *prev( ddl_nullptr );
|
2015-01-31 10:07:48 +00:00
|
|
|
while( *in != ')' && in != end ) {
|
2015-03-09 09:17:23 +00:00
|
|
|
in = OpenDDLParser::parseProperty( in, end, &prop );
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
|
|
|
|
if( *in != ',' && *in != ')' ) {
|
|
|
|
logInvalidTokenError( in, ")", m_logCallback );
|
|
|
|
return in;
|
|
|
|
}
|
2015-03-09 09:17:23 +00:00
|
|
|
|
2015-01-31 10:46:13 +00:00
|
|
|
if( ddl_nullptr != prop && *in != ',' ) {
|
|
|
|
if( ddl_nullptr == first ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
first = prop;
|
|
|
|
}
|
2015-01-31 10:46:13 +00:00
|
|
|
if( ddl_nullptr != prev ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
prev->m_next = prop;
|
|
|
|
}
|
|
|
|
prev = prop;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// store the node
|
2015-01-31 20:23:50 +00:00
|
|
|
DDLNode *node( createDDLNode( id, this ) );
|
2015-03-19 11:14:17 +00:00
|
|
|
if( ddl_nullptr != node ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
pushNode( node );
|
|
|
|
} else {
|
|
|
|
std::cerr << "nullptr returned by creating DDLNode." << std::endl;
|
|
|
|
}
|
|
|
|
|
2015-02-10 18:31:23 +00:00
|
|
|
// set the properties
|
|
|
|
if( ddl_nullptr != first ) {
|
|
|
|
node->setProperties( first );
|
|
|
|
}
|
|
|
|
|
2015-01-31 10:46:13 +00:00
|
|
|
Name *name( ddl_nullptr );
|
2015-01-31 10:07:48 +00:00
|
|
|
in = OpenDDLParser::parseName( in, end, &name );
|
2015-01-31 10:46:13 +00:00
|
|
|
if( ddl_nullptr != name ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
const std::string nodeName( name->m_id->m_buffer );
|
|
|
|
node->setName( nodeName );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseStructure( char *in, char *end ) {
|
2015-03-19 11:14:17 +00:00
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-02-10 18:31:23 +00:00
|
|
|
bool error( false );
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
if( *in == '{' ) {
|
2015-03-20 20:55:19 +00:00
|
|
|
// loop over all children ( data and nodes )
|
2015-03-09 09:17:23 +00:00
|
|
|
do {
|
|
|
|
in = parseStructureBody( in, end, error );
|
|
|
|
} while ( *in != '}' );
|
2015-01-31 10:07:48 +00:00
|
|
|
in++;
|
2015-03-25 18:55:39 +00:00
|
|
|
} else {
|
2015-01-31 10:07:48 +00:00
|
|
|
in++;
|
2015-03-16 19:34:42 +00:00
|
|
|
logInvalidTokenError( in, std::string( Grammar::OpenBracketToken ), m_logCallback );
|
2015-02-10 18:31:23 +00:00
|
|
|
error = true;
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-02-10 18:31:23 +00:00
|
|
|
|
|
|
|
// pop node from stack after successful parsing
|
|
|
|
if( !error ) {
|
|
|
|
popNode();
|
|
|
|
}
|
2015-01-31 10:07:48 +00:00
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-09 09:17:23 +00:00
|
|
|
static void setNodeValues( DDLNode *currentNode, Value *values ) {
|
|
|
|
if( ddl_nullptr != values ){
|
|
|
|
if( ddl_nullptr != currentNode ) {
|
|
|
|
currentNode->setValue( values );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setNodeReferences( DDLNode *currentNode, Reference *refs ) {
|
|
|
|
if( ddl_nullptr != refs ) {
|
|
|
|
if( ddl_nullptr != currentNode ) {
|
|
|
|
currentNode->setReferences( refs );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void setNodeDataArrayList( DDLNode *currentNode, DataArrayList *dtArrayList ) {
|
|
|
|
if( ddl_nullptr != dtArrayList ) {
|
|
|
|
if( ddl_nullptr != currentNode ) {
|
|
|
|
currentNode->setDataArrayList( dtArrayList );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseStructureBody( char *in, char *end, bool &error ) {
|
|
|
|
if( !isNumeric( *in ) && !isCharacter( *in ) ) {
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-03-09 09:17:23 +00:00
|
|
|
Value::ValueType type( Value::ddl_none );
|
|
|
|
size_t arrayLen( 0 );
|
|
|
|
in = OpenDDLParser::parsePrimitiveDataType( in, end, type, arrayLen );
|
|
|
|
if( Value::ddl_none != type ) {
|
2015-03-25 18:55:39 +00:00
|
|
|
// parse a primitive data type
|
|
|
|
in = lookForNextToken( in, end );
|
2015-03-09 09:17:23 +00:00
|
|
|
if( *in == '{' ) {
|
|
|
|
Reference *refs( ddl_nullptr );
|
|
|
|
DataArrayList *dtArrayList( ddl_nullptr );
|
|
|
|
Value *values( ddl_nullptr );
|
|
|
|
if( 1 == arrayLen ) {
|
2015-03-23 17:46:41 +00:00
|
|
|
size_t numRefs( 0 ), numValues( 0 );
|
|
|
|
in = parseDataList( in, end, &values, numValues, &refs, numRefs );
|
2015-03-09 09:17:23 +00:00
|
|
|
setNodeValues( top(), values );
|
|
|
|
setNodeReferences( top(), refs );
|
|
|
|
} else if( arrayLen > 1 ) {
|
|
|
|
in = parseDataArrayList( in, end, &dtArrayList );
|
|
|
|
setNodeDataArrayList( top(), dtArrayList );
|
|
|
|
} else {
|
|
|
|
std::cerr << "0 for array is invalid." << std::endl;
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-03-09 09:17:23 +00:00
|
|
|
if( *in != '}' ) {
|
2015-03-16 19:34:42 +00:00
|
|
|
logInvalidTokenError( in, std::string( Grammar::CloseBracketToken ), m_logCallback );
|
2015-03-09 09:17:23 +00:00
|
|
|
} else {
|
|
|
|
//in++;
|
|
|
|
}
|
|
|
|
} else {
|
2015-03-25 18:55:39 +00:00
|
|
|
// parse a complex data type
|
2015-03-09 09:17:23 +00:00
|
|
|
in = parseNextNode( in, end );
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-01-31 10:07:48 +00:00
|
|
|
void OpenDDLParser::pushNode( DDLNode *node ) {
|
2015-03-19 11:14:17 +00:00
|
|
|
if( ddl_nullptr == node ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_stack.push_back( node );
|
|
|
|
}
|
|
|
|
|
|
|
|
DDLNode *OpenDDLParser::popNode() {
|
|
|
|
if( m_stack.empty() ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
return ddl_nullptr;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DDLNode *topNode( top() );
|
|
|
|
m_stack.pop_back();
|
|
|
|
|
|
|
|
return topNode;
|
|
|
|
}
|
|
|
|
|
|
|
|
DDLNode *OpenDDLParser::top() {
|
|
|
|
if( m_stack.empty() ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
return ddl_nullptr;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
DDLNode *top( m_stack.back() );
|
|
|
|
return top;
|
|
|
|
}
|
|
|
|
|
|
|
|
DDLNode *OpenDDLParser::getRoot() const {
|
2015-03-19 11:14:17 +00:00
|
|
|
if( ddl_nullptr == m_context ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
return ddl_nullptr;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_context->m_root;
|
|
|
|
}
|
|
|
|
|
|
|
|
Context *OpenDDLParser::getContext() const {
|
|
|
|
return m_context;
|
|
|
|
}
|
|
|
|
|
2015-02-07 11:47:53 +00:00
|
|
|
void OpenDDLParser::normalizeBuffer( std::vector<char> &buffer) {
|
|
|
|
if( buffer.empty() ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-02-07 11:47:53 +00:00
|
|
|
std::vector<char> newBuffer;
|
|
|
|
const size_t len( buffer.size() );
|
|
|
|
char *end( &buffer[ len-1 ] + 1 );
|
2015-01-31 10:07:48 +00:00
|
|
|
for( size_t readIdx = 0; readIdx<len; ++readIdx ) {
|
|
|
|
char *c( &buffer[readIdx] );
|
|
|
|
// check for a comment
|
2015-03-25 18:55:39 +00:00
|
|
|
if( !isComment<char>( c, end ) && !isNewLine( *c ) ) {
|
2015-02-07 11:47:53 +00:00
|
|
|
newBuffer.push_back( buffer[ readIdx ] );
|
2015-01-31 10:07:48 +00:00
|
|
|
} else {
|
2015-03-25 18:55:39 +00:00
|
|
|
if( isComment<char>( c, end ) ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
readIdx++;
|
2015-03-25 18:55:39 +00:00
|
|
|
// skip the comment and the rest of the line
|
|
|
|
while( !isEndofLine( buffer[ readIdx ] ) ) {
|
|
|
|
readIdx++;
|
|
|
|
}
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-02-07 11:47:53 +00:00
|
|
|
buffer = newBuffer;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseName( char *in, char *end, Name **name ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*name = ddl_nullptr;
|
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore blanks
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
if( *in != '$' && *in != '%' ) {
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
NameType ntype( GlobalName );
|
|
|
|
if( *in == '%' ) {
|
|
|
|
ntype = LocalName;
|
|
|
|
}
|
|
|
|
|
2015-01-31 10:46:13 +00:00
|
|
|
Name *currentName( ddl_nullptr );
|
|
|
|
Identifier *id( ddl_nullptr );
|
2015-01-31 10:07:48 +00:00
|
|
|
in = parseIdentifier( in, end, &id );
|
|
|
|
if( id ) {
|
|
|
|
currentName = new Name( ntype, id );
|
|
|
|
if( currentName ) {
|
|
|
|
*name = currentName;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseIdentifier( char *in, char *end, Identifier **id ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*id = ddl_nullptr;
|
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ignore blanks
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
|
|
|
|
// staring with a number is forbidden
|
|
|
|
if( isNumeric<const char>( *in ) ) {
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
// get size of id
|
|
|
|
size_t idLen( 0 );
|
|
|
|
char *start( in );
|
2015-03-20 20:55:19 +00:00
|
|
|
while( !isSeparator( *in ) && !isNewLine( *in ) && ( in != end ) && *in != '(' && *in != ')' ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
in++;
|
|
|
|
idLen++;
|
|
|
|
}
|
|
|
|
|
|
|
|
const size_t len( idLen + 1 );
|
|
|
|
Identifier *newId = new Identifier( len, new char[ len ] );
|
|
|
|
::strncpy( newId->m_buffer, start, newId->m_len-1 );
|
|
|
|
newId->m_buffer[ newId->m_len - 1 ] = '\0';
|
|
|
|
*id = newId;
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parsePrimitiveDataType( char *in, char *end, Value::ValueType &type, size_t &len ) {
|
|
|
|
type = Value::ddl_none;
|
|
|
|
len = 0;
|
2015-01-31 10:46:13 +00:00
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-09 09:17:23 +00:00
|
|
|
size_t prim_len( 0 );
|
2015-01-31 10:07:48 +00:00
|
|
|
for( unsigned int i = 0; i < Value::ddl_types_max; i++ ) {
|
2015-03-09 09:17:23 +00:00
|
|
|
prim_len = strlen( Grammar::PrimitiveTypeToken[ i ] );
|
|
|
|
if( 0 == strncmp( in, Grammar::PrimitiveTypeToken[ i ], prim_len ) ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
type = ( Value::ValueType ) i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( Value::ddl_none == type ) {
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
} else {
|
2015-03-09 09:17:23 +00:00
|
|
|
in += prim_len;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ok( true );
|
|
|
|
if( *in == '[' ) {
|
|
|
|
ok = false;
|
|
|
|
in++;
|
|
|
|
char *start( in );
|
|
|
|
while ( in != end ) {
|
|
|
|
in++;
|
|
|
|
if( *in == ']' ) {
|
|
|
|
len = atoi( start );
|
|
|
|
ok = true;
|
|
|
|
in++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
len = 1;
|
|
|
|
}
|
|
|
|
if( !ok ) {
|
|
|
|
type = Value::ddl_none;
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseReference( char *in, char *end, std::vector<Name*> &names ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-01-31 10:46:13 +00:00
|
|
|
Name *nextName( ddl_nullptr );
|
2015-01-31 10:07:48 +00:00
|
|
|
in = parseName( in, end, &nextName );
|
|
|
|
if( nextName ) {
|
|
|
|
names.push_back( nextName );
|
|
|
|
}
|
2015-03-09 09:17:23 +00:00
|
|
|
while( ',' == *in ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
in = getNextSeparator( in, end );
|
|
|
|
if( ',' == *in ) {
|
|
|
|
in = parseName( in, end, &nextName );
|
|
|
|
if( nextName ) {
|
|
|
|
names.push_back( nextName );
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseBooleanLiteral( char *in, char *end, Value **boolean ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*boolean = ddl_nullptr;
|
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
char *start( in );
|
|
|
|
size_t len( 0 );
|
|
|
|
while( !isSeparator( *in ) && in != end ) {
|
|
|
|
in++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
len++;
|
2015-03-09 09:17:23 +00:00
|
|
|
int res = ::strncmp( Grammar::BoolTrue, start, strlen( Grammar::BoolTrue ) );
|
2015-01-31 10:07:48 +00:00
|
|
|
if( 0 != res ) {
|
2015-03-09 09:17:23 +00:00
|
|
|
res = ::strncmp( Grammar::BoolFalse, start, strlen( Grammar::BoolFalse ) );
|
2015-01-31 10:07:48 +00:00
|
|
|
if( 0 != res ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*boolean = ddl_nullptr;
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
*boolean = ValueAllocator::allocPrimData( Value::ddl_bool );
|
|
|
|
(*boolean)->setBool( false );
|
|
|
|
} else {
|
|
|
|
*boolean = ValueAllocator::allocPrimData( Value::ddl_bool );
|
|
|
|
(*boolean)->setBool( true );
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseIntegerLiteral( char *in, char *end, Value **integer, Value::ValueType integerType ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*integer = ddl_nullptr;
|
2015-03-19 11:07:16 +00:00
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !isIntegerType( integerType ) ) {
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
char *start( in );
|
|
|
|
while( !isSeparator( *in ) && in != end ) {
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( isNumeric( *start ) ) {
|
|
|
|
const int value( atoi( start ) );
|
|
|
|
*integer = ValueAllocator::allocPrimData( integerType );
|
|
|
|
switch( integerType ) {
|
|
|
|
case Value::ddl_int8:
|
|
|
|
( *integer )->setInt8( (int8) value );
|
|
|
|
break;
|
|
|
|
case Value::ddl_int16:
|
|
|
|
( *integer )->setInt16( ( int16 ) value );
|
|
|
|
break;
|
|
|
|
case Value::ddl_int32:
|
|
|
|
( *integer )->setInt32( ( int32 ) value );
|
|
|
|
break;
|
|
|
|
case Value::ddl_int64:
|
|
|
|
( *integer )->setInt64( ( int64 ) value );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseFloatingLiteral( char *in, char *end, Value **floating ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*floating = ddl_nullptr;
|
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
char *start( in );
|
|
|
|
while( !isSeparator( *in ) && in != end ) {
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse the float value
|
|
|
|
bool ok( false );
|
|
|
|
if( isNumeric( *start ) ) {
|
|
|
|
ok = true;
|
|
|
|
} else {
|
|
|
|
if( *start == '-' ) {
|
|
|
|
if( isNumeric( *(start+1) ) ) {
|
|
|
|
ok = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ok ) {
|
|
|
|
const float value( ( float ) atof( start ) );
|
|
|
|
*floating = ValueAllocator::allocPrimData( Value::ddl_float );
|
|
|
|
( *floating )->setFloat( value );
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseStringLiteral( char *in, char *end, Value **stringData ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*stringData = ddl_nullptr;
|
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
size_t len( 0 );
|
|
|
|
char *start( in );
|
|
|
|
if( *start == '\"' ) {
|
|
|
|
start++;
|
|
|
|
in++;
|
|
|
|
while( *in != '\"' && in != end ) {
|
|
|
|
in++;
|
|
|
|
len++;
|
|
|
|
}
|
|
|
|
|
2015-02-14 15:12:09 +00:00
|
|
|
*stringData = ValueAllocator::allocPrimData( Value::ddl_string, len );
|
2015-01-31 10:07:48 +00:00
|
|
|
::strncpy( ( char* ) ( *stringData )->m_data, start, len );
|
|
|
|
( *stringData )->m_data[len] = '\0';
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void createPropertyWithData( Identifier *id, Value *primData, Property **prop ) {
|
2015-03-19 11:07:16 +00:00
|
|
|
if( ddl_nullptr != primData ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
( *prop ) = new Property( id );
|
|
|
|
( *prop )->m_primData = primData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseHexaLiteral( char *in, char *end, Value **data ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*data = ddl_nullptr;
|
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
if( *in != '0' ) {
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
in++;
|
|
|
|
if( *in != 'x' && *in != 'X' ) {
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
in++;
|
|
|
|
bool ok( true );
|
|
|
|
char *start( in );
|
|
|
|
int pos( 0 );
|
|
|
|
while( !isSeparator( *in ) && in != end ) {
|
|
|
|
if( ( *in < '0' && *in > '9' ) || ( *in < 'a' && *in > 'f' ) || ( *in < 'A' && *in > 'F' ) ) {
|
|
|
|
ok = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos++;
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( !ok ) {
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
int value( 0 );
|
|
|
|
while( pos > 0 ) {
|
2015-04-14 10:04:39 +00:00
|
|
|
int v = hex2Decimal( *start );
|
2015-01-31 10:07:48 +00:00
|
|
|
pos--;
|
2015-04-14 10:04:39 +00:00
|
|
|
value = ( value << 4 ) | v;
|
2015-01-31 10:07:48 +00:00
|
|
|
start++;
|
|
|
|
}
|
|
|
|
|
2015-04-14 10:04:39 +00:00
|
|
|
*data = ValueAllocator::allocPrimData( Value::ddl_unsigned_int64 );
|
|
|
|
if( ddl_nullptr != *data ) {
|
|
|
|
( *data )->setUnsignedInt64( value );
|
|
|
|
}
|
2015-01-31 10:07:48 +00:00
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *OpenDDLParser::parseProperty( char *in, char *end, Property **prop ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*prop = ddl_nullptr;
|
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:46:13 +00:00
|
|
|
Identifier *id( ddl_nullptr );
|
2015-01-31 10:07:48 +00:00
|
|
|
in = parseIdentifier( in, end, &id );
|
2015-03-19 11:14:17 +00:00
|
|
|
if( ddl_nullptr != id ) {
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
if( *in == '=' ) {
|
|
|
|
in++;
|
|
|
|
in = getNextToken( in, end );
|
2015-01-31 10:46:13 +00:00
|
|
|
Value *primData( ddl_nullptr );
|
2015-01-31 10:07:48 +00:00
|
|
|
if( isInteger( in, end ) ) {
|
|
|
|
in = parseIntegerLiteral( in, end, &primData );
|
|
|
|
createPropertyWithData( id, primData, prop );
|
|
|
|
} else if( isFloat( in, end ) ) {
|
|
|
|
in = parseFloatingLiteral( in, end, &primData );
|
|
|
|
createPropertyWithData( id, primData, prop );
|
|
|
|
} else if( isStringLiteral( *in ) ) { // string data
|
|
|
|
in = parseStringLiteral( in, end, &primData );
|
|
|
|
createPropertyWithData( id, primData, prop );
|
|
|
|
} else { // reference data
|
|
|
|
std::vector<Name*> names;
|
|
|
|
in = parseReference( in, end, names );
|
|
|
|
if( !names.empty() ) {
|
|
|
|
Reference *ref = new Reference( names.size(), &names[ 0 ] );
|
|
|
|
( *prop ) = new Property( id );
|
|
|
|
( *prop )->m_ref = ref;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-23 17:46:41 +00:00
|
|
|
char *OpenDDLParser::parseDataList( char *in, char *end, Value **data, size_t &numValues, Reference **refs, size_t &numRefs ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*data = ddl_nullptr;
|
2015-03-23 17:46:41 +00:00
|
|
|
numValues = numRefs = 0;
|
2015-01-31 10:46:13 +00:00
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
if( *in == '{' ) {
|
|
|
|
in++;
|
2015-01-31 10:46:13 +00:00
|
|
|
Value *current( ddl_nullptr ), *prev( ddl_nullptr );
|
2015-01-31 10:07:48 +00:00
|
|
|
while( '}' != *in ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
current = ddl_nullptr;
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-01-31 10:07:48 +00:00
|
|
|
if( isInteger( in, end ) ) {
|
|
|
|
in = parseIntegerLiteral( in, end, ¤t );
|
|
|
|
} else if( isFloat( in, end ) ) {
|
|
|
|
in = parseFloatingLiteral( in, end, ¤t );
|
|
|
|
} else if( isStringLiteral( *in ) ) {
|
|
|
|
in = parseStringLiteral( in, end, ¤t );
|
|
|
|
} else if( isHexLiteral( in, end ) ) {
|
|
|
|
in = parseHexaLiteral( in, end, ¤t );
|
2015-03-09 09:17:23 +00:00
|
|
|
} else { // reference data
|
|
|
|
std::vector<Name*> names;
|
|
|
|
in = parseReference( in, end, names );
|
|
|
|
if( !names.empty() ) {
|
|
|
|
Reference *ref = new Reference( names.size(), &names[ 0 ] );
|
|
|
|
*refs = ref;
|
2015-03-23 17:46:41 +00:00
|
|
|
numRefs = names.size();
|
2015-03-09 09:17:23 +00:00
|
|
|
}
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
2015-01-31 10:46:13 +00:00
|
|
|
if( ddl_nullptr != current ) {
|
|
|
|
if( ddl_nullptr == *data ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
*data = current;
|
|
|
|
prev = current;
|
|
|
|
} else {
|
|
|
|
prev->setNext( current );
|
|
|
|
prev = current;
|
|
|
|
}
|
2015-03-23 17:46:41 +00:00
|
|
|
numValues++;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
in = getNextSeparator( in, end );
|
|
|
|
if( ',' != *in && '}' != *in && !isSpace( *in ) ) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
in++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-04-14 10:04:39 +00:00
|
|
|
static DataArrayList *createDataArrayList( Value *currentValue, size_t numValues ) {
|
2015-03-28 09:50:32 +00:00
|
|
|
DataArrayList *dataList = new DataArrayList;
|
|
|
|
dataList->m_dataList = currentValue;
|
|
|
|
dataList->m_numItems = numValues;
|
|
|
|
|
|
|
|
return dataList;
|
|
|
|
|
|
|
|
}
|
2015-01-31 10:07:48 +00:00
|
|
|
char *OpenDDLParser::parseDataArrayList( char *in, char *end, DataArrayList **dataList ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
*dataList = ddl_nullptr;
|
|
|
|
if( ddl_nullptr == in || in == end ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
2015-03-20 20:55:19 +00:00
|
|
|
if( *in == Grammar::OpenBracketToken[ 0 ] ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
in++;
|
2015-03-28 09:50:32 +00:00
|
|
|
Value *currentValue( ddl_nullptr );
|
2015-03-19 11:07:16 +00:00
|
|
|
Reference *refs( ddl_nullptr );
|
2015-01-31 10:46:13 +00:00
|
|
|
DataArrayList *prev( ddl_nullptr ), *currentDataList( ddl_nullptr );
|
2015-01-31 10:07:48 +00:00
|
|
|
do {
|
2015-03-23 17:46:41 +00:00
|
|
|
size_t numRefs( 0 ), numValues( 0 );
|
2015-03-28 09:50:32 +00:00
|
|
|
currentValue = ddl_nullptr;
|
|
|
|
in = parseDataList( in, end, ¤tValue, numValues, &refs, numRefs );
|
|
|
|
if( ddl_nullptr != currentValue ) {
|
2015-01-31 10:46:13 +00:00
|
|
|
if( ddl_nullptr == prev ) {
|
2015-03-28 09:50:32 +00:00
|
|
|
*dataList = createDataArrayList( currentValue, numValues );
|
2015-01-31 10:07:48 +00:00
|
|
|
prev = *dataList;
|
|
|
|
} else {
|
2015-03-28 09:50:32 +00:00
|
|
|
currentDataList = createDataArrayList( currentValue, numValues );
|
2015-01-31 10:46:13 +00:00
|
|
|
if( ddl_nullptr != prev ) {
|
2015-01-31 10:07:48 +00:00
|
|
|
prev->m_next = currentDataList;
|
|
|
|
prev = currentDataList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-14 10:04:39 +00:00
|
|
|
} while( Grammar::CommaSeparator[ 0 ] == *in && in != end );
|
2015-03-25 18:55:39 +00:00
|
|
|
in = lookForNextToken( in, end );
|
|
|
|
in++;
|
2015-01-31 10:07:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return in;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *OpenDDLParser::getVersion() {
|
|
|
|
return Version;
|
|
|
|
}
|
|
|
|
|
|
|
|
END_ODDLPARSER_NS
|