KrisLibrary  1.0.0
SimpleParser.h
1 #ifndef UTILS_SIMPLE_PARSER_H
2 #define UTILS_SIMPLE_PARSER_H
3 
4 #include <iosfwd>
5 #include <ctype.h>
6 #include <assert.h>
7 #include <string>
8 using namespace std;
9 
33 {
34 public:
35  enum Result { Continue, Stop, Error };
36  SimpleParser(istream& in);
37  virtual ~SimpleParser() {}
38  virtual bool IsSpace(char c) const { return isspace(c); }
39  virtual bool IsComment(char c) const { return c=='#'; }
40  virtual bool IsToken(char c) const { return isalnum(c); }
41  virtual bool IsPunct(char c) const { return !IsSpace(c) && !IsComment(c) && !IsToken(c); }
42  virtual Result InputToken(const string& word)=0;
43  virtual Result InputPunct(const string& punct)=0;
44  virtual Result InputEndLine()=0;
45 
46  bool Read();
47 
48  //called by sub classes on error, stop
49  bool EatSpace();
50  bool ReadLine(string& str);
51 
52  istream& in;
53  int lineno;
54 };
55 
56 #endif
A simple class to break files into tokens, punctuation, comments, and whitespace. ...
Definition: SimpleParser.h:32
Definition: rayprimitives.h:132
bool InputToken(std::istream &in, const char *characterSet, std::string &str)
Definition: ioutils.cpp:45