Home | Trees | Index | Help |
---|
Package ZestyParser :: Module Tokens :: Class AbstractToken |
|
CompositeToken
,
Default
,
Defer
,
Omit
,
RawToken
,
Skip
,
TakeToken
,
Token
,
TokenSequence
,
TokenSeries
,
_EOF
Method Summary | |
---|---|
__init__(self,
desc,
callback,
as,
name)
| |
Allows you to construct TokenSequence s with the + operator. | |
Allows you to construct CompositeToken s with the | operator. | |
__repr__(self)
| |
Convenience overloading for setting the callback of a token whose initializer you
do not call directly, such as the result of combining tokens with + or | . | |
Overloading for setting the failMessage of a token. | |
Method called by subclasses' __call__ methods to add
uniform support for the callback and as parameters. |
Instance Variable Summary | |
---|---|
as : An optional callable which, if not None, will be called in the same
manner as a callback (after any callback and before returning to the
parser instance), but will be passed only one argument: the data matched
(or returned by the callback, if any). | |
callback : An optional callable which, if not None, will be called whenever an
instance matches successfully. | |
desc : The generic "description" variable which stores the
"essence" of any given instance. |
Class Variable Summary | |
---|---|
NoneType |
failMessage = None |
Method Details |
---|
__add__(self,
other)
Allows you to construct |
__or__(self,
other)
Allows you to construct |
__rshift__(self, callback)Convenience overloading for setting thecallback of a token whose initializer you
do not call directly, such as the result of combining tokens with + or | .
|
__xor__(self, message)Overloading for setting thefailMessage of a token.
|
preprocessResult(self, parser, data, origCursor)Method called by subclasses'__call__ methods to add
uniform support for the callback and as parameters. Pass your
__call__ method's return value through this if you're
subclassing AbstractToken yourself.
|
Instance Variable Details |
---|
asAn optional callable which, if not None, will be called in the same manner as a callback (after any callback and before returning to the parser instance), but will be passed only one argument: the data matched (or returned by the callback, if any). Its main purpose is to allow you to concisely do things likeToken('[0-9]+', group=0, as=int)
-- the builtin callable int will be passed the text matched
by the regex, so the token will ultimately return an integer instead of a
string or a regex match object. You can also use this property with AHT
types, for more complex multi-stage parsing. See the n3.py
and n3rdflib.py examples for a demonstration of this.
|
callbackAn optional callable which, if not None, will be called whenever an instance matches successfully. It may take one, two, or three parameters, depending on its needs. If one, it will be passed whatever data the token matched (i.e. whatever it would normally have returned upon being called). If two, it will be passed theZestyParser instance and the data. If
three, it will be passed the parser, the data, and the what the parser's
cursor was when this token started matching. Callbacks may raise NotMatched or ParseError with the usual behaviour. They
should also return a value, which will be returned to the calling ZestyParser instance.
|
descThe generic "description" variable which stores the "essence" of any given instance. Subclasses use this as needed. |
Class Variable Details |
---|
failMessage
|
Home | Trees | Index | Help |
---|
Generated by Epydoc 2.1 on Thu Jan 11 23:26:09 2007 | http://epydoc.sf.net |