#ifndef already_included_reader_hh
#define already_included_reader_hh
class Gulper
{
public:
virtual ~Gulper() {}
virtual int gulp_char() = null;
};
class FileGulper : public Gulper
{
private:
FILE* f;
bool ours_to_close;
public:
FileGulper(string file_name);
FileGulper(const char* file_name);
FileGulper(FILE* f);
~FileGulper();
int gulp_char();
};
class Reader_core
{
private:
enum Return_values {
TT_eof = -1, TT_void=256, TT_char, TT_int, TT_double,
TT_identifier, TT_string, TT_bool,
};
Gulper* reader;
int current;
Return_values current_type;
string file_name;
public:
Reader_core(string file_name);
~Reader_core();
bool currently_bool() { return current_type == TT_bool; }
bool currently_char() { return current_type == TT_char; }
bool currently_int() { return current_type == TT_int; }
bool currently_double() { return current_type == TT_double; }
bool currently_identifier() { return current_type == TT_identifier; }
bool currently_string() { return current_type == TT_string; }
bool currently_eof() { return current_type == TT_eof; }
bool peek_bool();
char peek_char();
int peek_int();
double peek_double();
string peek_identifier();
string peek_string();
void next_token();
int get_file_line();
string get_file_name();
private:
void skip_whitespace();
int scan_int();
double scan_fraction();
string scan_identifier();
string scan_quoted_string();
double fractionalise(int i);
void gulp();
void wrong_type(string tname);
void error(string s);
string debug_say_symbol();
char last_char;
int last_int;
double last_double;
string last_identifier;
string last_string;
bool last_bool;
int current_line;
string current_file;
};
class Reader : public Reader_core
{
public:
Reader(string file_name) : Reader_core(file_name) {}
bool looking_at(char ch);
bool looking_at(string s);
friend Reader& operator>>(Reader& r, const char& ch);
friend Reader& operator>>(Reader& r, const char* s);
friend Reader& operator>>(Reader& r, bool& b);
friend Reader& operator>>(Reader& r, char& ch);
friend Reader& operator>>(Reader& r, int& i);
friend Reader& operator>>(Reader& r, double& d);
friend Reader& operator>>(Reader& r, string& s);
string gulp_quoted_string();
};
#endif