Screen out Ignore actions

This commit is contained in:
Keith Winstein
2011-01-13 01:06:16 -05:00
parent 40f196d02c
commit fbf0567085
3 changed files with 22 additions and 15 deletions
+18 -11
View File
@@ -1,5 +1,20 @@
#include <assert.h>
#include <typeinfo>
#include "parser.hpp" #include "parser.hpp"
static void append_or_delete( Parser::Action *act,
std::vector<Parser::Action *>&vec )
{
assert( act );
if ( typeid( *act ) != typeid( Parser::Ignore ) ) {
vec.push_back( act );
} else {
delete act;
}
}
std::vector<Parser::Action *> Parser::Parser::input( wchar_t ch ) std::vector<Parser::Action *> Parser::Parser::input( wchar_t ch )
{ {
std::vector<Action *> ret; std::vector<Action *> ret;
@@ -7,21 +22,13 @@ std::vector<Parser::Action *> Parser::Parser::input( wchar_t ch )
Transition tx = state->input( ch ); Transition tx = state->input( ch );
if ( tx.next_state != NULL ) { if ( tx.next_state != NULL ) {
Action *exitact = state->exit(); append_or_delete( state->exit(), ret );
if ( exitact ) {
ret.push_back( exitact );
}
} }
if ( tx.action ) { append_or_delete( tx.action, ret );
ret.push_back( tx.action );
}
if ( tx.next_state != NULL ) { if ( tx.next_state != NULL ) {
Action *enteract = tx.next_state->enter(); append_or_delete( tx.next_state->enter(), ret );
if ( enteract ) {
ret.push_back( enteract );
}
state = tx.next_state; state = tx.next_state;
} }
+2 -2
View File
@@ -18,8 +18,8 @@ namespace Parser {
public: public:
void setfamily( StateFamily *s_family ) { family = s_family; } void setfamily( StateFamily *s_family ) { family = s_family; }
Transition input( wchar_t ch ); Transition input( wchar_t ch );
virtual Action *enter( void ) { return NULL; } virtual Action *enter( void ) { return new Ignore; }
virtual Action *exit( void ) { return NULL; } virtual Action *exit( void ) { return new Ignore; }
State() : family( NULL ) {}; State() : family( NULL ) {};
virtual ~State() {}; virtual ~State() {};
+2 -2
View File
@@ -26,12 +26,12 @@ namespace Parser {
} }
virtual ~Transition() {} virtual ~Transition() {}
Transition( Action *s_action=new Ignore(), State *s_next_state=NULL ) Transition( Action *s_action=new Ignore, State *s_next_state=NULL )
: action( s_action ), next_state( s_next_state ) : action( s_action ), next_state( s_next_state )
{} {}
Transition( State *s_next_state ) Transition( State *s_next_state )
: action( new Ignore() ), next_state( s_next_state ) : action( new Ignore ), next_state( s_next_state )
{} {}
}; };
} }