diff --git a/parseraction.hpp b/parseraction.hpp index 16ac4e3..bccfbce 100644 --- a/parseraction.hpp +++ b/parseraction.hpp @@ -5,7 +5,7 @@ namespace Parser { class Action { public: - virtual ~Action(); + virtual ~Action() {} }; class Ignore : public Action {}; diff --git a/parserstate.cpp b/parserstate.cpp index e4d3c0a..4acab62 100644 --- a/parserstate.cpp +++ b/parserstate.cpp @@ -1 +1,37 @@ #include "parserstate.hpp" + +using namespace Parser; + +Transition State::anywhere_rule( wchar_t ch ) +{ + if ( (ch == 0x18) || (ch == 0x1A) + || ((0x80 <= ch) && (ch <= 0x8F)) + || ((0x91 <= ch) && (ch <= 0x97)) + || (ch == 0x99) || (ch == 0x9A) ) { + return Transition( Execute(), new Ground() ); + } else if ( ch == 0x9C ) { + return Transition( Ignore(), new Ground() ); + } else if ( ch == 0x1B ) { + return Transition( Ignore(), new Escape() ); + } else if ( (ch == 0x98) || (ch == 0x9E) || (ch == 0x9F) ) { + return Transition( Ignore(), new SOS_PM_APC_String() ); + } else if ( ch == 0x90 ) { + return Transition( Ignore(), new DCS_Entry() ); + } else if ( ch == 0x9D ) { + return Transition( Ignore(), new OSC_String() ); + } else if ( ch == 0x9B ) { + return Transition( Ignore(), new CSI_Entry() ); + } + + return Transition( Ignore(), NULL ); +} + +Transition State::input( wchar_t ch ) +{ + Transition any = anywhere_rule( ch ); + if ( any.next_state ) { + return any; + } else { + return this->input_state_rule( ch ); + } +} diff --git a/parserstate.hpp b/parserstate.hpp index 05308a0..203eadd 100644 --- a/parserstate.hpp +++ b/parserstate.hpp @@ -6,23 +6,23 @@ namespace Parser { class State { + protected: + virtual Transition input_state_rule( wchar_t ch ) { ch = ch; return Transition( Ignore(), NULL ); } + private: virtual Action enter( void ) { return Ignore(); }; virtual Action leave( void ) { return Ignore(); }; - virtual Transition input( wchar_t ch __attribute__ ((unused)) ) { - return IgnoreTransition(); - } - - static Transition anywhere( wchar_t ch ); + Transition input( wchar_t ch ); + Transition anywhere_rule( wchar_t ch ); public: - virtual ~State(); + virtual ~State() {}; }; class Ground : public State {}; - class Esc : public State {}; - class Esc_Intermediate : public State {}; + class Escape : public State {}; + class Escape_Intermediate : public State {}; class CSI_Entry : public State {}; class CSI_Param : public State {}; @@ -35,7 +35,7 @@ namespace Parser { class DCS_Passthrough : public State {}; class DCS_Ignore : public State {}; - class OCS_String : public State {}; + class OSC_String : public State {}; class SOS_PM_APC_String : public State {}; } diff --git a/parsertransition.hpp b/parsertransition.hpp index 3411f84..272afb3 100644 --- a/parsertransition.hpp +++ b/parsertransition.hpp @@ -5,29 +5,24 @@ #include "parseraction.hpp" -class State; - namespace Parser { + class State; + class Transition { public: Action action; State *next_state; - Transition(); - Transition( const Transition & ); + Transition( const Transition &x ) + : action( x.action ), + next_state( x.next_state ) {} bool operator=( const Transition & ); - virtual ~Transition(); - }; + virtual ~Transition() {} - class IgnoreTransition : public Transition - { - public: - IgnoreTransition() - { - action = Ignore(); - next_state = NULL; - } + Transition( Action s_action, State *s_next_state ) + : action( s_action ), next_state( s_next_state ) + {} }; }