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"
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<Action *> ret;
@@ -7,21 +22,13 @@ std::vector<Parser::Action *> Parser::Parser::input( wchar_t ch )
Transition tx = state->input( ch );
if ( tx.next_state != NULL ) {
Action *exitact = state->exit();
if ( exitact ) {
ret.push_back( exitact );
}
append_or_delete( state->exit(), ret );
}
if ( tx.action ) {
ret.push_back( tx.action );
}
append_or_delete( tx.action, ret );
if ( tx.next_state != NULL ) {
Action *enteract = tx.next_state->enter();
if ( enteract ) {
ret.push_back( enteract );
}
append_or_delete( tx.next_state->enter(), ret );
state = tx.next_state;
}
+2 -2
View File
@@ -18,8 +18,8 @@ namespace Parser {
public:
void setfamily( StateFamily *s_family ) { family = s_family; }
Transition input( wchar_t ch );
virtual Action *enter( void ) { return NULL; }
virtual Action *exit( void ) { return NULL; }
virtual Action *enter( void ) { return new Ignore; }
virtual Action *exit( void ) { return new Ignore; }
State() : family( NULL ) {};
virtual ~State() {};
+2 -2
View File
@@ -26,12 +26,12 @@ namespace Parser {
}
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 )
{}
Transition( State *s_next_state )
: action( new Ignore() ), next_state( s_next_state )
: action( new Ignore ), next_state( s_next_state )
{}
};
}