mpw-shell/phase1.h

41 lines
740 B
C
Raw Permalink 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 &&)> next_function_type;
2016-01-30 03:23:14 +00:00
phase1() = default;
2016-01-30 03:23:14 +00:00
void parse(const unsigned char *begin, const unsigned char *end);
void parse(const std::string &s) { parse((const unsigned char *)s.data(), (const unsigned char *)s.data() + s.size()); }
void finish();
2016-01-30 03:23:14 +00:00
void reset();
void abort() { reset(); }
2016-01-30 03:23:14 +00:00
2016-07-21 19:14:27 +00:00
bool continuation() const { return multiline; }
2016-01-31 05:41:02 +00:00
void set_next(next_function_type &&fx) { _then = std::move(fx); }
2016-01-30 03:23:14 +00:00
private:
int process(unsigned char, int);
void flush();
2016-01-30 03:23:14 +00:00
std::string scratch;
int line = 1;
int cs = 0;
bool multiline = false;
next_function_type _then;
2016-01-30 03:23:14 +00:00
};
#endif