corelib/include/ebcl/inline/SRDDefinitions.hh

526 lines
12 KiB
C++
Raw Normal View History

/******************************************************************************/
/* SRD - PARSER DEFINITIONS - INLINE CODE *************************************/
/******************************************************************************/
#ifndef _H_EBCL_INLINE_SRDDEFINITIONS
#define _H_EBCL_INLINE_SRDDEFINITIONS
#include <ebcl/SRDDefinitions.hh>
namespace ebcl {
/*= T_SRDEnum ================================================================*/
inline T_SRDEnum::T_SRDEnum( T_String name )
: name_( std::move( name ) ) , index_( 32 , 32 , 32 ) , words_( 32 )
{ }
/*----------------------------------------------------------------------------*/
inline T_SRDEnum& T_SRDEnum::operator<< ( char const* word )
{
return operator<< ( T_String::Pooled( word ) );
}
/*----------------------------------------------------------------------------*/
inline T_String const& T_SRDEnum::name( ) const
{
return name_;
}
inline auto T_SRDEnum::size( ) const
{
return words_.size( );
}
/*----------------------------------------------------------------------------*/
inline T_String const& T_SRDEnum::operator[] ( int index ) const
{
return words_[ index ];
}
inline T_String const& T_SRDEnum::operator[] ( uint32_t index ) const
{
return words_[ index ];
}
/*----------------------------------------------------------------------------*/
inline bool T_SRDEnum::contains( T_String const& word ) const
{
return (*this)[ word ] != T_HashIndex::INVALID_INDEX;
}
inline bool T_SRDEnum::contains( char const* word ) const
{
return (*this)[ word ] != T_HashIndex::INVALID_INDEX;
}
/*= T_SRDInputItem ===========================================================*/
inline T_SRDInputItem::T_ListHelper::T_ListHelper( )
: items( 16 )
{ }
inline T_SRDInputItem::T_ListHelper& T_SRDInputItem::T_ListHelper::operator <<( T_SRDInputItem item )
{
items.add( std::move( item ) );
return *this;
}
/*----------------------------------------------------------------------------*/
inline T_SRDInputItem::T_SRDInputItem( )
: type_( E_SRDInputItem::ALTERNATIVE ) , items_( 32 )
{ }
inline T_SRDInputItem::T_SRDInputItem( T_String wordOrName , bool isWord )
: type_( isWord ? E_SRDInputItem::WORD : E_SRDInputItem::ENUM ) , word_( std::move( wordOrName ) )
{ }
inline T_SRDInputItem::T_SRDInputItem( char const* cString )
: T_SRDInputItem( T_String::Pooled( cString ) , true )
{ }
inline T_SRDInputItem::T_SRDInputItem( E_SRDTokenType type )
: type_( E_SRDInputItem::TOKEN ) , token_( type )
{ }
inline T_SRDInputItem::T_SRDInputItem( uint32_t min , uint32_t max )
: type_( E_SRDInputItem::REPETITION ) , items_( 32 ) , min_( min ) , max_( max )
{
if ( min > max ) {
throw std::invalid_argument( "min > max" );
} else if ( min == 0 && max == 0 ) {
throw std::invalid_argument( "min = max = 0" );
}
}
/*----------------------------------------------------------------------------*/
inline E_SRDInputItem T_SRDInputItem::type( ) const
{
return type_;
}
inline T_String const& T_SRDInputItem::word( ) const
{
return word_;
}
inline E_SRDTokenType T_SRDInputItem::token( ) const
{
return token_;
}
inline T_Array< T_SRDInputItem > T_SRDInputItem::items( ) const
{
return items_;
}
inline uint32_t T_SRDInputItem::min( ) const
{
return min_;
}
inline uint32_t T_SRDInputItem::max( ) const
{
return max_;
}
/*----------------------------------------------------------------------------*/
inline bool T_SRDInputItem::operator ==( T_SRDInputItem const& ) const
{
return false;
}
/*----------------------------------------------------------------------------*/
inline T_Array< T_SRDInputItem >& operator <<(
T_Array< T_SRDInputItem >& items ,
T_SRDInputItem::T_ListHelper& list )
{
items << T_SRDInputItem( E_SRDTokenType::START );
items.addAll( list.items );
items << T_SRDInputItem( E_SRDTokenType::END );
return items;
}
inline T_SRDInputItem& T_SRDInputItem::operator <<( T_ListHelper list )
{
items_ << list;
return *this;
}
/*= T_SRDInputRule ===========================================================*/
inline T_SRDInputRule::T_SetContextExecutor::T_SetContextExecutor( bool exit , F_SRDHandler executor )
: exit( exit ) , executor( executor )
{ }
inline T_SRDInputRule::T_SetContext::T_SetContext( T_String string )
: name( std::move( string ) )
{ }
/*----------------------------------------------------------------------------*/
inline T_SRDInputRule& T_SRDInputRule::operator<< ( F_SRDHandler executor )
{
executor_ = executor;
return *this;
}
inline T_SRDInputRule& T_SRDInputRule::operator<< ( T_SetContextExecutor sce )
{
if ( sce.exit ) {
contextExit_ = sce.executor;
} else {
contextEnter_ = sce.executor;
}
return *this;
}
inline T_SRDInputRule& T_SRDInputRule::operator<< ( T_SetContext sc )
{
context_ = sc.name;
return *this;
}
inline T_SRDInputRule& T_SRDInputRule::operator <<( T_SRDInputItem::T_ListHelper lh )
{
items_ << lh;
return *this;
}
/*----------------------------------------------------------------------------*/
inline F_SRDHandler const& T_SRDInputRule::handler( ) const
{
return executor_;
}
inline T_Array< T_SRDInputItem > const& T_SRDInputRule::rule( ) const
{
return items_;
}
inline T_String const& T_SRDInputRule::context( ) const
{
return context_;
}
inline F_SRDHandler const& T_SRDInputRule::onEnter( ) const
{
return contextEnter_;
}
inline F_SRDHandler const& T_SRDInputRule::onExit( ) const
{
return contextExit_;
}
/*= T_SRDContext =============================================================*/
inline T_String const& T_SRDContext::name( ) const
{
return name_;
}
inline T_String const& T_SRDContext::parent( ) const
{
return parent_;
}
inline T_Array< T_SRDInputRule > const& T_SRDContext::rules( ) const
{
return rules_;
}
/*= T_SRDParserDefs ==========================================================*/
inline T_SRDParserDefs::SetHandler::SetHandler( F_SRDHandler const& handler , bool start )
: handler( handler ) , start( start )
{ }
/*----------------------------------------------------------------------------*/
inline T_SRDParserDefs::T_SRDParserDefs( char const* name )
: T_SRDParserDefs( T_String::Pooled( name ) )
{ }
/*----------------------------------------------------------------------------*/
inline T_String const& T_SRDParserDefs::defaultContext( ) const
{
return dfCtx_;
}
inline void T_SRDParserDefs::defaultContext( char const* name )
{
defaultContext( T_String::Pooled( name ) );
}
inline F_SRDHandler const& T_SRDParserDefs::onStart( ) const
{
return onStart_;
}
inline F_SRDHandler const& T_SRDParserDefs::onFinish( ) const
{
return onFinish_;
}
/*----------------------------------------------------------------------------*/
inline uint32_t T_SRDParserDefs::contexts( ) const
{
return ctx_.size( );
}
inline T_SRDContext& T_SRDParserDefs::operator[] ( uint32_t idx )
{
return ctx_[ idx ];
}
inline T_SRDContext const& T_SRDParserDefs::operator[] ( uint32_t idx ) const
{
return ctx_[ idx ];
}
inline T_SRDContext& T_SRDParserDefs::context( char const* name )
{
return context( T_String::Pooled( name ) );
}
inline T_SRDContext& T_SRDParserDefs::context( char const* name , char const* parent )
{
return context( T_String::Pooled( name ) , T_String::Pooled( parent ) );
}
/*----------------------------------------------------------------------------*/
inline uint32_t T_SRDParserDefs::enums( ) const
{
return enums_.size( );
}
inline T_SRDEnum & T_SRDParserDefs::enumeration( char const* name )
{
return enumeration( T_String::Pooled( name ) );
}
/*= SRD::* ===================================================================*/
namespace SRD {
inline T_SRDParserDefs::SetHandler OnStart( F_SRDHandler const& handler )
{
return T_SRDParserDefs::SetHandler( handler , true );
}
inline T_SRDParserDefs::SetHandler OnFinish( F_SRDHandler const& handler )
{
return T_SRDParserDefs::SetHandler( handler , false );
}
/*----------------------------------------------------------------------------*/
inline T_SRDContext Context( T_String name )
{
return T_SRDContext( std::move( name ) );
}
inline T_SRDContext Context( char const* name )
{
return T_SRDContext( T_String::Pooled( name ) );
}
inline T_SRDContext Context( char const* name , char const* parent )
{
return T_SRDContext( T_String::Pooled( name ) , T_String::Pooled( parent ) );
}
inline T_SRDContext Context( T_String name , T_String parent )
{
return T_SRDContext( std::move( name ) , std::move( parent ) );
}
/*----------------------------------------------------------------------------*/
inline T_SRDInputRule Rule( )
{
return T_SRDInputRule( );
}
/*----------------------------------------------------------------------------*/
inline T_SRDEnum CreateEnum( T_String name )
{
return T_SRDEnum( std::move( name ) );
}
inline T_SRDEnum CreateEnum( char const* name )
{
return T_SRDEnum( T_String::Pooled( name ) );
}
/*----------------------------------------------------------------------------*/
inline T_SRDInputItem Word( T_String const& word )
{
return T_SRDInputItem( word , true );
}
inline T_SRDInputItem Word( char const* word )
{
return T_SRDInputItem( T_String::Pooled( word ) , true );
}
inline T_SRDInputItem Word( )
{
return T_SRDInputItem( E_SRDTokenType::WORD );
}
inline T_SRDInputItem String( )
{
return T_SRDInputItem( E_SRDTokenType::STRING );
}
inline T_SRDInputItem Binary( )
{
return T_SRDInputItem( E_SRDTokenType::BINARY );
}
inline T_SRDInputItem LStart( )
{
return T_SRDInputItem( E_SRDTokenType::START );
}
inline T_SRDInputItem LEnd( )
{
return T_SRDInputItem( E_SRDTokenType::END );
}
inline T_SRDInputItem Int32( )
{
return T_SRDInputItem( E_SRDTokenType::INT );
}
inline T_SRDInputItem Int64( )
{
return T_SRDInputItem( E_SRDTokenType::LONG );
}
inline T_SRDInputItem Float( )
{
return T_SRDInputItem( E_SRDTokenType::FLOAT );
}
inline T_SRDInputItem Enum( T_String name )
{
return T_SRDInputItem( std::move( name ) , false );
}
inline T_SRDInputItem Enum( char const* name )
{
return T_SRDInputItem( T_String::Pooled( name ) , false );
}
/*----------------------------------------------------------------------------*/
inline T_SRDInputItem::T_ListHelper List( )
{
return T_SRDInputItem::T_ListHelper( );
}
inline T_SRDInputItem Alt( )
{
return T_SRDInputItem( );
}
inline T_SRDInputItem Sub( )
{
return T_SRDInputItem( 1 , 1 );
}
inline T_SRDInputItem Opt( )
{
return T_SRDInputItem( 0 , 1 );
}
inline T_SRDInputItem Opt( T_SRDInputItem item )
{
return Opt( ) << std::move( item );
}
inline T_SRDInputItem AtLeast( uint32_t n )
{
return T_SRDInputItem( n , UINT32_MAX );
}
inline T_SRDInputItem AtMost( uint32_t n )
{
return T_SRDInputItem( 0 , n );
}
inline T_SRDInputItem Times( uint32_t n )
{
return T_SRDInputItem( n , n );
}
inline T_SRDInputItem Between( uint32_t a , uint32_t b )
{
return T_SRDInputItem( a > b ? b : a , a > b ? a : b );
}
/*----------------------------------------------------------------------------*/
inline T_SRDInputItem Integer( )
{
return Alt( ) << Int32( ) << Int64( );
}
inline T_SRDInputItem Numeric( )
{
return Alt( ) << Integer( ) << Float( );
}
inline T_SRDInputItem Text( )
{
return Alt( ) << String( ) << Word( );
}
/*----------------------------------------------------------------------------*/
inline T_SRDInputRule::T_SetContext EnterContext( T_String name )
{
return T_SRDInputRule::T_SetContext( std::move( name ) );
}
inline T_SRDInputRule::T_SetContext EnterContext( char const* name )
{
return EnterContext( T_String::Pooled( name ) );
}
/*----------------------------------------------------------------------------*/
inline T_SRDInputRule::T_SetContextExecutor OnEnter( F_SRDHandler f )
{
return T_SRDInputRule::T_SetContextExecutor( false , f );
}
inline T_SRDInputRule::T_SetContextExecutor OnExit( F_SRDHandler f )
{
return T_SRDInputRule::T_SetContextExecutor( true , f );
}
} // namespace SRD
} // namespace
#endif // _H_EBCL_INLINE_SRDDEFINITIONS