KrisLibrary  1.0.0
Public Types | Public Member Functions | Public Attributes | List of all members
SimpleParser Class Referenceabstract

A simple class to break files into tokens, punctuation, comments, and whitespace. More...

#include <SimpleParser.h>

Inheritance diagram for SimpleParser:
PCLParser

Public Types

enum  Result { Continue, Stop, Error }
 

Public Member Functions

 SimpleParser (istream &in)
 
virtual bool IsSpace (char c) const
 
virtual bool IsComment (char c) const
 
virtual bool IsToken (char c) const
 
virtual bool IsPunct (char c) const
 
virtual Result InputToken (const string &word)=0
 
virtual Result InputPunct (const string &punct)=0
 
virtual Result InputEndLine ()=0
 
bool Read ()
 
bool EatSpace ()
 
bool ReadLine (string &str)
 

Public Attributes

istream & in
 
int lineno
 

Detailed Description

A simple class to break files into tokens, punctuation, comments, and whitespace.

Non-comment lines are broken up into tokens and punctuation, possibly separated by whitespace. Tokens and punctuation are contiguous blocks of token and punctuation characters.

Comments take up an entire line. The format is whitespace, followed by comment char, and consumes characters up to the endline.

Whitespace, comment, token, and punctuation characters are determined by the overrideable IsSpace, IsComment, IsToken, and IsPunct methods. By default, tokens are alphanumeric characters, whitespaces are spaces, tabs, and newlines, and comments start with '#'. Punctuation is everything else.

Callbacks are defined by overriding InputToken, InputPunct, and InputEndline in a subclass. They can return Continue to continue reading the file, Stop to stop reading the file (with success), and Error to stop reading the file with failiure.


The documentation for this class was generated from the following files: