diff --git a/include/ebcl/SRDIO.hh b/include/ebcl/SRDIO.hh index 3c53dfd..fca7b04 100644 --- a/include/ebcl/SRDIO.hh +++ b/include/ebcl/SRDIO.hh @@ -139,6 +139,7 @@ class T_SRDMemoryTarget : public A_SRDReaderTarget private: const bool structured_; bool clearFlushToken_; + bool clearComments_; T_SRDToken list_; RP_SRDToken current_; T_Array< RP_SRDToken > stack_; @@ -150,9 +151,13 @@ class T_SRDMemoryTarget : public A_SRDReaderTarget explicit T_SRDMemoryTarget( bool structured = true ); // Set/get flush token handling - void clearFlushToken( bool clearIt ) noexcept; + T_SRDMemoryTarget& clearFlushToken( bool clear ) noexcept; bool clearFlushToken( ) const noexcept; + // Set/get comment handling + T_SRDMemoryTarget& clearComments( bool clear ) noexcept; + bool clearComments( ) const noexcept; + void start( T_SRDErrors& errors ) override; void push( T_SRDErrors& errors , T_SRDToken&& token ) override; void end( T_SRDErrors& errors ) override; diff --git a/include/ebcl/inline/SRDIO.hh b/include/ebcl/inline/SRDIO.hh index 933317a..2291c1c 100644 --- a/include/ebcl/inline/SRDIO.hh +++ b/include/ebcl/inline/SRDIO.hh @@ -52,10 +52,11 @@ inline T_SRDReaderTargetHelper::~T_SRDReaderTargetHelper( ) /*= T_SRDMemoryTarget ========================================================*/ -inline void T_SRDMemoryTarget::clearFlushToken( - bool clearIt ) noexcept +inline T_SRDMemoryTarget& T_SRDMemoryTarget::clearFlushToken( + const bool clear ) noexcept { - clearFlushToken_ = clearIt; + clearFlushToken_ = clear; + return *this; } inline bool T_SRDMemoryTarget::clearFlushToken( ) const noexcept @@ -63,6 +64,18 @@ inline bool T_SRDMemoryTarget::clearFlushToken( ) const noexcept return clearFlushToken_; } +inline T_SRDMemoryTarget& T_SRDMemoryTarget::clearComments( + const bool clear ) noexcept +{ + clearComments_ = clear; + return *this; +} + +inline bool T_SRDMemoryTarget::clearComments( ) const noexcept +{ + return clearComments_; +} + inline T_SRDList const& T_SRDMemoryTarget::list( ) const { return list_.list( ); diff --git a/src/SRDIO.cc b/src/SRDIO.cc index e78c604..6d2d3e0 100644 --- a/src/SRDIO.cc +++ b/src/SRDIO.cc @@ -126,6 +126,7 @@ void T_SRDListFixer::end( T_SRDMemoryTarget::T_SRDMemoryTarget( bool structured ) : structured_( structured ) , clearFlushToken_( false ) , + clearComments_( false ) , list_( T_SRDToken::List( T_SRDList( ) ) ) , stack_( 128 ) { } @@ -141,6 +142,8 @@ void T_SRDMemoryTarget::push( T_SRDErrors& errors , T_SRDToken&& token ) assert( current_ != nullptr ); const auto tt( token.type( ) ); + + // Handle list starts if ( tt == E_SRDTokenType::START ) { if ( structured_ ) { auto& c( current_->list( ) ); @@ -156,8 +159,11 @@ void T_SRDMemoryTarget::push( T_SRDErrors& errors , T_SRDToken&& token ) l.add( std::move( token ) ); stack_.add( &( l[ l.size( ) - 1 ] ) ); } + return; + } - } else if ( tt == E_SRDTokenType::END ) { + // Handle list ends + if ( tt == E_SRDTokenType::END ) { if ( stack_.size( ) == 0 ) { errors.add( "unexpected ')'" , token ); } else { @@ -169,10 +175,18 @@ void T_SRDMemoryTarget::push( T_SRDErrors& errors , T_SRDToken&& token ) } stack_.remove( last ); } - - } else if ( tt != E_SRDTokenType::FLUSH || !clearFlushToken_ ) { - current_->list( ).add( std::move( token ) ); + return; } + + // Ignore flushes and comments if requested + if ( tt == E_SRDTokenType::FLUSH && clearFlushToken_ ) { + return; + } + if ( tt == E_SRDTokenType::COMMENT && clearComments_ ) { + return; + } + + current_->list( ).add( std::move( token ) ); } void T_SRDMemoryTarget::end( T_SRDErrors& errors )