Fill in state table

This commit is contained in:
Keith Winstein
2011-01-09 03:38:17 -05:00
parent 49c7b66835
commit f2ceffc5d9
3 changed files with 373 additions and 24 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ namespace Parser {
class Clear : public Action {}; class Clear : public Action {};
class Collect : public Action {}; class Collect : public Action {};
class Param : public Action {}; class Param : public Action {};
class ESC_Dispatch : public Action {}; class Esc_Dispatch : public Action {};
class CSI_Dispatch : public Action {}; class CSI_Dispatch : public Action {};
class Hook : public Action {}; class Hook : public Action {};
class Put : public Action {}; class Put : public Action {};
+316 -4
View File
@@ -2,7 +2,7 @@
using namespace Parser; using namespace Parser;
const Transition State::anywhere_rule( wchar_t ch ) Transition State::anywhere_rule( wchar_t ch )
{ {
if ( (ch == 0x18) || (ch == 0x1A) if ( (ch == 0x18) || (ch == 0x1A)
|| ((0x80 <= ch) && (ch <= 0x8F)) || ((0x80 <= ch) && (ch <= 0x8F))
@@ -26,12 +26,324 @@ const Transition State::anywhere_rule( wchar_t ch )
return Transition( Ignore(), NULL ); return Transition( Ignore(), NULL );
} }
const Transition State::input( wchar_t ch ) Transition State::input( wchar_t ch )
{ {
Transition any = anywhere_rule( ch ); Transition any = anywhere_rule( ch );
if ( any.next_state ) { if ( any.next_state ) {
return any; return any;
} else {
return this->input_state_rule( ch );
} }
if ( ch >= 0xA0 ) {
return this->input_state_rule( 0x41 );
}
return this->input_state_rule( ch );
}
static bool C0_prime( wchar_t ch )
{
return ( (ch <= 0x17)
|| (ch == 0x19)
|| ( (0x1C <= ch) && (ch <= 0x1F) ) );
}
static bool GLGR ( wchar_t ch )
{
return ( ( (0x20 <= ch) && (ch <= 0x7F) ) /* GL area */
|| ( (0xA0 <= ch) && (ch <= 0xFF) ) ); /* GR area */
}
Transition Ground::input_state_rule( wchar_t ch )
{
if ( C0_prime( ch ) ) {
return Transition( Execute(), NULL );
}
if ( GLGR( ch ) ) {
return Transition( Print(), NULL );
}
return Transition( Ignore(), NULL );
}
Action Escape::enter( void )
{
return Clear();
}
Transition Escape::input_state_rule( wchar_t ch )
{
if ( C0_prime( ch ) ) {
return Transition( Execute(), NULL );
}
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
return Transition( Collect(), new Escape_Intermediate() );
}
if ( ( (0x30 <= ch) && (ch <= 0x4F) )
|| ( (0x51 <= ch) && (ch <= 0x57) )
|| ( ch == 0x59 )
|| ( ch == 0x5A )
|| ( ch == 0x5C )
|| ( (0x60 <= ch) && (ch <= 0x7E) ) ) {
return Transition( Esc_Dispatch(), new Ground() );
}
if ( ch == 0x5B ) {
return Transition( Ignore(), new CSI_Entry() );
}
if ( ch == 0x5D ) {
return Transition( Ignore(), new OSC_String() );
}
if ( ch == 0x50 ) {
return Transition( Ignore(), new DCS_Entry() );
}
if ( (ch == 0x58) || (ch == 0x5E) || (ch == 0x5F) ) {
return Transition( Ignore(), new SOS_PM_APC_String() );
}
return Transition( Ignore(), NULL );
}
Transition Escape_Intermediate::input_state_rule( wchar_t ch )
{
if ( C0_prime( ch ) ) {
return Transition( Execute(), NULL );
}
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
return Transition( Collect(), NULL );
}
if ( (0x30 <= ch) && (ch <= 0x7E) ) {
return Transition( Esc_Dispatch(), new Ground() );
}
return Transition( Ignore(), NULL );
}
Action CSI_Entry::enter( void )
{
return Clear();
}
Transition CSI_Entry::input_state_rule( wchar_t ch )
{
if ( C0_prime( ch ) ) {
return Transition( Execute(), NULL );
}
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
return Transition( CSI_Dispatch(), new Ground() );
}
if ( ( (0x30 <= ch) && (ch <= 0x39) )
|| ( ch == 0x3B ) ) {
return Transition( Param(), new CSI_Param() );
}
if ( (ch <= 0x3C) && (ch <= 0x3F) ) {
return Transition( Collect(), new CSI_Param() );
}
if ( ch == 0x3A ) {
return Transition( Ignore(), new CSI_Ignore() );
}
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
return Transition( Collect(), new CSI_Intermediate() );
}
return Transition( Ignore(), NULL );
}
Transition CSI_Param::input_state_rule( wchar_t ch )
{
if ( ( (0x30 <= ch) && (ch <= 0x39) ) || ( ch == 0x3B ) ) {
return Transition( Param(), NULL );
}
if ( ( ch == 0x3A ) || ( (0x3C <= ch) && (ch <= 0x3F) ) ) {
return Transition( Ignore(), new CSI_Ignore() );
}
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
return Transition( Collect(), new CSI_Intermediate() );
}
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
return Transition( CSI_Dispatch(), new Ground() );
}
return Transition( Ignore(), NULL );
}
Transition CSI_Intermediate::input_state_rule( wchar_t ch )
{
if ( C0_prime( ch ) ) {
return Transition( Execute(), NULL );
}
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
return Transition( Collect(), NULL );
}
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
return Transition( CSI_Dispatch(), new Ground() );
}
if ( (0x30 <= ch) && (ch <= 0x3F) ) {
return Transition( Ignore(), new CSI_Ignore() );
}
return Transition( Ignore(), NULL );
}
Transition CSI_Ignore::input_state_rule( wchar_t ch )
{
if ( C0_prime( ch ) ) {
return Transition( Execute(), NULL );
}
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
return Transition( Ignore(), new Ground() );
}
return Transition( Ignore(), NULL );
}
Action DCS_Entry::enter( void )
{
return Clear();
}
Transition DCS_Entry::input_state_rule( wchar_t ch )
{
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
return Transition( Collect(), new DCS_Intermediate() );
}
if ( ch == 0x3A ) {
return Transition( Ignore(), new DCS_Ignore() );
}
if ( ( (0x30 <= ch) && (ch <= 0x39) ) || ( ch == 0x3B ) ) {
return Transition( Param(), new DCS_Param() );
}
if ( (0x3C <= ch) && (ch <= 0x3F) ) {
return Transition( Collect(), new DCS_Param() );
}
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
return Transition( Ignore(), new DCS_Passthrough() );
}
return Transition( Ignore(), NULL );
}
Transition DCS_Param::input_state_rule( wchar_t ch )
{
if ( ( (0x30 <= ch) && (ch <= 0x39) ) || ( ch == 0x3B ) ) {
return Transition( Param(), NULL );
}
if ( ( ch == 0x3A ) || ( (0x3C <= ch) && (ch <= 0x3F) ) ) {
return Transition( Ignore(), new DCS_Ignore() );
}
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
return Transition( Collect(), new DCS_Intermediate() );
}
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
return Transition( Ignore(), new DCS_Passthrough() );
}
return Transition( Ignore(), NULL );
}
Transition DCS_Intermediate::input_state_rule( wchar_t ch )
{
if ( (0x20 <= ch) && (ch <= 0x2F) ) {
return Transition( Collect(), NULL );
}
if ( (0x40 <= ch) && (ch <= 0x7E) ) {
return Transition( Ignore(), new DCS_Passthrough() );
}
if ( (0x30 <= ch) && (ch <= 0x3F) ) {
return Transition( Ignore(), new DCS_Ignore() );
}
return Transition( Ignore(), NULL );
}
Action DCS_Passthrough::enter( void )
{
return Hook();
}
Action DCS_Passthrough::exit( void )
{
return Unhook();
}
Transition DCS_Passthrough::input_state_rule( wchar_t ch )
{
if ( C0_prime( ch ) || ( (0x20 <= ch) && (ch <= 0x7E) ) ) {
return Transition( Put(), NULL );
}
if ( ch == 0x9C ) {
return Transition( Ignore(), new Ground() );
}
return Transition( Ignore(), NULL );
}
Transition DCS_Ignore::input_state_rule( wchar_t ch )
{
if ( ch == 0x9C ) {
return Transition( Ignore(), new Ground() );
}
return Transition( Ignore(), NULL );
}
Action OSC_String::enter( void )
{
return OSC_Start();
}
Action OSC_String::exit( void )
{
return OSC_End();
}
Transition OSC_String::input_state_rule( wchar_t ch )
{
if ( (0x20 <= ch) && (ch <= 0x7F) ) {
return Transition( OSC_Put(), NULL );
}
if ( ch == 0x9C ) {
return Transition( Ignore(), new Ground() );
}
return Transition( Ignore(), NULL );
}
Transition SOS_PM_APC_String::input_state_rule( wchar_t ch )
{
if ( ch == 0x9C ) {
return Transition( Ignore(), new Ground() );
}
return Transition( Ignore(), NULL );
} }
+56 -19
View File
@@ -7,36 +7,73 @@ namespace Parser {
class State class State
{ {
protected: protected:
const virtual Transition input_state_rule( wchar_t ch ) { ch = ch; return Transition( Ignore(), NULL ); } virtual Transition input_state_rule( wchar_t ch ) = 0;
private: private:
const virtual Action enter( void ) { return Ignore(); }; virtual Action enter( void ) { return Ignore(); };
const virtual Action leave( void ) { return Ignore(); }; virtual Action exit( void ) { return Ignore(); };
const Transition input( wchar_t ch ); Transition input( wchar_t ch );
const static Transition anywhere_rule( wchar_t ch ); Transition anywhere_rule( wchar_t ch );
public: public:
virtual ~State() {}; virtual ~State() {};
}; };
class Ground : public State {}; class Ground : public State {
class Escape : public State {}; Transition input_state_rule( wchar_t ch );
class Escape_Intermediate : public State {}; };
class CSI_Entry : public State {}; class Escape : public State {
class CSI_Param : public State {}; Action enter( void );
class CSI_Intermediate : public State {}; Transition input_state_rule( wchar_t ch );
class CSI_Ignore : public State {}; };
class DCS_Entry : public State {}; class Escape_Intermediate : public State {
class DCS_Param : public State {}; Transition input_state_rule( wchar_t ch );
class DCS_Intermediate : public State {}; };
class DCS_Passthrough : public State {};
class DCS_Ignore : public State {};
class OSC_String : public State {}; class CSI_Entry : public State {
class SOS_PM_APC_String : public State {}; Action enter( void );
Transition input_state_rule( wchar_t ch );
};
class CSI_Param : public State {
Transition input_state_rule( wchar_t ch );
};
class CSI_Intermediate : public State {
Transition input_state_rule( wchar_t ch );
};
class CSI_Ignore : public State {
Transition input_state_rule( wchar_t ch );
};
class DCS_Entry : public State {
Action enter( void );
Transition input_state_rule( wchar_t ch );
};
class DCS_Param : public State {
Transition input_state_rule( wchar_t ch );
};
class DCS_Intermediate : public State {
Transition input_state_rule( wchar_t ch );
};
class DCS_Passthrough : public State {
Action enter( void );
Transition input_state_rule( wchar_t ch );
Action exit( void );
};
class DCS_Ignore : public State {
Transition input_state_rule( wchar_t ch );
};
class OSC_String : public State {
Action enter( void );
Transition input_state_rule( wchar_t ch );
Action exit( void );
};
class SOS_PM_APC_String : public State {
Transition input_state_rule( wchar_t ch );
};
} }
#endif #endif