Package ZestyParser :: Module Parser :: Class ZestyParser
[show private | hide private]
[frames | no frames]

Class ZestyParser


Parses one stream of data, by means of tokens.
Method Summary
  __init__(self, data)
Initializes the parser, optionally calling useData
tuple coord(self, loc)
Returns row/column coordinates for a given point in the input stream, or cursor by default.
iterator iter(self, tokens, skip, until)
Returns an iterator which scans for tokens every time it is invoked.
object scan(self, tokens)
Scan for one token.
bool skip(self, token)
Skip one token.
  useData(self, data)
Begin parsing a stream of data

Instance Variable Summary
dict context: A dictionary which can be used for storing any necessary state information.
int cursor: The current position of the parser in data.
sequence data: The sequence being parsed (probably a string).
token last: The last matched token.

Class Variable Summary
int len = 0                                                                     

Method Details

__init__(self, data=None)
(Constructor)

Initializes the parser, optionally calling useData

coord(self, loc=None)

Returns row/column coordinates for a given point in the input stream, or cursor by default. Counting starts at (1, 1).
Parameters:
loc - An index of data.
           (type=int)
Returns:
A 2-tuple representing (row, column).
           (type=tuple)

iter(self, tokens, skip=None, until=None)

Returns an iterator which scans for tokens every time it is invoked.
Parameters:
tokens - The tokens to scan for. As with scan, either a single token or an iterable.
skip - An optional token to skip before each scan for tokens.
           (type=token)
until - An optional 2-tuple. If defined, the iterator will scan for tokens until it reaches the token until[0]; if scan returns None before the iterator encounters this token, it raises a ParseError with the message given in until[1].
           (type=tuple)
Returns:
iterator

scan(self, tokens)

Scan for one token.
Parameters:
tokens - One token, or an iterable of tokens (in which case any of them may match).
Returns:
The return value of the matching token, or None if the token iterable is empty or if all tokens raised NotMatched.
           (type=object)
Raises:
ParseError - If a token fails to match and it has a failMessage parameter.

skip(self, token)

Skip one token. This is a convenience method that may be slightly faster than scan when appropriate.
Parameters:
token - The token to scan for. (Can't be an iterable as in scan.)
           (type=token)
Returns:
Whether or not the token matched.
           (type=bool)

useData(self, data)

Begin parsing a stream of data
Parameters:
data - The data to parse.
           (type=sequence)

Instance Variable Details

context

A dictionary which can be used for storing any necessary state information.
Type:
dict
Value:
{}                                                                     

cursor

The current position of the parser in data.
Type:
int
Value:
0                                                                     

data

The sequence being parsed (probably a string).
Type:
sequence
Value:
None                                                                  

last

The last matched token.
Type:
token
Value:
None                                                                  

Class Variable Details

len

Type:
int
Value:
0                                                                     

Generated by Epydoc 2.1 on Thu Jan 11 23:26:09 2007 http://epydoc.sf.net