diff --git a/contrib/openddlparser/include/openddlparser/OpenDDLParser.h b/contrib/openddlparser/include/openddlparser/OpenDDLParser.h new file mode 100644 index 000000000..76c5ca7ef --- /dev/null +++ b/contrib/openddlparser/include/openddlparser/OpenDDLParser.h @@ -0,0 +1,117 @@ +/*----------------------------------------------------------------------------------------------- +The MIT License (MIT) + +Copyright (c) 2014 Kim Kulling + +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. +-----------------------------------------------------------------------------------------------*/ +#pragma once +#ifndef OPENDDLPARSER_OPENDDLPARSER_H_INC +#define OPENDDLPARSER_OPENDDLPARSER_H_INC + +#include +#include +#include +#include + +#include +#include + +BEGIN_ODDLPARSER_NS + +class DDLNode; +class Value; + +struct Identifier; +struct Reference; +struct Property; + +template +inline +T *getNextToken( T *in, T *end ) { + while( ( isSpace( *in ) || isNewLine( *in ) || ',' == *in ) && ( in != end ) ) { + in++; + } + return in; +} + +enum LogSeverity { + ddl_debug_msg = 0, + ddl_info_msg, + ddl_warn_msg, + ddl_error_msg, +}; + +class DLL_ODDLPARSER_EXPORT OpenDDLParser { +public: + typedef void( *logCallback )( LogSeverity severity, const std::string &msg ); + +public: + OpenDDLParser(); + OpenDDLParser( char *buffer, size_t len, bool ownsIt = false ); + ~OpenDDLParser(); + void setLogCallback( logCallback callback ); + logCallback getLogCallback() const; + void setBuffer( char *buffer, size_t len, bool ownsIt = false ); + char *getBuffer() const; + size_t getBufferSize() const; + void clear(); + bool parse(); + char *parseNextNode( char *current, char *end ); + char *parseHeader( char *in, char *end ); + char *parseStructure( char *in, char *end ); + void pushNode( DDLNode *node ); + DDLNode *popNode(); + DDLNode *top(); + DDLNode *getRoot() const; + Context *getContext() const; + +public: // static parser helpers + static void normalizeBuffer( char *buffer, size_t len ); + static char *parseName( char *in, char *end, Name **name ); + static char *parseIdentifier( char *in, char *end, Identifier **id ); + static char *parsePrimitiveDataType( char *in, char *end, Value::ValueType &type, size_t &len ); + static char *parseReference( char *in, char *end, std::vector &names ); + static char *parseBooleanLiteral( char *in, char *end, Value **boolean ); + static char *parseIntegerLiteral( char *in, char *end, Value **integer, Value::ValueType integerType = Value::ddl_int32 ); + static char *parseFloatingLiteral( char *in, char *end, Value **floating ); + static char *parseStringLiteral( char *in, char *end, Value **stringData ); + static char *parseHexaLiteral( char *in, char *end, Value **data ); + static char *parseProperty( char *in, char *end, Property **prop ); + static char *parseDataList( char *in, char *end, Value **data ); + static char *parseDataArrayList( char *in, char *end, DataArrayList **dataList ); + static const char *getVersion(); + +private: + OpenDDLParser( const OpenDDLParser & ); + OpenDDLParser &operator = ( const OpenDDLParser & ); + +private: + logCallback m_logCallback; + bool m_ownsBuffer; + char *m_buffer; + size_t m_len; + //DDLNode *m_root; + typedef std::vector DDLNodeStack; + DDLNodeStack m_stack; + Context *m_context; +}; + +END_ODDLPARSER_NS + +#endif // OPENDDLPARSER_OPENDDLPARSER_H_INC