Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

Lexer Class Reference

#include <Lexer.h>

List of all members.

Public Member Functions

 Lexer (const char *fn=NULL)
void close ()
void open (const char *fn)
int eof ()
string curToken ()
string getToken ()
void putbackToken (string token)
int isFlag (const string &token, const char *strg, int *flag)

Private Attributes

const char * _fn
std::ifstream _is
string _tok
string _buf
int _line
const char * _cbuf
const char * _cbufp


Detailed Description

Author:
Thomas Gschwind

Bug:
Documentation is missing.

Definition at line 18 of file Lexer.h.


Constructor & Destructor Documentation

Lexer::Lexer const char *  fn = NULL  )  [inline]
 

Definition at line 31 of file Lexer.h.

References _fn, and open().

00031                                       {
00032                 _fn = NULL;
00033                 if (fn)
00034                         open(fn);
00035         } void close() {


Member Function Documentation

void Lexer::close  )  [inline]
 

Definition at line 35 of file Lexer.h.

00035                        {
00036                 if (!_fn)
00037                         return;
00038                 _fn = NULL;
00039                 _is.close();
00040         }

string Lexer::curToken  )  [inline]
 

Definition at line 56 of file Lexer.h.

References _tok.

00056                           {
00057                 return _tok;
00058         }

int Lexer::eof  )  [inline]
 

Definition at line 52 of file Lexer.h.

References _is.

Referenced by Config::read().

00052                   {
00053                 return _is.eof();
00054         }

string Lexer::getToken  )  [inline]
 

Definition at line 60 of file Lexer.h.

References _buf, _cbuf, _cbufp, _is, _line, _tok, ERROR_LOCATION, and nlreadline().

Referenced by MPList::read(), Config::read(), AccessList::read(), AccessList::readClient(), and MPList::readServer().

00060                           {
00061                 const char *q;
00062                 while (!(*_cbufp)) {
00063                         if (!_is.good())
00064                                 throw IOError("Stream bad", -1,
00065                                               ERROR_LOCATION);
00066                         _line++;
00067                         nlreadline(_is, _buf, 0);
00068                         if (_is.eof())
00069                                 return "";
00070                         if (!_is.good())
00071                                 throw IOError("Stream bad", -1,
00072                                               ERROR_LOCATION);
00073                         _cbufp = _cbuf = _buf.c_str();
00074                         while (isspace(*_cbufp))
00075                                 _cbufp++;
00076                         if (*_cbufp == '#')
00077                                 _cbufp = _cbuf + _buf.length();
00078                 }
00079                 q = _cbufp;
00080                 while (*q && !isspace(*q))
00081                         q++;
00082                 _tok.assign(_cbufp, q - _cbufp);
00083                 _cbufp = q;
00084                 while (isspace(*_cbufp))
00085                         _cbufp++;
00086                 return _tok;
00087         }

int Lexer::isFlag const string &  token,
const char *  strg,
int *  flag
[inline]
 

Definition at line 94 of file Lexer.h.

00094                                                                       {
00095                 const char *ctok = token.c_str();
00096                 if (strcmp(ctok, strg) == 0) {
00097                         *flag = 1;
00098                         return 1;
00099                 }
00100                 if (strncmp(ctok, "not-", 4) == 0
00101                     && strcmp(ctok + 4, strg) == 0) {
00102                         *flag = 0;
00103                         return 1;
00104                 }
00105                 return 0;
00106         }

void Lexer::open const char *  fn  )  [inline]
 

Definition at line 42 of file Lexer.h.

References _buf, _cbuf, _cbufp, _fn, _is, _line, and ERROR_LOCATION.

Referenced by Lexer().

00042                                   {
00043                 _is.open(fn);
00044                 if (!_is.good())
00045                         throw IOError("Stream bad", -1, ERROR_LOCATION);
00046                 _fn = fn;
00047                 _line = 0;
00048                 _buf = "";
00049                 _cbufp = _cbuf = _buf.c_str();
00050         }

void Lexer::putbackToken string  token  )  [inline]
 

Definition at line 89 of file Lexer.h.

References _buf, _cbuf, and _cbufp.

Referenced by Config::read(), AccessList::readClient(), and MPList::readServer().

00089                                         {
00090                 _buf.replace(0, _cbufp - _cbuf, token + ' ');
00091                 _cbufp = _cbuf = _buf.c_str();
00092         }


Member Data Documentation

string Lexer::_buf [private]
 

Definition at line 26 of file Lexer.h.

Referenced by getToken(), open(), and putbackToken().

const char* Lexer::_cbuf [private]
 

Definition at line 28 of file Lexer.h.

Referenced by getToken(), open(), and putbackToken().

const char* Lexer::_cbufp [private]
 

Definition at line 29 of file Lexer.h.

Referenced by getToken(), open(), and putbackToken().

const char* Lexer::_fn [private]
 

Definition at line 21 of file Lexer.h.

Referenced by Lexer(), open(), and SyntaxError::SyntaxError().

std::ifstream Lexer::_is [private]
 

Definition at line 22 of file Lexer.h.

Referenced by eof(), getToken(), and open().

int Lexer::_line [private]
 

Definition at line 27 of file Lexer.h.

Referenced by getToken(), open(), and SyntaxError::SyntaxError().

string Lexer::_tok [private]
 

Definition at line 24 of file Lexer.h.

Referenced by curToken(), and getToken().


The documentation for this class was generated from the following file:
Generated on Sun Oct 24 21:08:22 2004 for NewsCache by doxygen 1.3.6-20040222