mpw-shell/phase1.h

40 lines
855 B
C
Raw Normal View History

2016-01-30 03:23:14 +00:00
#ifndef __phase1_h__
#define __phase1_h__
#include <string>
#include <functional>
class phase1 {
public:
typedef std::function<void(std::string &&)> pipe_function;
phase1();
void process(const unsigned char *begin, const unsigned char *end, bool final = false);
void process(const char *begin, const char *end, bool final = false) {
process((const unsigned char *)begin, (const unsigned char *)end, final);
}
void process(const std::string &s) { process(s.data(), s.data() + s.size()); }
void finish() { const char *tmp = ""; process(tmp, tmp, true); }
void reset();
//template<class F>
//phase1 &operator >>= (F &&f) { pipe_to = pipe_function(f); return *this; }
phase1 &operator >>= (pipe_function f) { pipe_to = f; return *this; }
private:
std::string scratch;
pipe_function pipe_to;
int line = 1;
int cs = 0;
};
#endif