commit 52f527891cee8d3ab60eb1272d8ed60531e37734 Author: Keith Winstein Date: Tue Dec 28 18:05:50 2010 -0500 Initial commit diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..29709ea --- /dev/null +++ b/Makefile @@ -0,0 +1,24 @@ +source = parse.cpp parserstate.cpp +objects = parserstate.o +executables = parse + +CPP = g++ +CPPFLAGS = -g --std=c++0x -pedantic -Werror -Wall -Wextra -Weffc++ -fno-implicit-templates -pipe -D_FILE_OFFSET_BITS=64 -D_XOPEN_SOURCE=500 -D_GNU_SOURCE +LIBS = + +all: $(executables) + +parse: parse.o $(objects) + $(CPP) $(CPPFLAGS) -o $@ $+ $(LIBS) + +%.o: %.cpp + $(CPP) $(CPPFLAGS) -c -o $@ $< + +include depend + +depend: $(source) + $(CPP) $(INCLUDES) -MM $(source) > depend + +.PHONY: clean +clean: + -rm -f $(executables) depend *.o *.rpo diff --git a/parse.cpp b/parse.cpp new file mode 100644 index 0000000..3326f68 --- /dev/null +++ b/parse.cpp @@ -0,0 +1,8 @@ +#include "parser.hpp" + +int main( void ) +{ + Parser::Parser parser; + + return 0; +} diff --git a/parser.hpp b/parser.hpp new file mode 100644 index 0000000..c78a1c3 --- /dev/null +++ b/parser.hpp @@ -0,0 +1,24 @@ +#ifndef PARSE_HPP +#define PARSE_HPP + +#include + +#include "parsertransition.hpp" +#include "parseraction.hpp" +#include "parserstate.hpp" + +namespace Parser { + class Parser { + private: + State *state; + + public: + Parser() : state( NULL ) {} + Parser( const Parser & ); + bool operator=( const Parser & ); + void input( wchar_t c ); /* should return list of actions */ + ~Parser() {} + }; +} + +#endif diff --git a/parseraction.hpp b/parseraction.hpp new file mode 100644 index 0000000..16ac4e3 --- /dev/null +++ b/parseraction.hpp @@ -0,0 +1,27 @@ +#ifndef PARSERACTION_HPP +#define PARSERACTION_HPP + +namespace Parser { + class Action + { + public: + virtual ~Action(); + }; + + class Ignore : public Action {}; + class Print : public Action {}; + class Execute : public Action {}; + class Clear : public Action {}; + class Collect : public Action {}; + class Param : public Action {}; + class ESC_Dispatch : public Action {}; + class CSI_Dispatch : public Action {}; + class Hook : public Action {}; + class Put : public Action {}; + class Unhook : public Action {}; + class OSC_Start : public Action {}; + class OSC_Put : public Action {}; + class OSC_End : public Action {}; +} + +#endif diff --git a/parserstate.cpp b/parserstate.cpp new file mode 100644 index 0000000..e4d3c0a --- /dev/null +++ b/parserstate.cpp @@ -0,0 +1 @@ +#include "parserstate.hpp" diff --git a/parserstate.hpp b/parserstate.hpp new file mode 100644 index 0000000..05308a0 --- /dev/null +++ b/parserstate.hpp @@ -0,0 +1,42 @@ +#ifndef PARSERSTATE_HPP +#define PARSERSTATE_HPP + +#include "parsertransition.hpp" + +namespace Parser { + class State + { + 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 ); + + public: + virtual ~State(); + }; + + class Ground : public State {}; + class Esc : public State {}; + class Esc_Intermediate : public State {}; + + class CSI_Entry : public State {}; + class CSI_Param : public State {}; + class CSI_Intermediate : public State {}; + class CSI_Ignore : public State {}; + + class DCS_Entry : public State {}; + class DCS_Param : public State {}; + class DCS_Intermediate : public State {}; + class DCS_Passthrough : public State {}; + class DCS_Ignore : public State {}; + + class OCS_String : public State {}; + class SOS_PM_APC_String : public State {}; +} + +#endif diff --git a/parsertransition.hpp b/parsertransition.hpp new file mode 100644 index 0000000..3411f84 --- /dev/null +++ b/parsertransition.hpp @@ -0,0 +1,34 @@ +#ifndef PARSERTRANSITION_HPP +#define PARSERTRANSITION_HPP + +#include + +#include "parseraction.hpp" + +class State; + +namespace Parser { + class Transition + { + public: + Action action; + State *next_state; + + Transition(); + Transition( const Transition & ); + bool operator=( const Transition & ); + virtual ~Transition(); + }; + + class IgnoreTransition : public Transition + { + public: + IgnoreTransition() + { + action = Ignore(); + next_state = NULL; + } + }; +} + +#endif