SRDIO - Memory target can ignore comments

This commit is contained in:
Emmanuel BENOîT 2017-11-06 10:53:54 +01:00
parent 073fcb3d5e
commit 3adfdadd11
3 changed files with 40 additions and 8 deletions

View file

@ -139,6 +139,7 @@ class T_SRDMemoryTarget : public A_SRDReaderTarget
private: private:
const bool structured_; const bool structured_;
bool clearFlushToken_; bool clearFlushToken_;
bool clearComments_;
T_SRDToken list_; T_SRDToken list_;
RP_SRDToken current_; RP_SRDToken current_;
T_Array< RP_SRDToken > stack_; T_Array< RP_SRDToken > stack_;
@ -150,9 +151,13 @@ class T_SRDMemoryTarget : public A_SRDReaderTarget
explicit T_SRDMemoryTarget( bool structured = true ); explicit T_SRDMemoryTarget( bool structured = true );
// Set/get flush token handling // Set/get flush token handling
void clearFlushToken( bool clearIt ) noexcept; T_SRDMemoryTarget& clearFlushToken( bool clear ) noexcept;
bool clearFlushToken( ) const 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 start( T_SRDErrors& errors ) override;
void push( T_SRDErrors& errors , T_SRDToken&& token ) override; void push( T_SRDErrors& errors , T_SRDToken&& token ) override;
void end( T_SRDErrors& errors ) override; void end( T_SRDErrors& errors ) override;

View file

@ -52,10 +52,11 @@ inline T_SRDReaderTargetHelper::~T_SRDReaderTargetHelper( )
/*= T_SRDMemoryTarget ========================================================*/ /*= T_SRDMemoryTarget ========================================================*/
inline void T_SRDMemoryTarget::clearFlushToken( inline T_SRDMemoryTarget& T_SRDMemoryTarget::clearFlushToken(
bool clearIt ) noexcept const bool clear ) noexcept
{ {
clearFlushToken_ = clearIt; clearFlushToken_ = clear;
return *this;
} }
inline bool T_SRDMemoryTarget::clearFlushToken( ) const noexcept inline bool T_SRDMemoryTarget::clearFlushToken( ) const noexcept
@ -63,6 +64,18 @@ inline bool T_SRDMemoryTarget::clearFlushToken( ) const noexcept
return clearFlushToken_; 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 inline T_SRDList const& T_SRDMemoryTarget::list( ) const
{ {
return list_.list( ); return list_.list( );

View file

@ -126,6 +126,7 @@ void T_SRDListFixer::end(
T_SRDMemoryTarget::T_SRDMemoryTarget( bool structured ) T_SRDMemoryTarget::T_SRDMemoryTarget( bool structured )
: structured_( structured ) , : structured_( structured ) ,
clearFlushToken_( false ) , clearFlushToken_( false ) ,
clearComments_( false ) ,
list_( T_SRDToken::List( T_SRDList( ) ) ) , list_( T_SRDToken::List( T_SRDList( ) ) ) ,
stack_( 128 ) stack_( 128 )
{ } { }
@ -141,6 +142,8 @@ void T_SRDMemoryTarget::push( T_SRDErrors& errors , T_SRDToken&& token )
assert( current_ != nullptr ); assert( current_ != nullptr );
const auto tt( token.type( ) ); const auto tt( token.type( ) );
// Handle list starts
if ( tt == E_SRDTokenType::START ) { if ( tt == E_SRDTokenType::START ) {
if ( structured_ ) { if ( structured_ ) {
auto& c( current_->list( ) ); auto& c( current_->list( ) );
@ -156,8 +159,11 @@ void T_SRDMemoryTarget::push( T_SRDErrors& errors , T_SRDToken&& token )
l.add( std::move( token ) ); l.add( std::move( token ) );
stack_.add( &( l[ l.size( ) - 1 ] ) ); 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 ) { if ( stack_.size( ) == 0 ) {
errors.add( "unexpected ')'" , token ); errors.add( "unexpected ')'" , token );
} else { } else {
@ -169,10 +175,18 @@ void T_SRDMemoryTarget::push( T_SRDErrors& errors , T_SRDToken&& token )
} }
stack_.remove( last ); stack_.remove( last );
} }
return;
} else if ( tt != E_SRDTokenType::FLUSH || !clearFlushToken_ ) {
current_->list( ).add( std::move( token ) );
} }
// 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 ) void T_SRDMemoryTarget::end( T_SRDErrors& errors )