MetaCC::TextReader Class Reference

#include <text_reader.h>

List of all members.


Detailed Description

Encapsulates text file stream and provides more convenient API to read the text for line oriented text parsers.

Definition at line 16 of file text_reader.h.

Public Member Functions

unsigned int get_row ()
 Returns current row being parsed.
unsigned int get_col ()
 Returns column on current row being parsed.
 TextReader (const char *fname)
 Construct TextReader based on file (supply name).
 ~TextReader ()
 Destroy TextReader object and close the internal stream.
bool reached_eof ()
 Returns true if we reached end of file.
bool reached_end_of_row ()
 Returns true if we reached end of row, otherwise returns false.
void restart_row (unsigned int at_column=0)
 Moves caret back to specified column (0 by default if not specified).
unsigned int cur_row_length ()
 Returns length of currently parsed row of text.
std::string cur_row_text ()
 Returns currently parsed row of text (as string).
bool adv_row ()
 Advance parser "reading caret" to next row.
bool adv_col ()
 Advance parser "reading caret" to next column in current row.
char cur_char ()
 Returns current character the "reading caret" is pointing at, or ASCII NUL char (0) if the caret is at end of current row.
void skip_spaces ()
 Skips spaces up to first non-space character on current row, or till end of row.
bool is_next_word ()
 Returns true if next token is word (keyword or identifier).
bool is_next_int ()
 Returns true if next token is int May skip some spaces (that is, alter the "column" of the reading caret).
std::string read_word ()
 Skip spaces, then read word at current caret position, and advance the caret to first character which terminated the word reading.
unsigned int read_int ()
 Skip spaces, then read int at current caret position, and advance the caret to first character which terminated the int reading.


Constructor & Destructor Documentation

MetaCC::TextReader::TextReader ( const char *  fname  )  [inline]

Construct TextReader based on file (supply name).

Definition at line 33 of file text_reader.h.

MetaCC::TextReader::~TextReader (  )  [inline]

Destroy TextReader object and close the internal stream.

Definition at line 46 of file text_reader.h.


Member Function Documentation

unsigned int MetaCC::TextReader::get_row (  )  [inline]

Returns current row being parsed.

Definition at line 27 of file text_reader.h.

unsigned int MetaCC::TextReader::get_col (  )  [inline]

Returns column on current row being parsed.

Definition at line 30 of file text_reader.h.

bool MetaCC::TextReader::reached_eof (  )  [inline]

Returns true if we reached end of file.

Definition at line 52 of file text_reader.h.

Referenced by adv_row(), and TextReader().

bool MetaCC::TextReader::reached_end_of_row (  )  [inline]

Returns true if we reached end of row, otherwise returns false.

Definition at line 58 of file text_reader.h.

void MetaCC::TextReader::restart_row ( unsigned int  at_column = 0  )  [inline]

Moves caret back to specified column (0 by default if not specified).

Can be used if you already started to parse the row, but then need to restart the parsing. Note that if at_column specified is larger than length of current row, then caret is automatically placed in

Definition at line 70 of file text_reader.h.

Referenced by skip_spaces().

unsigned int MetaCC::TextReader::cur_row_length (  )  [inline]

Returns length of currently parsed row of text.

Definition at line 79 of file text_reader.h.

Referenced by skip_spaces().

std::string MetaCC::TextReader::cur_row_text (  )  [inline]

Returns currently parsed row of text (as string).

Definition at line 85 of file text_reader.h.

bool MetaCC::TextReader::adv_row (  )  [inline]

Advance parser "reading caret" to next row.

Returns true if succeeded, or false if reached end of file (so it could not advance).

Definition at line 93 of file text_reader.h.

bool MetaCC::TextReader::adv_col (  )  [inline]

Advance parser "reading caret" to next column in current row.

Returns true if succeeded, or false if we reached end of row so it can't advance.

Definition at line 106 of file text_reader.h.

Referenced by read_int(), read_word(), and skip_spaces().

char MetaCC::TextReader::cur_char (  )  [inline]

Returns current character the "reading caret" is pointing at, or ASCII NUL char (0) if the caret is at end of current row.

Definition at line 115 of file text_reader.h.

Referenced by is_next_int(), is_next_word(), read_int(), read_word(), and skip_spaces().

void MetaCC::TextReader::skip_spaces (  )  [inline]

Skips spaces up to first non-space character on current row, or till end of row.

Note:
Implementation currently also kills comments starting from hash (#) symbol. This is done this way: after skipping spaces - if we see hash symbol (#), then caret is moved to end of line (effectively killing the comment). THIS WILL BE CHANGED LATER, it's now only done temporary for convenience.

Definition at line 128 of file text_reader.h.

Referenced by is_next_int(), is_next_word(), read_int(), and read_word().

bool MetaCC::TextReader::is_next_word (  )  [inline]

Returns true if next token is word (keyword or identifier).

May skip some spaces (that is, alter the "column" of the reading caret).

Definition at line 142 of file text_reader.h.

bool MetaCC::TextReader::is_next_int (  )  [inline]

Returns true if next token is int May skip some spaces (that is, alter the "column" of the reading caret).

Definition at line 151 of file text_reader.h.

std::string MetaCC::TextReader::read_word (  )  [inline]

Skip spaces, then read word at current caret position, and advance the caret to first character which terminated the word reading.

Definition at line 158 of file text_reader.h.

unsigned int MetaCC::TextReader::read_int (  )  [inline]

Skip spaces, then read int at current caret position, and advance the caret to first character which terminated the int reading.

Definition at line 170 of file text_reader.h.


The documentation for this class was generated from the following file:
Generated on Sat Sep 9 03:50:56 2006 for Openem APIs by  doxygen 1.4.7