PK»,6“×2EGG-INFO/dependency_links.txt PK»,6 ¦Â½½EGG-INFO/PKG-INFOMetadata-Version: 1.0 Name: ZestyParser Version: 0.6.0 Summary: A simple but highly flexible approach to parsing Home-page: http://adamatlas.org/2006/12/ZestyParser/ Author: Adam Atlas Author-email: adam@atlas.st License: GPL Description: ZestyParser is a small parsing toolkit for Python. It doesn't use the traditional separated lexer/parser approach, nor does it make you learn a new ugly syntax for specifying grammar. It is based entirely on Python regular expressions and callbacks; its flow is very simple, but can accomodate a vast array of parsing situations. Platform: UNKNOWN Classifier: Development Status :: 4 - Beta Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: GNU General Public License (GPL) Classifier: Natural Language :: English Classifier: Programming Language :: Python Classifier: Topic :: Software Development :: Libraries :: Python Modules Classifier: Topic :: Text Processing PK»,6íÖØÔ Ô EGG-INFO/SOURCES.txtCHANGES.txt LICENSE.txt MANIFEST.in setup.py Docs/epydoc.css Docs/index.html Docs/private/ZestyParser-module.html Docs/private/ZestyParser.AHT-module.html Docs/private/ZestyParser.AHT.Env-class.html Docs/private/ZestyParser.AHT._AHTFactory-class.html Docs/private/ZestyParser.Parser-module.html Docs/private/ZestyParser.Parser.CallbackFor-class.html Docs/private/ZestyParser.Parser.Error-class.html Docs/private/ZestyParser.Parser.NotMatched-class.html Docs/private/ZestyParser.Parser.ParseError-class.html Docs/private/ZestyParser.Parser.ParserIterator-class.html Docs/private/ZestyParser.Parser.ZestyParser-class.html Docs/private/ZestyParser.Tokens-module.html Docs/private/ZestyParser.Tokens.AbstractToken-class.html Docs/private/ZestyParser.Tokens.CompositeToken-class.html Docs/private/ZestyParser.Tokens.Default-class.html Docs/private/ZestyParser.Tokens.Defer-class.html Docs/private/ZestyParser.Tokens.Omit-class.html Docs/private/ZestyParser.Tokens.RawToken-class.html Docs/private/ZestyParser.Tokens.Skip-class.html Docs/private/ZestyParser.Tokens.TakeToken-class.html Docs/private/ZestyParser.Tokens.Token-class.html Docs/private/ZestyParser.Tokens.TokenSequence-class.html Docs/private/ZestyParser.Tokens.TokenSeries-class.html Docs/private/ZestyParser.Tokens._EOF-class.html Docs/private/epydoc.css Docs/private/exceptions.Exception-class.html Docs/private/frames.html Docs/private/help.html Docs/private/index.html Docs/private/indices.html Docs/private/toc-ZestyParser-module.html Docs/private/toc-ZestyParser.AHT-module.html Docs/private/toc-ZestyParser.Parser-module.html Docs/private/toc-ZestyParser.Tokens-module.html Docs/private/toc-everything.html Docs/private/toc.html Docs/private/trees.html Docs/public/ZestyParser-module.html Docs/public/ZestyParser.AHT-module.html Docs/public/ZestyParser.AHT.Env-class.html Docs/public/ZestyParser.Parser-module.html Docs/public/ZestyParser.Parser.CallbackFor-class.html Docs/public/ZestyParser.Parser.NotMatched-class.html Docs/public/ZestyParser.Parser.ParseError-class.html Docs/public/ZestyParser.Parser.ZestyParser-class.html Docs/public/ZestyParser.Tokens-module.html Docs/public/ZestyParser.Tokens.AbstractToken-class.html Docs/public/ZestyParser.Tokens.CompositeToken-class.html Docs/public/ZestyParser.Tokens.Default-class.html Docs/public/ZestyParser.Tokens.Defer-class.html Docs/public/ZestyParser.Tokens.Omit-class.html Docs/public/ZestyParser.Tokens.RawToken-class.html Docs/public/ZestyParser.Tokens.Skip-class.html Docs/public/ZestyParser.Tokens.TakeToken-class.html Docs/public/ZestyParser.Tokens.Token-class.html Docs/public/ZestyParser.Tokens.TokenSequence-class.html Docs/public/ZestyParser.Tokens.TokenSeries-class.html Docs/public/epydoc.css Docs/public/exceptions.Exception-class.html Docs/public/frames.html Docs/public/help.html Docs/public/index.html Docs/public/indices.html Docs/public/toc-ZestyParser-module.html Docs/public/toc-ZestyParser.AHT-module.html Docs/public/toc-ZestyParser.Parser-module.html Docs/public/toc-ZestyParser.Tokens-module.html Docs/public/toc-everything.html Docs/public/toc.html Docs/public/trees.html ZestyParser/AHT.py ZestyParser/Parser.py ZestyParser/Tokens.py ZestyParser/__init__.py ZestyParser.egg-info/PKG-INFO ZestyParser.egg-info/SOURCES.txt ZestyParser.egg-info/dependency_links.txt ZestyParser.egg-info/top_level.txt examples/bdecode.py examples/calcy.py examples/elements.py examples/n3.py examples/n3rdflib.py examples/phpserialize.py examples/plist.py examples/sexp-bench.py examples/sexp.py examples/testy.py PK»,6µ& EGG-INFO/top_level.txtZestyParser PK»,6“×2EGG-INFO/zip-safe PKÕº+6àÎúö::ZestyParser/__init__.py# ZestyParser 0.6.0 -- Parses in Python zestily # Copyright (C) 2006-2007 Adam Atlas # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ''' @version: 0.6.0 @author: Adam Atlas @copyright: Copyright 2006-2007 Adam Atlas. Released under the terms of the GNU General Public License. @contact: adam@atlas.st @group Parsing: Parser,Tokens @group Utilities: AHT ''' from Parser import * from Tokens import * from AHT import *PK»,6ŸÜ×€¾¾ZestyParser/__init__.pyc;ò  §Ec@sdZdkTdkTdkTdS(sÚ @version: 0.6.0 @author: Adam Atlas @copyright: Copyright 2006-2007 Adam Atlas. Released under the terms of the GNU General Public License. @contact: adam@atlas.st @group Parsing: Parser,Tokens @group Utilities: AHT (s*N(s__doc__sParsersTokenssAHT(((s9build/bdist.darwin-8.8.2-i386/egg/ZestyParser/__init__.pys?sPK'+6¢µo¹I I ZestyParser/AHT.py# ZestyParser 0.6.0 -- Parses in Python zestily # Copyright (C) 2006-2007 Adam Atlas # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ''' @version: 0.6.0 @author: Adam Atlas @copyright: Copyright 2006-2007 Adam Atlas. Released under the terms of the GNU General Public License. @contact: adam@atlas.st AHT (Ad Hoc Types) is a utility module providing an easy way to generate "labels" for objects in abstract parse trees without defining a class for each one. To use it, create an instance of L{Env}. Now you can access any property on it and get a unique type for that name. The first time such a type is called, it becomes a subclass of the type of whatever it is passed. For example, C{EnvInstance.SomeEntity("hi")} marks C{SomeEntity} as being a subclass of C{str}, and returns an instance of itself initialized with C{"hi"}.) Now you can check at any time with nothing more than a C{isinstance(something, EnvInstance.SomeEntity)} how a piece of data was instantiated. Ad Hoc Types are primarily intended to be used in conjunction with L{AbstractToken} types, where you should set it as the C{as} parameter, or, if it is more convenient (e.g. when you must use C{>>}), as its callback. ''' from types import ClassType __all__ = ('Env',) class Env: ''' @see: L{AHT} ''' _aht_types = {} def __getattr__(self, attr): if attr in self._aht_types: return self._aht_types[attr] else: return _AHTFactory(self, attr) class _AHTFactory: def __init__(self, env, name): self.env, self.name = env, name def __call__(self, arg): if self.name not in self.env._aht_types: self.env._aht_types[self.name] = ClassType(self.name, (arg.__class__,), {}) return self.env._aht_types[self.name](arg)PK»,6‰3Ûœq q ZestyParser/AHT.pyc;ò »Á¦Ec@sFdZdklZdfZdfd„ƒYZdfd„ƒYZdS(s @version: 0.6.0 @author: Adam Atlas @copyright: Copyright 2006-2007 Adam Atlas. Released under the terms of the GNU General Public License. @contact: adam@atlas.st AHT (Ad Hoc Types) is a utility module providing an easy way to generate "labels" for objects in abstract parse trees without defining a class for each one. To use it, create an instance of L{Env}. Now you can access any property on it and get a unique type for that name. The first time such a type is called, it becomes a subclass of the type of whatever it is passed. For example, C{EnvInstance.SomeEntity("hi")} marks C{SomeEntity} as being a subclass of C{str}, and returns an instance of itself initialized with C{"hi"}.) Now you can check at any time with nothing more than a C{isinstance(something, EnvInstance.SomeEntity)} how a piece of data was instantiated. Ad Hoc Types are primarily intended to be used in conjunction with L{AbstractToken} types, where you should set it as the C{as} parameter, or, if it is more convenient (e.g. when you must use C{>>}), as its callback. (s ClassTypesEnvcBstZdZhZd„ZRS(s @see: L{AHT} cCs0||ijo|i|Snt||ƒSdS(N(sattrsselfs _aht_typess _AHTFactory(sselfsattr((s4build/bdist.darwin-8.8.2-i386/egg/ZestyParser/AHT.pys __getattr__)s(s__name__s __module__s__doc__s _aht_typess __getattr__(((s4build/bdist.darwin-8.8.2-i386/egg/ZestyParser/AHT.pysEnv#s s _AHTFactorycBstZd„Zd„ZRS(NcCs||f\|_|_dS(N(senvsnamesself(sselfsenvsname((s4build/bdist.darwin-8.8.2-i386/egg/ZestyParser/AHT.pys__init__0scCs]|i|iijo,t|i|ifhƒ|ii|i}. @ivar context: A dictionary which can be used for storing any necessary state information. @type context: dict @ivar data: The sequence being parsed (probably a string). @type data: sequence @ivar cursor: The current position of the parser in L{data}. @type cursor: int @ivar last: The last matched token. @type last: L{token} ''' context = {} data = None cursor = 0 len = 0 last = None def __init__(self, data=None): '''Initializes the parser, optionally calling L{useData}''' if data: self.useData(data) self.last = None def useData(self, data): ''' Begin parsing a stream of data @param data: The data to parse. @type data: sequence ''' self.data = data self.cursor = 0 self.len = len(data) def scan(self, tokens): ''' Scan for one token. @param tokens: One token, or an iterable of tokens (in which case any of them may match). @return: The return value of the matching token, or None if the token iterable is empty or if all tokens raised NotMatched. @rtype: object @raise ParseError: If a token fails to match and it has a failMessage parameter. ''' if not hasattr(tokens, '__iter__'): tokens = (tokens,) for t in tokens: oldCursor = self.cursor try: r = t(self, oldCursor) self.last = t return r except NotMatched: self.cursor = oldCursor if hasattr(t, 'failMessage') and t.failMessage: raise ParseError(self, t.failMessage) self.last = None return None def skip(self, token): ''' Skip one token. This is a convenience method that may be slightly faster than L{scan} when appropriate. @param token: The token to scan for. (Can't be an iterable as in L{scan}.) @type token: token @return: Whether or not the token matched. @rtype: bool ''' oldCursor = self.cursor try: token(self, oldCursor) except NotMatched: self.cursor = oldCursor if hasattr(token, 'failMessage') and token.failMessage: raise ParseError(self, token.failMessage) else: return False return True def iter(self, tokens, skip=None, until=None): ''' Returns an iterator which scans for L{tokens} every time it is invoked. @param tokens: The tokens to scan for. As with L{scan}, either a single token or an iterable. @param skip: An optional token to L{skip} before each L{scan} for L{tokens}. @type skip: token @param until: An optional 2-tuple. If defined, the iterator will scan for L{tokens} until it reaches the token C{until[0]}; if L{scan} returns C{None} before the iterator encounters this token, it raises a L{ParseError} with the message given in C{until[1]}. @type until: tuple @rtype: iterator ''' return ParserIterator(tokens, self, skip, until) def coord(self, loc=None): ''' Returns row/column coordinates for a given point in the input stream, or L{cursor} by default. Counting starts at C{(1, 1)}. @param loc: An index of L{data}. @type loc: int @return: A 2-tuple representing (row, column). @rtype: tuple ''' if loc is None: loc = self.cursor row = self.data.count('\n', 0, loc) col = loc - self.data.rfind('\n', 0, loc) return (row + 1, col) class ParserIterator: def __init__(self, tokens, parser, skip=None, until=None): self.tokens = tokens self.parser = parser self.skip = skip self.until = until def __iter__(self): return self def next(self): if self.skip: self.parser.skip(self.skip) if self.until and self.parser.skip(self.until[0]): raise StopIteration r = self.parser.scan(self.tokens) if not self.parser.last: if self.until: raise ParseError(self.parser, self.until[1]) else: raise StopIteration return rPK»,6œÁïë"ë"ZestyParser/Parser.pyc;ò §Ec@s—dZddddfZdefd„ƒYZdefd„ƒYZdefd„ƒYZdfd „ƒYZdfd „ƒYZd fd „ƒYZd S(s¥ @version: 0.6.0 @author: Adam Atlas @copyright: Copyright 2006-2007 Adam Atlas. Released under the terms of the GNU General Public License. @contact: adam@atlas.st s ZestyParsers NotMatcheds ParseErrors CallbackForsErrorcBstZRS(N(s__name__s __module__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pysErrorscBstZdZRS(sKRaised by a token if it has failed to match at the parser's current cursor.(s__name__s __module__s__doc__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys NotMatcheds cBs tZdZd„Zd„ZRS(s>Raised by a token to indicate that a parse error has occurred.cCs+|||iƒf\|_|_|_dS(s§ @param parser: The parser instance that encountered the error. @type parser: ZestyParser @param message: A message explaining the error. @type message: str N(sparsersmessagescoordsself(sselfsparsersmessage((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys__init__scCs&d|i|id|idfSdS(sUPrints the error message and the row and column corresponding to the parser's cursor.s%s at line %i column %iiiN(sselfsmessagescoord(sself((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys__str__'s(s__name__s __module__s__doc__s__init__s__str__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys ParseErrors  cBs tZdZd„Zd„ZRS(s< Function decorator indicating that the function should be set as the callback of the given token; returns the token instead of the function. Example:: @CallbackFor(Token('([0-9]+)')) def T_INT(r): print r This is equivalent to:: def T_INT(r): print r T_INT = Token('([0-9]+)', callback=T_INT) cCs ||_dS(N(stokensself(sselfstoken((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys__init__9scCs||i_|iSdS(N(sfuncsselfstokenscallback(sselfsfunc((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys__call__<s (s__name__s __module__s__doc__s__init__s__call__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys CallbackFor+s  cBsntZdZhZeZdZdZeZed„Z d„Z d„Z d„Z eed„Z ed„ZRS(s® Parses one stream of data, by means of L{tokens}. @ivar context: A dictionary which can be used for storing any necessary state information. @type context: dict @ivar data: The sequence being parsed (probably a string). @type data: sequence @ivar cursor: The current position of the parser in L{data}. @type cursor: int @ivar last: The last matched token. @type last: L{token} icCs%|o|i|ƒnt|_dS(s5Initializes the parser, optionally calling L{useData}N(sdatasselfsuseDatasNoneslast(sselfsdata((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys__init__TscCs%||_d|_t|ƒ|_dS(s` Begin parsing a stream of data @param data: The data to parse. @type data: sequence iN(sdatasselfscursorslen(sselfsdata((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pysuseDataYs  cCs¸t|dƒ o |f}nx†|D]~}|i}y |||ƒ}||_|SWq%tj o@||_t|dƒo|i ot ||i ƒ‚q£q%Xq%Wt |_t SdS(sZ Scan for one token. @param tokens: One token, or an iterable of tokens (in which case any of them may match). @return: The return value of the matching token, or None if the token iterable is empty or if all tokens raised NotMatched. @rtype: object @raise ParseError: If a token fails to match and it has a failMessage parameter. s__iter__s failMessageN( shasattrstokensstsselfscursors oldCursorsrslasts NotMatcheds failMessages ParseErrorsNone(sselfstokenssrsts oldCursor((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pysscands      cCsu|i}y|||ƒWnPtj oD||_t|dƒo|iot||iƒ‚qmtSnXt SdS(s Skip one token. This is a convenience method that may be slightly faster than L{scan} when appropriate. @param token: The token to scan for. (Can't be an iterable as in L{scan}.) @type token: token @return: Whether or not the token matched. @rtype: bool s failMessageN( sselfscursors oldCursorstokens NotMatchedshasattrs failMessages ParseErrorsFalsesTrue(sselfstokens oldCursor((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pysskip{s   cCst||||ƒSdS(s@ Returns an iterator which scans for L{tokens} every time it is invoked. @param tokens: The tokens to scan for. As with L{scan}, either a single token or an iterable. @param skip: An optional token to L{skip} before each L{scan} for L{tokens}. @type skip: token @param until: An optional 2-tuple. If defined, the iterator will scan for L{tokens} until it reaches the token C{until[0]}; if L{scan} returns C{None} before the iterator encounters this token, it raises a L{ParseError} with the message given in C{until[1]}. @type until: tuple @rtype: iterator N(sParserIteratorstokenssselfsskipsuntil(sselfstokenssskipsuntil((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pysiters cCs`|tjo |i}n|iidd|ƒ}||iidd|ƒ}|d|fSdS(sú Returns row/column coordinates for a given point in the input stream, or L{cursor} by default. Counting starts at C{(1, 1)}. @param loc: An index of L{data}. @type loc: int @return: A 2-tuple representing (row, column). @rtype: tuple s iiN( slocsNonesselfscursorsdatascountsrowsrfindscol(sselfslocscolsrow((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pyscoordšs  (s__name__s __module__s__doc__scontextsNonesdatascursorslenslasts__init__suseDatasscansskipsiterscoord(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys ZestyParser@s     sParserIteratorcBs)tZeed„Zd„Zd„ZRS(NcCs(||_||_||_||_dS(N(stokenssselfsparsersskipsuntil(sselfstokenssparsersskipsuntil((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys__init__©s   cCs|SdS(N(sself(sself((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys__iter__¯scCs«|io|ii|iƒn|io|ii|idƒo t‚n|ii|iƒ}|ii o1|iot |i|idƒ‚q£t‚n|SdS(Nii( sselfsskipsparsersuntils StopIterationsscanstokenssrslasts ParseError(sselfsr((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pysnext±s $   (s__name__s __module__sNones__init__s__iter__snext(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pysParserIterator¨s N( s__doc__s__all__s ExceptionsErrors NotMatcheds ParseErrors CallbackFors ZestyParsersParserIterator(s CallbackFors NotMatcheds__all__sParserIterators ZestyParsers ParseErrorsError((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Parser.pys?shPKvº+6w©¥O=O=ZestyParser/Tokens.py# ZestyParser 0.6.0 -- Parses in Python zestily # Copyright (C) 2006-2007 Adam Atlas # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ''' @group Basic Tokens: RawToken,Token,TakeToken @group Complex Tokens: CompositeToken,TokenSequence,TokenSeries @group Special Tokens: Defer,EOF,EmptyToken,Default @group TokenSequence Flags: Omit,Skip @version: 0.6.0 @author: Adam Atlas @copyright: Copyright 2006-2007 Adam Atlas. Released under the terms of the GNU General Public License. @contact: adam@atlas.st @var EmptyToken: A L{Default} instance initialized with the empty string. @var EOF: A token which matches (and returns C{None}) if the parser is at the end of its L{data } sequence. In ZestyParser, a token object must, at minimum, be a callable taking a L{ZestyParser } instance and its current L{cursor } as parameters. It can do whatever it needs with the parser's L{data } and L{cursor } properties before returning. It may raise L{NotMatched} to indicate to the L{ZestyParser } instance that it failed to match; it may also raise L{ParseError} to indicate, for instance, that it began matching successfully but encountered an unrecoverable error. The L{Tokens} module contains a variety of predefined token classes (instances of which are callable) and other valid token objects which should cover most parsing situations. ''' import re, copy from Parser import NotMatched, ParseError __all__ = ('AbstractToken', 'Token', 'RawToken', 'CompositeToken', 'TokenSequence', 'TakeToken', 'TokenSeries', 'EmptyToken', 'Default', 'Skip', 'Omit', 'Defer', 'EOF') rstack = [] class AbstractToken: ''' Base class from which most tokens defined in this module derive. Subclassing this is not required for writing tokens, since they can be any callable with certain semantics, but this class provides several useful services for creating reusable token classes, such as callback support and convenient operator overloading. @ivar desc: The generic "description" variable which stores the "essence" of any given instance. Subclasses use this as needed. @ivar callback: An 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 the L{ZestyParser } 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 L{NotMatched} or L{ParseError} with the usual behaviour. They should also return a value, which will be returned to the calling L{ZestyParser } instance. @ivar 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). Its main purpose is to allow you to concisely do things like C{Token('[0-9]+', group=0, as=int)} -- the builtin callable C{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 L{AHT} types, for more complex multi-stage parsing. See the C{n3.py} and C{n3rdflib.py} examples for a demonstration of this. ''' failMessage = None def __init__(self, desc, callback=None, as=None, name=None): self.desc = desc self.callback = callback self.as = as self.name = name def __repr__(self): return '%s %s' % (self.__class__.__name__, (self.name or str(self))) def preprocessResult(self, parser, data, origCursor): ''' Method called by subclasses' C{__call__} methods to add uniform support for the L{callback} and L{as} parameters. Pass your C{__call__} method's return value through this if you're subclassing L{AbstractToken} yourself. ''' if self.callback is not None: try: data = self.callback(data) except TypeError: try: data = self.callback(parser, data) except TypeError: data = self.callback(parser, data, origCursor) if self.as is not None: data = self.as(data) return data def __add__(self, other): '''Allows you to construct L{TokenSequence}s with the + operator.''' return TokenSequence([self, other]) def __or__(self, other): '''Allows you to construct L{CompositeToken}s with the | operator.''' return CompositeToken([self, other]) def __rshift__(self, callback): '''Convenience overloading for setting the L{callback} of a token whose initializer you do not call directly, such as the result of combining tokens with L{+<__add__>} or L{|<__or__>}. @param callback: An L{AbstractToken}-compatible callback. @type callback: callable @return: A copy of C{self} with the L{callback} property set to C{callback}. ''' new = copy.copy(self) new.callback = callback return new def __xor__(self, message): ''' Overloading for setting the L{failMessage} of a token. @param message: The message to be raised with L{ParseError} if this token fails to match. @type message: str @return: A copy of C{self} with the L{failMessage} property set to C{callback}. ''' new = copy.copy(self) new.failMessage = message return new class Token (AbstractToken): ''' A class whose instances match Python regular expressions. @ivar group: If defined, L{__call__} returns that group of the regular expression match instead of the whole match object. @type group: int ''' def __init__(self, regex, callback=None, as=None, name=None, group=None): ''' @param regex: Either a compiled regex object or a string regex. @param group: To be set as the object's L{group} property. @type group: int ''' if not hasattr(regex, 'match'): regex = re.compile(regex, re.DOTALL) AbstractToken.__init__(self, regex, callback, as, name) self.group = group def __call__(self, parser, origCursor): matches = self.desc.match(parser.data, origCursor) if matches is None: raise NotMatched parser.cursor = matches.end() if self.group is not None: matches = matches.group(self.group) return self.preprocessResult(parser, matches, origCursor) def __str__(self): return repr(self.desc.pattern) class RawToken (AbstractToken): ''' A class whose instances match only a particular string. Returns that string. @ivar caseInsensitive: If true, ignores case. @type caseInsensitive: bool ''' def __init__(self, string, callback=None, as=None, name=None, caseInsensitive=False): ''' @param string: The string to match. @type string: str @param caseInsensitive: To be set as the object's L{caseInsensitive} property. @type caseInsensitive: bool ''' AbstractToken.__init__(self, string, callback, as, name) self.len = len(string) self.caseInsensitive = caseInsensitive if caseInsensitive: self.desc = self.desc.lower() def __call__(self, parser, origCursor): end = origCursor + self.len d = parser.data[origCursor:end] if (not self.caseInsensitive and d == self.desc) or (self.caseInsensitive and d.lower() == self.desc): parser.cursor = end return self.preprocessResult(parser, d, origCursor) else: raise NotMatched def __str__(self): return repr(self.desc) class Default (AbstractToken): ''' A class whose instances always return L{desc} and do not advance the parser's cursor. ''' def __call__(self, parser, origCursor): return self.preprocessResult(parser, self.desc, origCursor) EmptyToken = Default('') class CompositeToken (AbstractToken): ''' A class whose instances match any of a number of tokens. @ivar desc: An iterable returning token objects. @type desc: iterable ''' def __call__(self, parser, origCursor): r = parser.scan(self.desc) if parser.last is None: raise NotMatched return self.preprocessResult(parser, r, origCursor) def __str__(self): if self in rstack: return '...' else: rstack.append(self) d = '(' + ' | '.join([repr(t) for t in self.desc]) + ')' rstack.pop() return d def __or__(self, other): if isinstance(other, CompositeToken): return CompositeToken(self.desc + other.desc) elif hasattr(other, '__iter__'): return CompositeToken(self.desc + list(other)) else: return CompositeToken(self.desc + [other]) def __ior__(self, other): if isinstance(other, CompositeToken): self.desc += other.desc elif hasattr(other, '__iter__'): self.desc += list(other) else: self.desc.append(other) return self class TokenSequence (AbstractToken): ''' A class whose instances match a sequence of tokens. Returns a corresponding list of return values from L{ZestyParser.scan}. Two special types, L{Skip} and L{Omit}, are allowed in the sequence. These are wrappers for other token objects adding special behaviours. If it encounters a L{Skip} token, it will process it with L{ZestyParser.skip}, ignore whether it matched, and not include it in the list. If it encounters a L{Omit} token, it will still require that it match (the default behaviour), but it will not be included in the list. @ivar desc: An iterable returning token objects. @type desc: iterable ''' def __call__(self, parser, origCursor): o = [] for g in self.desc: r = parser.scan(g) if parser.last is None: raise NotMatched if not isinstance(parser.last, (Skip, Omit)): o.append(r) return self.preprocessResult(parser, o, origCursor) def __str__(self): if self in rstack: return '...' else: rstack.append(self) d = '(' + ' + '.join([repr(t) for t in self.desc]) + ')' rstack.pop() return d def __add__(self, other): if isinstance(other, TokenSequence): return TokenSequence(self.desc + other.desc) elif hasattr(other, '__iter__'): return TokenSequence(self.desc + list(other)) else: return TokenSequence(self.desc + [other]) def __iadd__(self, other): if isinstance(other, TokenSequence): self.desc += other.desc elif hasattr(other, '__iter__'): self.desc += list(other) else: self.desc.append(other) return self class TakeToken (AbstractToken): ''' A class whose instances match and return a given number of characters from the parser's L{data}. Raises L{NotMatched} if not enough characters are left. ''' def __init__(self, length, callback=None, as=None, name=None): AbstractToken.__init__(self, length, callback, as, name) def __call__(self, parser, start): end = start + self.desc if parser.len < end: raise NotMatched parser.cursor = end return parser.data[start:end] class TokenSeries (AbstractToken): ''' A particularly versatile class whose instances match one token multiple times. The properties L{skip}, L{prefix}, L{postfix}, and L{delimiter} are optional tokens which add structure to the series. It can be represented, approximately in the idioms of L{TokenSequence}, as follows:: [Skip(skip) + Omit(prefix) + desc + Omit(postfix)] + [Skip(skip) + Omit(delimiter) + Skip(skip) + Omit(prefix) + desc + Omit(postfix)] + ... + Skip(skip) Or, if there is no delimiter:: [Skip(skip) + Omit(prefix) + desc + Omit(postfix)] + ... + Skip(skip) @ivar desc: The token to match. @type desc: token @ivar min: The minimum number of times L{desc} must match. @type min: int @ivar max: The maximum number of times L{desc} will try to match. @type max: int @ivar skip: An optional token to skip between matches. @type skip: token @ivar prefix: An optional token to require (but omit from the return value) before each instance of L{token}. @type prefix: token @ivar postfix: An optional token to require (but omit from the return value) after each instance of L{token}. @type postfix: token @ivar delimiter: An optional token to require (but omit from the return value) between each instance of L{token}. @type delimiter: token @ivar until: An optional 2-tuple whose first item is a token, and whose second item is either a message or False. The presence of this property indicates that the token in C{until[0]} must match at the end of the series. If this fails, then if C{until[1]} is a message, a ParseError will be raised with that message; if it is False, NotMatched will be raised. ''' def __init__(self, token, min=0, max=False, skip=EmptyToken, prefix=EmptyToken, postfix=EmptyToken, delimiter=None, until=None, includeDelimiter=False, callback=None, as=None, name=None): AbstractToken.__init__(self, token, callback, as, name) self.min, self.max, self.skip, self.prefix, self.postfix, self.delimiter, self.until, self.includeDelimiter = min, max, skip, prefix, postfix, delimiter, until, includeDelimiter def __call__(self, parser, origCursor): o = [] i = 0 done = False while (self.max is False or i != self.max): if self.until and parser.skip(self.until[0]): done = True; break parser.skip(self.skip) c = parser.cursor if i != 0 and self.delimiter is not None: d = parser.scan(self.delimiter) if parser.last is None: parser.cursor = c; break parser.skip(self.skip) if not parser.skip(self.prefix): parser.cursor = c; break t = parser.scan(self.desc) if parser.last is None: parser.cursor = c; break if not parser.skip(self.postfix): parser.cursor = c; break if i != 0 and self.includeDelimiter: o.append(d) o.append(t) i += 1 if not done and self.until: if self.until[1]: raise ParseError(parser, self.until[1]) else: raise NotMatched if len(o) >= self.min: return self.preprocessResult(parser, o, origCursor) else: raise NotMatched class Defer (AbstractToken): ''' A token which takes a callable (generally a lambda) which takes no arguments and itself returns a token. A Defer instance, upon being called, will call this function, scan for the returned token, and return that return value. This is primarily intended to allow you to define tokens recursively; if you need to refer to a token that hasn't been defined yet, simply use C{Defer(lambda: T_SOME_TOKEN)}, where C{T_SOME_TOKEN} is the token's eventual name. ''' def __init__(self, func, callback=None, as=None, name=None): AbstractToken.__init__(self, func, callback, as, name) def __call__(self, parser, origCursor): t = parser.scan(self.desc()) if parser.last is None: raise NotMatched return t class Skip (AbstractToken): ''' See L{TokenSequence}. ''' def __call__(self, parser, origCursor): parser.skip(self.desc) class Omit(AbstractToken): ''' See L{TokenSequence}. ''' def __call__(self, parser, origCursor): if not parser.skip(self.desc): raise NotMatched class _EOF(AbstractToken): def __call__(self, parser, origCursor): if parser.cursor != parser.len: raise NotMatched EOF = _EOF(None) PK»,6ë¸oBJ\J\ZestyParser/Tokens.pyc;ò ` §Ec @sdZdkZdkZdklZlZddddddd d d d d ddf ZgZdfd„ƒYZdefd„ƒYZ defd„ƒYZ d efd„ƒYZ e dƒZ defd„ƒYZ defd„ƒYZdefd„ƒYZd efd„ƒYZdefd„ƒYZd efd„ƒYZd efd„ƒYZdefd„ƒYZeeƒZdS(s  @group Basic Tokens: RawToken,Token,TakeToken @group Complex Tokens: CompositeToken,TokenSequence,TokenSeries @group Special Tokens: Defer,EOF,EmptyToken,Default @group TokenSequence Flags: Omit,Skip @version: 0.6.0 @author: Adam Atlas @copyright: Copyright 2006-2007 Adam Atlas. Released under the terms of the GNU General Public License. @contact: adam@atlas.st @var EmptyToken: A L{Default} instance initialized with the empty string. @var EOF: A token which matches (and returns C{None}) if the parser is at the end of its L{data } sequence. In ZestyParser, a token object must, at minimum, be a callable taking a L{ZestyParser } instance and its current L{cursor } as parameters. It can do whatever it needs with the parser's L{data } and L{cursor } properties before returning. It may raise L{NotMatched} to indicate to the L{ZestyParser } instance that it failed to match; it may also raise L{ParseError} to indicate, for instance, that it began matching successfully but encountered an unrecoverable error. The L{Tokens} module contains a variety of predefined token classes (instances of which are callable) and other valid token objects which should cover most parsing situations. N(s NotMatcheds ParseErrors AbstractTokensTokensRawTokensCompositeTokens TokenSequences TakeTokens TokenSeriess EmptyTokensDefaultsSkipsOmitsDefersEOFcBs\tZdZeZeeed„Zd„Zd„Zd„Zd„Z d„Z d„Z RS(s> Base class from which most tokens defined in this module derive. Subclassing this is not required for writing tokens, since they can be any callable with certain semantics, but this class provides several useful services for creating reusable token classes, such as callback support and convenient operator overloading. @ivar desc: The generic "description" variable which stores the "essence" of any given instance. Subclasses use this as needed. @ivar callback: An 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 the L{ZestyParser } 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 L{NotMatched} or L{ParseError} with the usual behaviour. They should also return a value, which will be returned to the calling L{ZestyParser } instance. @ivar 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). Its main purpose is to allow you to concisely do things like C{Token('[0-9]+', group=0, as=int)} -- the builtin callable C{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 L{AHT} types, for more complex multi-stage parsing. See the C{n3.py} and C{n3rdflib.py} examples for a demonstration of this. cCs(||_||_||_||_dS(N(sdescsselfscallbacksassname(sselfsdescscallbacksassname((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__init__6s   cCs(d|ii|ip t|ƒfSdS(Ns%s %s(sselfs __class__s__name__snamesstr(sself((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__repr__<scCs©|itj ony|i|ƒ}Wq~tj oHy|i||ƒ}Wqztj o|i|||ƒ}qzXq~Xn|itj o|i|ƒ}n|SdS(sá Method called by subclasses' C{__call__} methods to add uniform support for the L{callback} and L{as} parameters. Pass your C{__call__} method's return value through this if you're subclassing L{AbstractToken} yourself. N(sselfscallbacksNonesdatas TypeErrorsparsers origCursorsas(sselfsparsersdatas origCursor((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pyspreprocessResult?s#cCst||gƒSdS(s>Allows you to construct L{TokenSequence}s with the + operator.N(s TokenSequencesselfsother(sselfsother((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__add__LscCst||gƒSdS(s?Allows you to construct L{CompositeToken}s with the | operator.N(sCompositeTokensselfsother(sselfsother((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__or__PscCs ti|ƒ}||_|SdS(s‘Convenience overloading for setting the L{callback} of a token whose initializer you do not call directly, such as the result of combining tokens with L{+<__add__>} or L{|<__or__>}. @param callback: An L{AbstractToken}-compatible callback. @type callback: callable @return: A copy of C{self} with the L{callback} property set to C{callback}. N(scopysselfsnewscallback(sselfscallbacksnew((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys __rshift__Ts cCs ti|ƒ}||_|SdS(s9 Overloading for setting the L{failMessage} of a token. @param message: The message to be raised with L{ParseError} if this token fails to match. @type message: str @return: A copy of C{self} with the L{failMessage} property set to C{callback}. N(scopysselfsnewsmessages failMessage(sselfsmessagesnew((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__xor___s ( s__name__s __module__s__doc__sNones failMessages__init__s__repr__spreprocessResults__add__s__or__s __rshift__s__xor__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys AbstractToken,s     cBs5tZdZeeeed„Zd„Zd„ZRS(sÍ A class whose instances match Python regular expressions. @ivar group: If defined, L{__call__} returns that group of the regular expression match instead of the whole match object. @type group: int cCsPt|dƒ oti|tiƒ}nti|||||ƒ||_ dS(s• @param regex: Either a compiled regex object or a string regex. @param group: To be set as the object's L{group} property. @type group: int smatchN( shasattrsregexsrescompilesDOTALLs AbstractTokens__init__sselfscallbacksassnamesgroup(sselfsregexscallbacksassnamesgroup((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__init__ts cCs{|ii|i|ƒ}|tjo t‚n|i ƒ|_ |i tj o|i |i ƒ}n|i |||ƒSdS(N( sselfsdescsmatchsparsersdatas origCursorsmatchessNones NotMatchedsendscursorsgroupspreprocessResult(sselfsparsers origCursorsmatches((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call__s cCst|iiƒSdS(N(sreprsselfsdescspattern(sself((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__str__‡s(s__name__s __module__s__doc__sNones__init__s__call__s__str__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pysTokenls  cBs5tZdZeeeed„Zd„Zd„ZRS(sž A class whose instances match only a particular string. Returns that string. @ivar caseInsensitive: If true, ignores case. @type caseInsensitive: bool cCsRti|||||ƒt|ƒ|_||_|o|i i ƒ|_ ndS(s¬ @param string: The string to match. @type string: str @param caseInsensitive: To be set as the object's L{caseInsensitive} property. @type caseInsensitive: bool N( s AbstractTokens__init__sselfsstringscallbacksassnameslenscaseInsensitivesdescslower(sselfsstringscallbacksassnamescaseInsensitive((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__init__‘s  cCs‚||i}|i||!}|i o ||ijp|io|i ƒ|ijo ||_ |i |||ƒSnt ‚dS(N( s origCursorsselfslensendsparsersdatasdscaseInsensitivesdescslowerscursorspreprocessResults NotMatched(sselfsparsers origCursorsendsd((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call__žs  ; cCst|iƒSdS(N(sreprsselfsdesc(sself((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__str__¦s(s__name__s __module__s__doc__sNonesFalses__init__s__call__s__str__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pysRawTokenŠs  cBstZdZd„ZRS(sY A class whose instances always return L{desc} and do not advance the parser's cursor. cCs|i||i|ƒSdS(N(sselfspreprocessResultsparsersdescs origCursor(sselfsparsers origCursor((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call__­s(s__name__s __module__s__doc__s__call__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pysDefault©s scBs2tZdZd„Zd„Zd„Zd„ZRS(s† A class whose instances match any of a number of tokens. @ivar desc: An iterable returning token objects. @type desc: iterable cCsC|i|iƒ}|itjo t‚n|i|||ƒSdS(N( sparsersscansselfsdescsrslastsNones NotMatchedspreprocessResults origCursor(sselfsparsers origCursorsr((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call__¹s cCsu|tjodSn]ti|ƒddigi}|iD]}|t|ƒƒq<~ƒd}ti ƒ|SdS(Ns...s(s | s)( sselfsrstacksappendsjoins_[1]sdescstsreprsdspop(sselfsds_[1]st((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__str__¾s   A cCskt|tƒot|i|iƒSn@t|dƒot|it|ƒƒSnt|i|gƒSdS(Ns__iter__(s isinstancesothersCompositeTokensselfsdescshasattrslist(sselfsother((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__or__Çs cCsgt|tƒo|i|i7_n:t|dƒo|it|ƒ7_n|ii|ƒ|SdS(Ns__iter__(s isinstancesothersCompositeTokensselfsdescshasattrslistsappend(sselfsother((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__ior__Ïs (s__name__s __module__s__doc__s__call__s__str__s__or__s__ior__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pysCompositeToken²s   cBs2tZdZd„Zd„Zd„Zd„ZRS(si A class whose instances match a sequence of tokens. Returns a corresponding list of return values from L{ZestyParser.scan}. Two special types, L{Skip} and L{Omit}, are allowed in the sequence. These are wrappers for other token objects adding special behaviours. If it encounters a L{Skip} token, it will process it with L{ZestyParser.skip}, ignore whether it matched, and not include it in the list. If it encounters a L{Omit} token, it will still require that it match (the default behaviour), but it will not be included in the list. @ivar desc: An iterable returning token objects. @type desc: iterable cCs…g}xe|iD]Z}|i|ƒ}|itjo t ‚nt |it t fƒ o|i |ƒqqW|i|||ƒSdS(N(sosselfsdescsgsparsersscansrslastsNones NotMatcheds isinstancesSkipsOmitsappendspreprocessResults origCursor(sselfsparsers origCursorsgsosr((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call__ás  cCsu|tjodSn]ti|ƒddigi}|iD]}|t|ƒƒq<~ƒd}ti ƒ|SdS(Ns...s(s + s)( sselfsrstacksappendsjoins_[1]sdescstsreprsdspop(sselfsds_[1]st((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__str__és   A cCskt|tƒot|i|iƒSn@t|dƒot|it|ƒƒSnt|i|gƒSdS(Ns__iter__(s isinstancesothers TokenSequencesselfsdescshasattrslist(sselfsother((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__add__òs cCsgt|tƒo|i|i7_n:t|dƒo|it|ƒ7_n|ii|ƒ|SdS(Ns__iter__(s isinstancesothers TokenSequencesselfsdescshasattrslistsappend(sselfsother((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__iadd__ús (s__name__s __module__s__doc__s__call__s__str__s__add__s__iadd__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys TokenSequenceØs   cBs)tZdZeeed„Zd„ZRS(s® A class whose instances match and return a given number of characters from the parser's L{data}. Raises L{NotMatched} if not enough characters are left. cCsti|||||ƒdS(N(s AbstractTokens__init__sselfslengthscallbacksassname(sselfslengthscallbacksassname((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__init__scCsB||i}|i|jo t‚n||_|i||!SdS(N( sstartsselfsdescsendsparserslens NotMatchedscursorsdata(sselfsparsersstartsend((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call__ s    (s__name__s __module__s__doc__sNones__init__s__call__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys TakeTokens c BsAtZdZdeeeeeeeeeed„ Zd„ZRS(sH A particularly versatile class whose instances match one token multiple times. The properties L{skip}, L{prefix}, L{postfix}, and L{delimiter} are optional tokens which add structure to the series. It can be represented, approximately in the idioms of L{TokenSequence}, as follows:: [Skip(skip) + Omit(prefix) + desc + Omit(postfix)] + [Skip(skip) + Omit(delimiter) + Skip(skip) + Omit(prefix) + desc + Omit(postfix)] + ... + Skip(skip) Or, if there is no delimiter:: [Skip(skip) + Omit(prefix) + desc + Omit(postfix)] + ... + Skip(skip) @ivar desc: The token to match. @type desc: token @ivar min: The minimum number of times L{desc} must match. @type min: int @ivar max: The maximum number of times L{desc} will try to match. @type max: int @ivar skip: An optional token to skip between matches. @type skip: token @ivar prefix: An optional token to require (but omit from the return value) before each instance of L{token}. @type prefix: token @ivar postfix: An optional token to require (but omit from the return value) after each instance of L{token}. @type postfix: token @ivar delimiter: An optional token to require (but omit from the return value) between each instance of L{token}. @type delimiter: token @ivar until: An optional 2-tuple whose first item is a token, and whose second item is either a message or False. The presence of this property indicates that the token in C{until[0]} must match at the end of the series. If this fails, then if C{until[1]} is a message, a ParseError will be raised with that message; if it is False, NotMatched will be raised. ic Cskti||| | | ƒ|||||||| f\|_|_|_ |_ |_ |_ |_ |_dS(N(s AbstractTokens__init__sselfstokenscallbacksassnamesminsmaxsskipsprefixspostfixs delimitersuntilsincludeDelimiter( sselfstokensminsmaxsskipsprefixspostfixs delimitersuntilsincludeDelimiterscallbacksassname((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__init__-sc Csg}d}t}x~|itjp ||ijo]|io|i|idƒo t }Pn|i|iƒ|i }|djo |i t j oD|i|i ƒ}|it jo||_ Pn|i|iƒn|i|iƒ o||_ Pn|i|iƒ}|it jo||_ Pn|i|iƒ o||_ Pn|djo|io|i|ƒn|i|ƒ|d7}qW| o|io2|idot||idƒ‚q×t‚nt|ƒ|ijo|i|||ƒSnt‚dS(Nii(sosisFalsesdonesselfsmaxsuntilsparsersskipsTruescursorscs delimitersNonesscansdslastsprefixsdescstspostfixsincludeDelimitersappends ParseErrors NotMatchedslensminspreprocessResults origCursor( sselfsparsers origCursorscsdsisosdonest((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call__1s@ !    (s__name__s __module__s__doc__sFalses EmptyTokensNones__init__s__call__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys TokenSeriess *cBs)tZdZeeed„Zd„ZRS(sÈ A token which takes a callable (generally a lambda) which takes no arguments and itself returns a token. A Defer instance, upon being called, will call this function, scan for the returned token, and return that return value. This is primarily intended to allow you to define tokens recursively; if you need to refer to a token that hasn't been defined yet, simply use C{Defer(lambda: T_SOME_TOKEN)}, where C{T_SOME_TOKEN} is the token's eventual name. cCsti|||||ƒdS(N(s AbstractTokens__init__sselfsfuncscallbacksassname(sselfsfuncscallbacksassname((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__init__SscCs7|i|iƒƒ}|itjo t‚n|SdS(N(sparsersscansselfsdescstslastsNones NotMatched(sselfsparsers origCursorst((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call__Vs (s__name__s __module__s__doc__sNones__init__s__call__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pysDeferNs cBstZdZd„ZRS(s See L{TokenSequence}. cCs|i|iƒdS(N(sparsersskipsselfsdesc(sselfsparsers origCursor((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call___s(s__name__s __module__s__doc__s__call__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pysSkip[s cBstZdZd„ZRS(s See L{TokenSequence}. cCs"|i|iƒ o t‚ndS(N(sparsersskipsselfsdescs NotMatched(sselfsparsers origCursor((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call__fs(s__name__s __module__s__doc__s__call__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pysOmitbs s_EOFcBstZd„ZRS(NcCs!|i|ijo t‚ndS(N(sparserscursorslens NotMatched(sselfsparsers origCursor((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys__call__js(s__name__s __module__s__call__(((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys_EOFis(s__doc__srescopysParsers NotMatcheds ParseErrors__all__srstacks AbstractTokensTokensRawTokensDefaults EmptyTokensCompositeTokens TokenSequences TakeTokens TokenSeriessDefersSkipsOmits_EOFsNonesEOF(sDefers NotMatcheds TokenSequences__all__sDefaultsSkips TokenSeriess AbstractTokensCompositeTokens ParseErrorsresTokensrstacksOmits TakeTokensRawTokenscopysEOFs_EOFs EmptyToken((s7build/bdist.darwin-8.8.2-i386/egg/ZestyParser/Tokens.pys?#s$-@ &+= PK»,6“×2¤EGG-INFO/dependency_links.txtPK»,6 ¦Â½½¤<EGG-INFO/PKG-INFOPK»,6íÖØÔ Ô ¤(EGG-INFO/SOURCES.txtPK»,6µ& ¤.EGG-INFO/top_level.txtPK»,6“×2¤nEGG-INFO/zip-safePKÕº+6àÎúö::¤žZestyParser/__init__.pyPK»,6ŸÜ×€¾¾¤ ZestyParser/__init__.pycPK'+6¢µo¹I I ¤ZestyParser/AHT.pyPK»,6‰3Ûœq q ¤z"ZestyParser/AHT.pycPK8¹+6äÐö4^^¤-ZestyParser/Parser.pyPK»,6œÁïë"ë"¤­DZestyParser/Parser.pycPKvº+6w©¥O=O=¤ÌgZestyParser/Tokens.pyPK»,6ë¸oBJ\J\¤N¥ZestyParser/Tokens.pycPK iÌ