Module yeanpypa :: Class InputReader
[show private | hide private]
[frames | no frames]

Class InputReader


The InputReader serves as an abstraction to read chars from a string with a state. The reader provides tools to save the current reading position and a stack to set checkpoints where to return to later.
Method Summary
  __init__(self, string, ignore_white)
Create this reader with the given string.
  checkPoint(self)
Set a checkpoint in the reader.
  deleteCheckpoint(self)
Delete the newest checkpoint without rolling back.
  fullyConsumed(self)
Return whether the string was fully consumed
  getChar(self)
Get a single character from the string.
  getIgnoreState(self)
Return whether the reader is set to ignore whitespaces.
  getPos(self)
Return the current position of this reader
  getString(self, length)
Get a substring of the string from this reader and advance the reader's position.
  rollback(self)
Rollback the parser to the last checkpoint set.
  setIgnoreState(self, state)
Set the ignore state of the reader.
  skipWhite(self)
Function to skip the whitespace characters from the current position on.

Method Details

__init__(self, string, ignore_white)
(Constructor)

Create this reader with the given string.
Parameters:
string - The string the reader reads from.
           (type=str)
ignore_white - Whether to ignore whitespaces or not.
           (type=boolean)

checkPoint(self)

Set a checkpoint in the reader. A checkpoint is kind of like a safety net where the parser can return to later if parsin failed at any later point in the string. The checkpoints are managed in a stack-like fashion: the parser can always return to the last checkpoint set.

deleteCheckpoint(self)

Delete the newest checkpoint without rolling back. If a rules sucessfully matches, it deletes the previously saved checkpoint to clean up the parser stack

fullyConsumed(self)

Return whether the string was fully consumed
Returns:
True if the string was read to the last byte, False otherwise

getChar(self)

Get a single character from the string. This methdo returns the next character of the string. If ignore_whitespace is True, this will be the next non-whitespace character.
Returns:
The next character of the string.

getIgnoreState(self)

Return whether the reader is set to ignore whitespaces.
Returns:
True if the reader currently ignores whitespaces, False otherwise.

getPos(self)

Return the current position of this reader
Returns:
the current position of the reader in the string

getString(self, length)

Get a substring of the string from this reader and advance the reader's position. This method returns the current substring of the reader with the given length. Note that even if ignore_whitespace is True, the string will return any containing whitespaces.
Parameters:
length - The length of the string to return
           (type=int)
Returns:
A substring of the given length.

rollback(self)

Rollback the parser to the last checkpoint set. This is called by the rules internally whenever parsing fails and a rollback is necessary.

setIgnoreState(self, state)

Set the ignore state of the reader. This call tells the reader whether it should ignore whitespaces or not.
Parameters:
state - True to ignore whitespace, False to return them
           (type=boolean)

skipWhite(self)

Function to skip the whitespace characters from the current position on.

Generated by Epydoc 2.1 on Sat Feb 10 16:11:43 2007 http://epydoc.sf.net