<s> __doc__ = """<STR_LIT>""" <EOL> __version__ = "<STR_LIT>" <EOL> __versionTime__ = "<STR_LIT>" <EOL> __author__ = "<STR_LIT>" <EOL> import string <EOL> from weakref import ref as wkref <EOL> import copy <EOL> import sys <EOL> import warnings <EOL> import re <EOL> import sre_constants <EOL> import collections <EOL> import pprint <EOL> __all__ = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> ] <EOL> PY_3 = sys . version . startswith ( '<STR_LIT:3>' ) <EOL> if PY_3 : <EOL> _MAX_INT = sys . maxsize <EOL> basestring = str <EOL> unichr = chr <EOL> _ustr = str <EOL> singleArgBuiltins = [ sum , len , sorted , reversed , list , tuple , set , any , all , min , max ] <EOL> else : <EOL> _MAX_INT = sys . maxint <EOL> range = xrange <EOL> def _ustr ( obj ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( obj , unicode ) : <EOL> return obj <EOL> try : <EOL> return str ( obj ) <EOL> except UnicodeEncodeError : <EOL> return unicode ( obj ) <EOL> singleArgBuiltins = [ ] <EOL> import __builtin__ <EOL> for fname in "<STR_LIT>" . split ( ) : <EOL> try : <EOL> singleArgBuiltins . append ( getattr ( __builtin__ , fname ) ) <EOL> except AttributeError : <EOL> continue <EOL> _generatorType = type ( ( y for y in range ( <NUM_LIT:1> ) ) ) <EOL> def _xml_escape ( data ) : <EOL> """<STR_LIT>""" <EOL> from_symbols = '<STR_LIT>' <EOL> to_symbols = ( '<STR_LIT:&>' + s + '<STR_LIT:;>' for s in "<STR_LIT>" . split ( ) ) <EOL> for from_ , to_ in zip ( from_symbols , to_symbols ) : <EOL> data = data . replace ( from_ , to_ ) <EOL> return data <EOL> class _Constants ( object ) : <EOL> pass <EOL> alphas = string . ascii_lowercase + string . ascii_uppercase <EOL> nums = "<STR_LIT>" <EOL> hexnums = nums + "<STR_LIT>" <EOL> alphanums = alphas + nums <EOL> _bslash = chr ( <NUM_LIT> ) <EOL> printables = "<STR_LIT>" . join ( c for c in string . printable if c not in string . whitespace ) <EOL> class ParseBaseException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , pstr , loc = <NUM_LIT:0> , msg = None , elem = None ) : <EOL> self . loc = loc <EOL> if msg is None : <EOL> self . msg = pstr <EOL> self . pstr = "<STR_LIT>" <EOL> else : <EOL> self . msg = msg <EOL> self . pstr = pstr <EOL> self . parserElement = elem <EOL> def __getattr__ ( self , aname ) : <EOL> """<STR_LIT>""" <EOL> if ( aname == "<STR_LIT>" ) : <EOL> return lineno ( self . loc , self . pstr ) <EOL> elif ( aname in ( "<STR_LIT>" , "<STR_LIT>" ) ) : <EOL> return col ( self . loc , self . pstr ) <EOL> elif ( aname == "<STR_LIT>" ) : <EOL> return line ( self . loc , self . pstr ) <EOL> else : <EOL> raise AttributeError ( aname ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . msg , self . loc , self . lineno , self . column ) <EOL> def __repr__ ( self ) : <EOL> return _ustr ( self ) <EOL> def markInputline ( self , markerString = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> line_str = self . line <EOL> line_column = self . column - <NUM_LIT:1> <EOL> if markerString : <EOL> line_str = "<STR_LIT>" . join ( ( line_str [ : line_column ] , <EOL> markerString , line_str [ line_column : ] ) ) <EOL> return line_str . strip ( ) <EOL> def __dir__ ( self ) : <EOL> return "<STR_LIT>" "<STR_LIT>" . split ( ) <EOL> class ParseException ( ParseBaseException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ParseFatalException ( ParseBaseException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class ParseSyntaxException ( ParseFatalException ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , pe ) : <EOL> super ( ParseSyntaxException , self ) . __init__ ( <EOL> pe . pstr , pe . loc , pe . msg , pe . parserElement ) <EOL> class RecursiveGrammarException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parseElementList ) : <EOL> self . parseElementTrace = parseElementList <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % self . parseElementTrace <EOL> class _ParseResultsWithOffset ( object ) : <EOL> def __init__ ( self , p1 , p2 ) : <EOL> self . tup = ( p1 , p2 ) <EOL> def __getitem__ ( self , i ) : <EOL> return self . tup [ i ] <EOL> def __repr__ ( self ) : <EOL> return repr ( self . tup ) <EOL> def setOffset ( self , i ) : <EOL> self . tup = ( self . tup [ <NUM_LIT:0> ] , i ) <EOL> class ParseResults ( object ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , toklist , name = None , asList = True , modal = True ) : <EOL> if isinstance ( toklist , cls ) : <EOL> return toklist <EOL> retobj = object . __new__ ( cls ) <EOL> retobj . __doinit = True <EOL> return retobj <EOL> def __init__ ( self , toklist , name = None , asList = True , modal = True , isinstance = isinstance ) : <EOL> if self . __doinit : <EOL> self . __doinit = False <EOL> self . __name = None <EOL> self . __parent = None <EOL> self . __accumNames = { } <EOL> if isinstance ( toklist , list ) : <EOL> self . __toklist = toklist [ : ] <EOL> elif isinstance ( toklist , _generatorType ) : <EOL> self . __toklist = list ( toklist ) <EOL> else : <EOL> self . __toklist = [ toklist ] <EOL> self . __tokdict = dict ( ) <EOL> if name is not None and name : <EOL> if not modal : <EOL> self . __accumNames [ name ] = <NUM_LIT:0> <EOL> if isinstance ( name , int ) : <EOL> name = _ustr ( name ) <EOL> self . __name = name <EOL> if not ( isinstance ( toklist , ( type ( None ) , basestring , list ) ) and toklist in ( None , '<STR_LIT>' , [ ] ) ) : <EOL> if isinstance ( toklist , basestring ) : <EOL> toklist = [ toklist ] <EOL> if asList : <EOL> if isinstance ( toklist , ParseResults ) : <EOL> self [ name ] = _ParseResultsWithOffset ( toklist . copy ( ) , <NUM_LIT:0> ) <EOL> else : <EOL> self [ name ] = _ParseResultsWithOffset ( ParseResults ( toklist [ <NUM_LIT:0> ] ) , <NUM_LIT:0> ) <EOL> self [ name ] . __name = name <EOL> else : <EOL> try : <EOL> self [ name ] = toklist [ <NUM_LIT:0> ] <EOL> except ( KeyError , TypeError , IndexError ) : <EOL> self [ name ] = toklist <EOL> def __getitem__ ( self , i ) : <EOL> if isinstance ( i , ( int , slice ) ) : <EOL> return self . __toklist [ i ] <EOL> else : <EOL> if i not in self . __accumNames : <EOL> return self . __tokdict [ i ] [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> else : <EOL> return ParseResults ( [ v [ <NUM_LIT:0> ] for v in self . __tokdict [ i ] ] ) <EOL> def __setitem__ ( self , k , v , isinstance = isinstance ) : <EOL> if isinstance ( v , _ParseResultsWithOffset ) : <EOL> self . __tokdict [ k ] = self . __tokdict . get ( k , list ( ) ) + [ v ] <EOL> sub = v [ <NUM_LIT:0> ] <EOL> elif isinstance ( k , int ) : <EOL> self . __toklist [ k ] = v <EOL> sub = v <EOL> else : <EOL> self . __tokdict [ k ] = self . __tokdict . get ( k , list ( ) ) + [ _ParseResultsWithOffset ( v , <NUM_LIT:0> ) ] <EOL> sub = v <EOL> if isinstance ( sub , ParseResults ) : <EOL> sub . __parent = wkref ( self ) <EOL> def __delitem__ ( self , i ) : <EOL> if isinstance ( i , ( int , slice ) ) : <EOL> mylen = len ( self . __toklist ) <EOL> del self . __toklist [ i ] <EOL> if isinstance ( i , int ) : <EOL> if i < <NUM_LIT:0> : <EOL> i += mylen <EOL> i = slice ( i , i + <NUM_LIT:1> ) <EOL> removed = list ( range ( * i . indices ( mylen ) ) ) <EOL> removed . reverse ( ) <EOL> for name in self . __tokdict : <EOL> occurrences = self . __tokdict [ name ] <EOL> for j in removed : <EOL> for k , ( value , position ) in enumerate ( occurrences ) : <EOL> occurrences [ k ] = _ParseResultsWithOffset ( value , position - ( position > j ) ) <EOL> else : <EOL> del self . __tokdict [ i ] <EOL> def __contains__ ( self , k ) : <EOL> return k in self . __tokdict <EOL> def __len__ ( self ) : return len ( self . __toklist ) <EOL> def __bool__ ( self ) : return len ( self . __toklist ) > <NUM_LIT:0> <EOL> __nonzero__ = __bool__ <EOL> def __iter__ ( self ) : return iter ( self . __toklist ) <EOL> def __reversed__ ( self ) : return iter ( self . __toklist [ : : - <NUM_LIT:1> ] ) <EOL> def iterkeys ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self . __tokdict , "<STR_LIT>" ) : <EOL> return self . __tokdict . iterkeys ( ) <EOL> else : <EOL> return iter ( self . __tokdict ) <EOL> def itervalues ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( self [ k ] for k in self . iterkeys ( ) ) <EOL> def iteritems ( self ) : <EOL> return ( ( k , self [ k ] ) for k in self . iterkeys ( ) ) <EOL> if PY_3 : <EOL> keys = iterkeys <EOL> values = itervalues <EOL> items = iteritems <EOL> else : <EOL> def keys ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . iterkeys ( ) ) <EOL> def values ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . itervalues ( ) ) <EOL> def items ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . iteritems ( ) ) <EOL> def haskeys ( self ) : <EOL> """<STR_LIT>""" <EOL> return bool ( self . __tokdict ) <EOL> def pop ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not args : <EOL> args = [ - <NUM_LIT:1> ] <EOL> for k , v in kwargs . items ( ) : <EOL> if k == '<STR_LIT:default>' : <EOL> args = ( args [ <NUM_LIT:0> ] , v ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" % k ) <EOL> if ( isinstance ( args [ <NUM_LIT:0> ] , int ) or <EOL> len ( args ) == <NUM_LIT:1> or <EOL> args [ <NUM_LIT:0> ] in self ) : <EOL> index = args [ <NUM_LIT:0> ] <EOL> ret = self [ index ] <EOL> del self [ index ] <EOL> return ret <EOL> else : <EOL> defaultvalue = args [ <NUM_LIT:1> ] <EOL> return defaultvalue <EOL> def get ( self , key , defaultValue = None ) : <EOL> """<STR_LIT>""" <EOL> if key in self : <EOL> return self [ key ] <EOL> else : <EOL> return defaultValue <EOL> def insert ( self , index , insStr ) : <EOL> """<STR_LIT>""" <EOL> self . __toklist . insert ( index , insStr ) <EOL> for name in self . __tokdict : <EOL> occurrences = self . __tokdict [ name ] <EOL> for k , ( value , position ) in enumerate ( occurrences ) : <EOL> occurrences [ k ] = _ParseResultsWithOffset ( value , position + ( position > index ) ) <EOL> def append ( self , item ) : <EOL> """<STR_LIT>""" <EOL> self . __toklist . append ( item ) <EOL> def extend ( self , itemseq ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( itemseq , ParseResults ) : <EOL> self += itemseq <EOL> else : <EOL> self . __toklist . extend ( itemseq ) <EOL> def clear ( self ) : <EOL> """<STR_LIT>""" <EOL> del self . __toklist [ : ] <EOL> self . __tokdict . clear ( ) <EOL> def __getattr__ ( self , name ) : <EOL> try : <EOL> return self [ name ] <EOL> except KeyError : <EOL> return "<STR_LIT>" <EOL> if name in self . __tokdict : <EOL> if name not in self . __accumNames : <EOL> return self . __tokdict [ name ] [ - <NUM_LIT:1> ] [ <NUM_LIT:0> ] <EOL> else : <EOL> return ParseResults ( [ v [ <NUM_LIT:0> ] for v in self . __tokdict [ name ] ] ) <EOL> else : <EOL> return "<STR_LIT>" <EOL> def __add__ ( self , other ) : <EOL> ret = self . copy ( ) <EOL> ret += other <EOL> return ret <EOL> def __iadd__ ( self , other ) : <EOL> if other . __tokdict : <EOL> offset = len ( self . __toklist ) <EOL> addoffset = ( lambda a : ( a < <NUM_LIT:0> and offset ) or ( a + offset ) ) <EOL> otheritems = other . __tokdict . items ( ) <EOL> otherdictitems = [ ( k , _ParseResultsWithOffset ( v [ <NUM_LIT:0> ] , addoffset ( v [ <NUM_LIT:1> ] ) ) ) <EOL> for ( k , vlist ) in otheritems for v in vlist ] <EOL> for k , v in otherdictitems : <EOL> self [ k ] = v <EOL> if isinstance ( v [ <NUM_LIT:0> ] , ParseResults ) : <EOL> v [ <NUM_LIT:0> ] . __parent = wkref ( self ) <EOL> self . __toklist += other . __toklist <EOL> self . __accumNames . update ( other . __accumNames ) <EOL> return self <EOL> def __radd__ ( self , other ) : <EOL> if isinstance ( other , int ) and other == <NUM_LIT:0> : <EOL> return self . copy ( ) <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( repr ( self . __toklist ) , repr ( self . __tokdict ) ) <EOL> def __str__ ( self ) : <EOL> out = [ ] <EOL> for i in self . __toklist : <EOL> if isinstance ( i , ParseResults ) : <EOL> out . append ( _ustr ( i ) ) <EOL> else : <EOL> out . append ( repr ( i ) ) <EOL> return '<STR_LIT:[>' + '<STR_LIT:U+002CU+0020>' . join ( out ) + '<STR_LIT:]>' <EOL> def _asStringList ( self , sep = '<STR_LIT>' ) : <EOL> out = [ ] <EOL> for item in self . __toklist : <EOL> if out and sep : <EOL> out . append ( sep ) <EOL> if isinstance ( item , ParseResults ) : <EOL> out += item . _asStringList ( ) <EOL> else : <EOL> out . append ( _ustr ( item ) ) <EOL> return out <EOL> def asList ( self ) : <EOL> """<STR_LIT>""" <EOL> out = [ ] <EOL> for res in self . __toklist : <EOL> if isinstance ( res , ParseResults ) : <EOL> out . append ( res . asList ( ) ) <EOL> else : <EOL> out . append ( res ) <EOL> return out <EOL> def asDict ( self ) : <EOL> """<STR_LIT>""" <EOL> if PY_3 : <EOL> return dict ( self . items ( ) ) <EOL> else : <EOL> return dict ( self . iteritems ( ) ) <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> ret = ParseResults ( self . __toklist ) <EOL> ret . __tokdict = self . __tokdict . copy ( ) <EOL> ret . __parent = self . __parent <EOL> ret . __accumNames . update ( self . __accumNames ) <EOL> ret . __name = self . __name <EOL> return ret <EOL> def asXML ( self , doctag = None , namedItemsOnly = False , indent = "<STR_LIT>" , formatted = True ) : <EOL> """<STR_LIT>""" <EOL> nl = "<STR_LIT:\n>" <EOL> out = [ ] <EOL> namedItems = dict ( ( v [ <NUM_LIT:1> ] , k ) for ( k , vlist ) in self . __tokdict . items ( ) <EOL> for v in vlist ) <EOL> nextLevelIndent = indent + "<STR_LIT:U+0020>" <EOL> if not formatted : <EOL> indent = "<STR_LIT>" <EOL> nextLevelIndent = "<STR_LIT>" <EOL> nl = "<STR_LIT>" <EOL> selfTag = None <EOL> if doctag is not None : <EOL> selfTag = doctag <EOL> else : <EOL> if self . __name : <EOL> selfTag = self . __name <EOL> if not selfTag : <EOL> if namedItemsOnly : <EOL> return "<STR_LIT>" <EOL> else : <EOL> selfTag = "<STR_LIT>" <EOL> out += [ nl , indent , "<STR_LIT:<>" , selfTag , "<STR_LIT:>>" ] <EOL> worklist = self . __toklist <EOL> for i , res in enumerate ( worklist ) : <EOL> if isinstance ( res , ParseResults ) : <EOL> if i in namedItems : <EOL> out += [ res . asXML ( namedItems [ i ] , <EOL> namedItemsOnly and doctag is None , <EOL> nextLevelIndent , <EOL> formatted ) ] <EOL> else : <EOL> out += [ res . asXML ( None , <EOL> namedItemsOnly and doctag is None , <EOL> nextLevelIndent , <EOL> formatted ) ] <EOL> else : <EOL> resTag = None <EOL> if i in namedItems : <EOL> resTag = namedItems [ i ] <EOL> if not resTag : <EOL> if namedItemsOnly : <EOL> continue <EOL> else : <EOL> resTag = "<STR_LIT>" <EOL> xmlBodyText = _xml_escape ( _ustr ( res ) ) <EOL> out += [ nl , nextLevelIndent , "<STR_LIT:<>" , resTag , "<STR_LIT:>>" , <EOL> xmlBodyText , <EOL> "<STR_LIT>" , resTag , "<STR_LIT:>>" ] <EOL> out += [ nl , indent , "<STR_LIT>" , selfTag , "<STR_LIT:>>" ] <EOL> return "<STR_LIT>" . join ( out ) <EOL> def __lookup ( self , sub ) : <EOL> for k , vlist in self . __tokdict . items ( ) : <EOL> for v , loc in vlist : <EOL> if sub is v : <EOL> return k <EOL> return None <EOL> def getName ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . __name : <EOL> return self . __name <EOL> elif self . __parent : <EOL> par = self . __parent ( ) <EOL> if par : <EOL> return par . __lookup ( self ) <EOL> else : <EOL> return None <EOL> elif ( len ( self ) == <NUM_LIT:1> and <EOL> len ( self . __tokdict ) == <NUM_LIT:1> and <EOL> self . __tokdict . values ( ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] in ( <NUM_LIT:0> , - <NUM_LIT:1> ) ) : <EOL> return self . __tokdict . keys ( ) [ <NUM_LIT:0> ] <EOL> else : <EOL> return None <EOL> def dump ( self , indent = '<STR_LIT>' , depth = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> out = [ ] <EOL> NL = '<STR_LIT:\n>' <EOL> out . append ( indent + _ustr ( self . asList ( ) ) ) <EOL> items = sorted ( self . items ( ) ) <EOL> for k , v in items : <EOL> if out : <EOL> out . append ( NL ) <EOL> out . append ( "<STR_LIT>" % ( indent , ( '<STR_LIT:U+0020>' * depth ) , k ) ) <EOL> if isinstance ( v , ParseResults ) : <EOL> if v : <EOL> if v . haskeys ( ) : <EOL> out . append ( v . dump ( indent , depth + <NUM_LIT:1> ) ) <EOL> elif any ( isinstance ( vv , ParseResults ) for vv in v ) : <EOL> for i , vv in enumerate ( v ) : <EOL> if isinstance ( vv , ParseResults ) : <EOL> out . append ( "<STR_LIT>" % ( indent , ( '<STR_LIT:U+0020>' * ( depth + <NUM_LIT:1> ) ) , i , indent , ( '<STR_LIT:U+0020>' * ( depth + <NUM_LIT:2> ) ) , vv . dump ( indent , depth + <NUM_LIT:2> ) ) ) <EOL> else : <EOL> out . append ( "<STR_LIT>" % ( indent , ( '<STR_LIT:U+0020>' * ( depth + <NUM_LIT:1> ) ) , i , indent , ( '<STR_LIT:U+0020>' * ( depth + <NUM_LIT:2> ) ) , _ustr ( vv ) ) ) <EOL> else : <EOL> out . append ( _ustr ( v ) ) <EOL> else : <EOL> out . append ( _ustr ( v ) ) <EOL> else : <EOL> out . append ( _ustr ( v ) ) <EOL> return "<STR_LIT>" . join ( out ) <EOL> def pprint ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> pprint . pprint ( self . asList ( ) , * args , ** kwargs ) <EOL> def __getstate__ ( self ) : <EOL> return ( self . __toklist , <EOL> ( self . __tokdict . copy ( ) , <EOL> self . __parent is not None and self . __parent ( ) or None , <EOL> self . __accumNames , <EOL> self . __name ) ) <EOL> def __setstate__ ( self , state ) : <EOL> self . __toklist = state [ <NUM_LIT:0> ] <EOL> ( self . __tokdict , <EOL> par , <EOL> inAccumNames , <EOL> self . __name ) = state [ <NUM_LIT:1> ] <EOL> self . __accumNames = { } <EOL> self . __accumNames . update ( inAccumNames ) <EOL> if par is not None : <EOL> self . __parent = wkref ( par ) <EOL> else : <EOL> self . __parent = None <EOL> def __dir__ ( self ) : <EOL> return dir ( super ( ParseResults , self ) ) + list ( self . keys ( ) ) <EOL> collections . MutableMapping . register ( ParseResults ) <EOL> def col ( loc , strg ) : <EOL> """<STR_LIT>""" <EOL> return ( loc < len ( strg ) and strg [ loc ] == '<STR_LIT:\n>' ) and <NUM_LIT:1> or loc - strg . rfind ( "<STR_LIT:\n>" , <NUM_LIT:0> , loc ) <EOL> def lineno ( loc , strg ) : <EOL> """<STR_LIT>""" <EOL> return strg . count ( "<STR_LIT:\n>" , <NUM_LIT:0> , loc ) + <NUM_LIT:1> <EOL> def line ( loc , strg ) : <EOL> """<STR_LIT>""" <EOL> lastCR = strg . rfind ( "<STR_LIT:\n>" , <NUM_LIT:0> , loc ) <EOL> nextCR = strg . find ( "<STR_LIT:\n>" , loc ) <EOL> if nextCR >= <NUM_LIT:0> : <EOL> return strg [ lastCR + <NUM_LIT:1> : nextCR ] <EOL> else : <EOL> return strg [ lastCR + <NUM_LIT:1> : ] <EOL> def _defaultStartDebugAction ( instring , loc , expr ) : <EOL> print ( ( "<STR_LIT>" + _ustr ( expr ) + "<STR_LIT>" + _ustr ( loc ) + "<STR_LIT>" % ( lineno ( loc , instring ) , col ( loc , instring ) ) ) ) <EOL> def _defaultSuccessDebugAction ( instring , startloc , endloc , expr , toks ) : <EOL> print ( "<STR_LIT>" + _ustr ( expr ) + "<STR_LIT>" + str ( toks . asList ( ) ) ) <EOL> def _defaultExceptionDebugAction ( instring , loc , expr , exc ) : <EOL> print ( "<STR_LIT>" + _ustr ( exc ) ) <EOL> def nullDebugAction ( * args ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> '<STR_LIT>' <EOL> def _trim_arity ( func , maxargs = <NUM_LIT:2> ) : <EOL> if func in singleArgBuiltins : <EOL> return lambda s , l , t : func ( t ) <EOL> limit = [ <NUM_LIT:0> ] <EOL> foundArity = [ False ] <EOL> def wrapper ( * args ) : <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> ret = func ( * args [ limit [ <NUM_LIT:0> ] : ] ) <EOL> foundArity [ <NUM_LIT:0> ] = True <EOL> return ret <EOL> except TypeError : <EOL> if limit [ <NUM_LIT:0> ] <= maxargs and not foundArity [ <NUM_LIT:0> ] : <EOL> limit [ <NUM_LIT:0> ] += <NUM_LIT:1> <EOL> continue <EOL> raise <EOL> return wrapper <EOL> class ParserElement ( object ) : <EOL> """<STR_LIT>""" <EOL> DEFAULT_WHITE_CHARS = "<STR_LIT>" <EOL> verbose_stacktrace = False <EOL> def setDefaultWhitespaceChars ( chars ) : <EOL> """<STR_LIT>""" <EOL> ParserElement . DEFAULT_WHITE_CHARS = chars <EOL> setDefaultWhitespaceChars = staticmethod ( setDefaultWhitespaceChars ) <EOL> def inlineLiteralsUsing ( cls ) : <EOL> """<STR_LIT>""" <EOL> ParserElement . literalStringClass = cls <EOL> inlineLiteralsUsing = staticmethod ( inlineLiteralsUsing ) <EOL> def __init__ ( self , savelist = False ) : <EOL> self . parseAction = list ( ) <EOL> self . failAction = None <EOL> self . strRepr = None <EOL> self . resultsName = None <EOL> self . saveAsList = savelist <EOL> self . skipWhitespace = True <EOL> self . whiteChars = ParserElement . DEFAULT_WHITE_CHARS <EOL> self . copyDefaultWhiteChars = True <EOL> self . mayReturnEmpty = False <EOL> self . keepTabs = False <EOL> self . ignoreExprs = list ( ) <EOL> self . debug = False <EOL> self . streamlined = False <EOL> self . mayIndexError = True <EOL> self . errmsg = "<STR_LIT>" <EOL> self . modalResults = True <EOL> self . debugActions = ( None , None , None ) <EOL> self . re = None <EOL> self . callPreparse = True <EOL> self . callDuringTry = False <EOL> def copy ( self ) : <EOL> """<STR_LIT>""" <EOL> cpy = copy . copy ( self ) <EOL> cpy . parseAction = self . parseAction [ : ] <EOL> cpy . ignoreExprs = self . ignoreExprs [ : ] <EOL> if self . copyDefaultWhiteChars : <EOL> cpy . whiteChars = ParserElement . DEFAULT_WHITE_CHARS <EOL> return cpy <EOL> def setName ( self , name ) : <EOL> """<STR_LIT>""" <EOL> self . name = name <EOL> self . errmsg = "<STR_LIT>" + self . name <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> self . exception . msg = self . errmsg <EOL> return self <EOL> def setResultsName ( self , name , listAllMatches = False ) : <EOL> """<STR_LIT>""" <EOL> newself = self . copy ( ) <EOL> if name . endswith ( "<STR_LIT:*>" ) : <EOL> name = name [ : - <NUM_LIT:1> ] <EOL> listAllMatches = True <EOL> newself . resultsName = name <EOL> newself . modalResults = not listAllMatches <EOL> return newself <EOL> def setBreak ( self , breakFlag = True ) : <EOL> """<STR_LIT>""" <EOL> if breakFlag : <EOL> _parseMethod = self . _parse <EOL> def breaker ( instring , loc , doActions = True , callPreParse = True ) : <EOL> import pdb <EOL> pdb . set_trace ( ) <EOL> return _parseMethod ( instring , loc , doActions , callPreParse ) <EOL> breaker . _originalParseMethod = _parseMethod <EOL> self . _parse = breaker <EOL> else : <EOL> if hasattr ( self . _parse , "<STR_LIT>" ) : <EOL> self . _parse = self . _parse . _originalParseMethod <EOL> return self <EOL> def setParseAction ( self , * fns , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . parseAction = list ( map ( _trim_arity , list ( fns ) ) ) <EOL> self . callDuringTry = ( "<STR_LIT>" in kwargs and kwargs [ "<STR_LIT>" ] ) <EOL> return self <EOL> def addParseAction ( self , * fns , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . parseAction += list ( map ( _trim_arity , list ( fns ) ) ) <EOL> self . callDuringTry = self . callDuringTry or ( "<STR_LIT>" in kwargs and kwargs [ "<STR_LIT>" ] ) <EOL> return self <EOL> def setFailAction ( self , fn ) : <EOL> """<STR_LIT>""" <EOL> self . failAction = fn <EOL> return self <EOL> def _skipIgnorables ( self , instring , loc ) : <EOL> exprsFound = True <EOL> while exprsFound : <EOL> exprsFound = False <EOL> for e in self . ignoreExprs : <EOL> try : <EOL> while <NUM_LIT:1> : <EOL> loc , dummy = e . _parse ( instring , loc ) <EOL> exprsFound = True <EOL> except ParseException : <EOL> pass <EOL> return loc <EOL> def preParse ( self , instring , loc ) : <EOL> if self . ignoreExprs : <EOL> loc = self . _skipIgnorables ( instring , loc ) <EOL> if self . skipWhitespace : <EOL> wt = self . whiteChars <EOL> instrlen = len ( instring ) <EOL> while loc < instrlen and instring [ loc ] in wt : <EOL> loc += <NUM_LIT:1> <EOL> return loc <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> return loc , [ ] <EOL> def postParse ( self , instring , loc , tokenlist ) : <EOL> return tokenlist <EOL> def _parseNoCache ( self , instring , loc , doActions = True , callPreParse = True ) : <EOL> debugging = ( self . debug ) <EOL> if debugging or self . failAction : <EOL> if ( self . debugActions [ <NUM_LIT:0> ] ) : <EOL> self . debugActions [ <NUM_LIT:0> ] ( instring , loc , self ) <EOL> if callPreParse and self . callPreparse : <EOL> preloc = self . preParse ( instring , loc ) <EOL> else : <EOL> preloc = loc <EOL> tokensStart = preloc <EOL> try : <EOL> try : <EOL> loc , tokens = self . parseImpl ( instring , preloc , doActions ) <EOL> except IndexError : <EOL> raise ParseException ( instring , len ( instring ) , self . errmsg , self ) <EOL> except ParseBaseException as err : <EOL> if self . debugActions [ <NUM_LIT:2> ] : <EOL> self . debugActions [ <NUM_LIT:2> ] ( instring , tokensStart , self , err ) <EOL> if self . failAction : <EOL> self . failAction ( instring , tokensStart , self , err ) <EOL> raise <EOL> else : <EOL> if callPreParse and self . callPreparse : <EOL> preloc = self . preParse ( instring , loc ) <EOL> else : <EOL> preloc = loc <EOL> tokensStart = preloc <EOL> if self . mayIndexError or loc >= len ( instring ) : <EOL> try : <EOL> loc , tokens = self . parseImpl ( instring , preloc , doActions ) <EOL> except IndexError : <EOL> raise ParseException ( instring , len ( instring ) , self . errmsg , self ) <EOL> else : <EOL> loc , tokens = self . parseImpl ( instring , preloc , doActions ) <EOL> tokens = self . postParse ( instring , loc , tokens ) <EOL> retTokens = ParseResults ( tokens , self . resultsName , asList = self . saveAsList , modal = self . modalResults ) <EOL> if self . parseAction and ( doActions or self . callDuringTry ) : <EOL> if debugging : <EOL> try : <EOL> for fn in self . parseAction : <EOL> tokens = fn ( instring , tokensStart , retTokens ) <EOL> if tokens is not None : <EOL> retTokens = ParseResults ( tokens , <EOL> self . resultsName , <EOL> asList = self . saveAsList and isinstance ( tokens , ( ParseResults , list ) ) , <EOL> modal = self . modalResults ) <EOL> except ParseBaseException as err : <EOL> if ( self . debugActions [ <NUM_LIT:2> ] ) : <EOL> self . debugActions [ <NUM_LIT:2> ] ( instring , tokensStart , self , err ) <EOL> raise <EOL> else : <EOL> for fn in self . parseAction : <EOL> tokens = fn ( instring , tokensStart , retTokens ) <EOL> if tokens is not None : <EOL> retTokens = ParseResults ( tokens , <EOL> self . resultsName , <EOL> asList = self . saveAsList and isinstance ( tokens , ( ParseResults , list ) ) , <EOL> modal = self . modalResults ) <EOL> if debugging : <EOL> if ( self . debugActions [ <NUM_LIT:1> ] ) : <EOL> self . debugActions [ <NUM_LIT:1> ] ( instring , tokensStart , loc , self , retTokens ) <EOL> return loc , retTokens <EOL> def tryParse ( self , instring , loc ) : <EOL> try : <EOL> return self . _parse ( instring , loc , doActions = False ) [ <NUM_LIT:0> ] <EOL> except ParseFatalException : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> def _parseCache ( self , instring , loc , doActions = True , callPreParse = True ) : <EOL> lookup = ( self , instring , loc , callPreParse , doActions ) <EOL> if lookup in ParserElement . _exprArgCache : <EOL> value = ParserElement . _exprArgCache [ lookup ] <EOL> if isinstance ( value , Exception ) : <EOL> raise value <EOL> return ( value [ <NUM_LIT:0> ] , value [ <NUM_LIT:1> ] . copy ( ) ) <EOL> else : <EOL> try : <EOL> value = self . _parseNoCache ( instring , loc , doActions , callPreParse ) <EOL> ParserElement . _exprArgCache [ lookup ] = ( value [ <NUM_LIT:0> ] , value [ <NUM_LIT:1> ] . copy ( ) ) <EOL> return value <EOL> except ParseBaseException as pe : <EOL> pe . __traceback__ = None <EOL> ParserElement . _exprArgCache [ lookup ] = pe <EOL> raise <EOL> _parse = _parseNoCache <EOL> _exprArgCache = { } <EOL> def resetCache ( ) : <EOL> ParserElement . _exprArgCache . clear ( ) <EOL> resetCache = staticmethod ( resetCache ) <EOL> _packratEnabled = False <EOL> def enablePackrat ( ) : <EOL> """<STR_LIT>""" <EOL> if not ParserElement . _packratEnabled : <EOL> ParserElement . _packratEnabled = True <EOL> ParserElement . _parse = ParserElement . _parseCache <EOL> enablePackrat = staticmethod ( enablePackrat ) <EOL> def parseString ( self , instring , parseAll = False ) : <EOL> """<STR_LIT>""" <EOL> ParserElement . resetCache ( ) <EOL> if not self . streamlined : <EOL> self . streamline ( ) <EOL> for e in self . ignoreExprs : <EOL> e . streamline ( ) <EOL> if not self . keepTabs : <EOL> instring = instring . expandtabs ( ) <EOL> try : <EOL> loc , tokens = self . _parse ( instring , <NUM_LIT:0> ) <EOL> if parseAll : <EOL> loc = self . preParse ( instring , loc ) <EOL> se = Empty ( ) + StringEnd ( ) <EOL> se . _parse ( instring , loc ) <EOL> except ParseBaseException as exc : <EOL> if ParserElement . verbose_stacktrace : <EOL> raise <EOL> else : <EOL> raise exc <EOL> else : <EOL> return tokens <EOL> def scanString ( self , instring , maxMatches = _MAX_INT , overlap = False ) : <EOL> """<STR_LIT>""" <EOL> if not self . streamlined : <EOL> self . streamline ( ) <EOL> for e in self . ignoreExprs : <EOL> e . streamline ( ) <EOL> if not self . keepTabs : <EOL> instring = _ustr ( instring ) . expandtabs ( ) <EOL> instrlen = len ( instring ) <EOL> loc = <NUM_LIT:0> <EOL> preparseFn = self . preParse <EOL> parseFn = self . _parse <EOL> ParserElement . resetCache ( ) <EOL> matches = <NUM_LIT:0> <EOL> try : <EOL> while loc <= instrlen and matches < maxMatches : <EOL> try : <EOL> preloc = preparseFn ( instring , loc ) <EOL> nextLoc , tokens = parseFn ( instring , preloc , callPreParse = False ) <EOL> except ParseException : <EOL> loc = preloc + <NUM_LIT:1> <EOL> else : <EOL> if nextLoc > loc : <EOL> matches += <NUM_LIT:1> <EOL> yield tokens , preloc , nextLoc <EOL> if overlap : <EOL> nextloc = preparseFn ( instring , loc ) <EOL> if nextloc > loc : <EOL> loc = nextLoc <EOL> else : <EOL> loc += <NUM_LIT:1> <EOL> else : <EOL> loc = nextLoc <EOL> else : <EOL> loc = preloc + <NUM_LIT:1> <EOL> except ParseBaseException as exc : <EOL> if ParserElement . verbose_stacktrace : <EOL> raise <EOL> else : <EOL> raise exc <EOL> def transformString ( self , instring ) : <EOL> """<STR_LIT>""" <EOL> out = [ ] <EOL> lastE = <NUM_LIT:0> <EOL> self . keepTabs = True <EOL> try : <EOL> for t , s , e in self . scanString ( instring ) : <EOL> out . append ( instring [ lastE : s ] ) <EOL> if t : <EOL> if isinstance ( t , ParseResults ) : <EOL> out += t . asList ( ) <EOL> elif isinstance ( t , list ) : <EOL> out += t <EOL> else : <EOL> out . append ( t ) <EOL> lastE = e <EOL> out . append ( instring [ lastE : ] ) <EOL> out = [ o for o in out if o ] <EOL> return "<STR_LIT>" . join ( map ( _ustr , _flatten ( out ) ) ) <EOL> except ParseBaseException as exc : <EOL> if ParserElement . verbose_stacktrace : <EOL> raise <EOL> else : <EOL> raise exc <EOL> def searchString ( self , instring , maxMatches = _MAX_INT ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return ParseResults ( [ t for t , s , e in self . scanString ( instring , maxMatches ) ] ) <EOL> except ParseBaseException as exc : <EOL> if ParserElement . verbose_stacktrace : <EOL> raise <EOL> else : <EOL> raise exc <EOL> def __add__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> if not isinstance ( other , ParserElement ) : <EOL> warnings . warn ( "<STR_LIT>" % type ( other ) , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return None <EOL> return And ( [ self , other ] ) <EOL> def __radd__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> if not isinstance ( other , ParserElement ) : <EOL> warnings . warn ( "<STR_LIT>" % type ( other ) , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return None <EOL> return other + self <EOL> def __sub__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> if not isinstance ( other , ParserElement ) : <EOL> warnings . warn ( "<STR_LIT>" % type ( other ) , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return None <EOL> return And ( [ self , And . _ErrorStop ( ) , other ] ) <EOL> def __rsub__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> if not isinstance ( other , ParserElement ) : <EOL> warnings . warn ( "<STR_LIT>" % type ( other ) , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return None <EOL> return other - self <EOL> def __mul__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , int ) : <EOL> minElements , optElements = other , <NUM_LIT:0> <EOL> elif isinstance ( other , tuple ) : <EOL> other = ( other + ( None , None ) ) [ : <NUM_LIT:2> ] <EOL> if other [ <NUM_LIT:0> ] is None : <EOL> other = ( <NUM_LIT:0> , other [ <NUM_LIT:1> ] ) <EOL> if isinstance ( other [ <NUM_LIT:0> ] , int ) and other [ <NUM_LIT:1> ] is None : <EOL> if other [ <NUM_LIT:0> ] == <NUM_LIT:0> : <EOL> return ZeroOrMore ( self ) <EOL> if other [ <NUM_LIT:0> ] == <NUM_LIT:1> : <EOL> return OneOrMore ( self ) <EOL> else : <EOL> return self * other [ <NUM_LIT:0> ] + ZeroOrMore ( self ) <EOL> elif isinstance ( other [ <NUM_LIT:0> ] , int ) and isinstance ( other [ <NUM_LIT:1> ] , int ) : <EOL> minElements , optElements = other <EOL> optElements -= minElements <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" , type ( other [ <NUM_LIT:0> ] ) , type ( other [ <NUM_LIT:1> ] ) ) <EOL> else : <EOL> raise TypeError ( "<STR_LIT>" , type ( other ) ) <EOL> if minElements < <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if optElements < <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if minElements == optElements == <NUM_LIT:0> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if ( optElements ) : <EOL> def makeOptionalList ( n ) : <EOL> if n > <NUM_LIT:1> : <EOL> return Optional ( self + makeOptionalList ( n - <NUM_LIT:1> ) ) <EOL> else : <EOL> return Optional ( self ) <EOL> if minElements : <EOL> if minElements == <NUM_LIT:1> : <EOL> ret = self + makeOptionalList ( optElements ) <EOL> else : <EOL> ret = And ( [ self ] * minElements ) + makeOptionalList ( optElements ) <EOL> else : <EOL> ret = makeOptionalList ( optElements ) <EOL> else : <EOL> if minElements == <NUM_LIT:1> : <EOL> ret = self <EOL> else : <EOL> ret = And ( [ self ] * minElements ) <EOL> return ret <EOL> def __rmul__ ( self , other ) : <EOL> return self . __mul__ ( other ) <EOL> def __or__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> if not isinstance ( other , ParserElement ) : <EOL> warnings . warn ( "<STR_LIT>" % type ( other ) , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return None <EOL> return MatchFirst ( [ self , other ] ) <EOL> def __ror__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> if not isinstance ( other , ParserElement ) : <EOL> warnings . warn ( "<STR_LIT>" % type ( other ) , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return None <EOL> return other | self <EOL> def __xor__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> if not isinstance ( other , ParserElement ) : <EOL> warnings . warn ( "<STR_LIT>" % type ( other ) , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return None <EOL> return Or ( [ self , other ] ) <EOL> def __rxor__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> if not isinstance ( other , ParserElement ) : <EOL> warnings . warn ( "<STR_LIT>" % type ( other ) , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return None <EOL> return other ^ self <EOL> def __and__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> if not isinstance ( other , ParserElement ) : <EOL> warnings . warn ( "<STR_LIT>" % type ( other ) , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return None <EOL> return Each ( [ self , other ] ) <EOL> def __rand__ ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> if not isinstance ( other , ParserElement ) : <EOL> warnings . warn ( "<STR_LIT>" % type ( other ) , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return None <EOL> return other & self <EOL> def __invert__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return NotAny ( self ) <EOL> def __call__ ( self , name = None ) : <EOL> """<STR_LIT>""" <EOL> if name is not None : <EOL> return self . setResultsName ( name ) <EOL> else : <EOL> return self . copy ( ) <EOL> def suppress ( self ) : <EOL> """<STR_LIT>""" <EOL> return Suppress ( self ) <EOL> def leaveWhitespace ( self ) : <EOL> """<STR_LIT>""" <EOL> self . skipWhitespace = False <EOL> return self <EOL> def setWhitespaceChars ( self , chars ) : <EOL> """<STR_LIT>""" <EOL> self . skipWhitespace = True <EOL> self . whiteChars = chars <EOL> self . copyDefaultWhiteChars = False <EOL> return self <EOL> def parseWithTabs ( self ) : <EOL> """<STR_LIT>""" <EOL> self . keepTabs = True <EOL> return self <EOL> def ignore ( self , other ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( other , Suppress ) : <EOL> if other not in self . ignoreExprs : <EOL> self . ignoreExprs . append ( other . copy ( ) ) <EOL> else : <EOL> self . ignoreExprs . append ( Suppress ( other . copy ( ) ) ) <EOL> return self <EOL> def setDebugActions ( self , startAction , successAction , exceptionAction ) : <EOL> """<STR_LIT>""" <EOL> self . debugActions = ( startAction or _defaultStartDebugAction , <EOL> successAction or _defaultSuccessDebugAction , <EOL> exceptionAction or _defaultExceptionDebugAction ) <EOL> self . debug = True <EOL> return self <EOL> def setDebug ( self , flag = True ) : <EOL> """<STR_LIT>""" <EOL> if flag : <EOL> self . setDebugActions ( _defaultStartDebugAction , _defaultSuccessDebugAction , _defaultExceptionDebugAction ) <EOL> else : <EOL> self . debug = False <EOL> return self <EOL> def __str__ ( self ) : <EOL> return self . name <EOL> def __repr__ ( self ) : <EOL> return _ustr ( self ) <EOL> def streamline ( self ) : <EOL> self . streamlined = True <EOL> self . strRepr = None <EOL> return self <EOL> def checkRecursion ( self , parseElementList ) : <EOL> pass <EOL> def validate ( self , validateTrace = [ ] ) : <EOL> """<STR_LIT>""" <EOL> self . checkRecursion ( [ ] ) <EOL> def parseFile ( self , file_or_filename , parseAll = False ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> file_contents = file_or_filename . read ( ) <EOL> except AttributeError : <EOL> f = open ( file_or_filename , "<STR_LIT:r>" ) <EOL> file_contents = f . read ( ) <EOL> f . close ( ) <EOL> try : <EOL> return self . parseString ( file_contents , parseAll ) <EOL> except ParseBaseException as exc : <EOL> if ParserElement . verbose_stacktrace : <EOL> raise <EOL> else : <EOL> raise exc <EOL> def __eq__ ( self , other ) : <EOL> if isinstance ( other , ParserElement ) : <EOL> return self is other or self . __dict__ == other . __dict__ <EOL> elif isinstance ( other , basestring ) : <EOL> try : <EOL> self . parseString ( _ustr ( other ) , parseAll = True ) <EOL> return True <EOL> except ParseBaseException : <EOL> return False <EOL> else : <EOL> return super ( ParserElement , self ) == other <EOL> def __ne__ ( self , other ) : <EOL> return not ( self == other ) <EOL> def __hash__ ( self ) : <EOL> return hash ( id ( self ) ) <EOL> def __req__ ( self , other ) : <EOL> return self == other <EOL> def __rne__ ( self , other ) : <EOL> return not ( self == other ) <EOL> class Token ( ParserElement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( Token , self ) . __init__ ( savelist = False ) <EOL> def setName ( self , name ) : <EOL> s = super ( Token , self ) . setName ( name ) <EOL> self . errmsg = "<STR_LIT>" + self . name <EOL> return s <EOL> class Empty ( Token ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( Empty , self ) . __init__ ( ) <EOL> self . name = "<STR_LIT>" <EOL> self . mayReturnEmpty = True <EOL> self . mayIndexError = False <EOL> class NoMatch ( Token ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( NoMatch , self ) . __init__ ( ) <EOL> self . name = "<STR_LIT>" <EOL> self . mayReturnEmpty = True <EOL> self . mayIndexError = False <EOL> self . errmsg = "<STR_LIT>" <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> class Literal ( Token ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , matchString ) : <EOL> super ( Literal , self ) . __init__ ( ) <EOL> self . match = matchString <EOL> self . matchLen = len ( matchString ) <EOL> try : <EOL> self . firstMatchChar = matchString [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> warnings . warn ( "<STR_LIT>" , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> self . __class__ = Empty <EOL> self . name = '<STR_LIT>' % _ustr ( self . match ) <EOL> self . errmsg = "<STR_LIT>" + self . name <EOL> self . mayReturnEmpty = False <EOL> self . mayIndexError = False <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if ( instring [ loc ] == self . firstMatchChar and <EOL> ( self . matchLen == <NUM_LIT:1> or instring . startswith ( self . match , loc ) ) ) : <EOL> return loc + self . matchLen , self . match <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> _L = Literal <EOL> ParserElement . literalStringClass = Literal <EOL> class Keyword ( Token ) : <EOL> """<STR_LIT>""" <EOL> DEFAULT_KEYWORD_CHARS = alphanums + "<STR_LIT>" <EOL> def __init__ ( self , matchString , identChars = DEFAULT_KEYWORD_CHARS , caseless = False ) : <EOL> super ( Keyword , self ) . __init__ ( ) <EOL> self . match = matchString <EOL> self . matchLen = len ( matchString ) <EOL> try : <EOL> self . firstMatchChar = matchString [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> warnings . warn ( "<STR_LIT>" , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> self . name = '<STR_LIT>' % self . match <EOL> self . errmsg = "<STR_LIT>" + self . name <EOL> self . mayReturnEmpty = False <EOL> self . mayIndexError = False <EOL> self . caseless = caseless <EOL> if caseless : <EOL> self . caselessmatch = matchString . upper ( ) <EOL> identChars = identChars . upper ( ) <EOL> self . identChars = set ( identChars ) <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if self . caseless : <EOL> if ( ( instring [ loc : loc + self . matchLen ] . upper ( ) == self . caselessmatch ) and <EOL> ( loc >= len ( instring ) - self . matchLen or instring [ loc + self . matchLen ] . upper ( ) not in self . identChars ) and <EOL> ( loc == <NUM_LIT:0> or instring [ loc - <NUM_LIT:1> ] . upper ( ) not in self . identChars ) ) : <EOL> return loc + self . matchLen , self . match <EOL> else : <EOL> if ( instring [ loc ] == self . firstMatchChar and <EOL> ( self . matchLen == <NUM_LIT:1> or instring . startswith ( self . match , loc ) ) and <EOL> ( loc >= len ( instring ) - self . matchLen or instring [ loc + self . matchLen ] not in self . identChars ) and <EOL> ( loc == <NUM_LIT:0> or instring [ loc - <NUM_LIT:1> ] not in self . identChars ) ) : <EOL> return loc + self . matchLen , self . match <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> def copy ( self ) : <EOL> c = super ( Keyword , self ) . copy ( ) <EOL> c . identChars = Keyword . DEFAULT_KEYWORD_CHARS <EOL> return c <EOL> def setDefaultKeywordChars ( chars ) : <EOL> """<STR_LIT>""" <EOL> Keyword . DEFAULT_KEYWORD_CHARS = chars <EOL> setDefaultKeywordChars = staticmethod ( setDefaultKeywordChars ) <EOL> class CaselessLiteral ( Literal ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , matchString ) : <EOL> super ( CaselessLiteral , self ) . __init__ ( matchString . upper ( ) ) <EOL> self . returnString = matchString <EOL> self . name = "<STR_LIT>" % self . returnString <EOL> self . errmsg = "<STR_LIT>" + self . name <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if instring [ loc : loc + self . matchLen ] . upper ( ) == self . match : <EOL> return loc + self . matchLen , self . returnString <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> class CaselessKeyword ( Keyword ) : <EOL> def __init__ ( self , matchString , identChars = Keyword . DEFAULT_KEYWORD_CHARS ) : <EOL> super ( CaselessKeyword , self ) . __init__ ( matchString , identChars , caseless = True ) <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if ( ( instring [ loc : loc + self . matchLen ] . upper ( ) == self . caselessmatch ) and <EOL> ( loc >= len ( instring ) - self . matchLen or instring [ loc + self . matchLen ] . upper ( ) not in self . identChars ) ) : <EOL> return loc + self . matchLen , self . match <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> class Word ( Token ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , initChars , bodyChars = None , min = <NUM_LIT:1> , max = <NUM_LIT:0> , exact = <NUM_LIT:0> , asKeyword = False , excludeChars = None ) : <EOL> super ( Word , self ) . __init__ ( ) <EOL> if excludeChars : <EOL> initChars = '<STR_LIT>' . join ( c for c in initChars if c not in excludeChars ) <EOL> if bodyChars : <EOL> bodyChars = '<STR_LIT>' . join ( c for c in bodyChars if c not in excludeChars ) <EOL> self . initCharsOrig = initChars <EOL> self . initChars = set ( initChars ) <EOL> if bodyChars : <EOL> self . bodyCharsOrig = bodyChars <EOL> self . bodyChars = set ( bodyChars ) <EOL> else : <EOL> self . bodyCharsOrig = initChars <EOL> self . bodyChars = set ( initChars ) <EOL> self . maxSpecified = max > <NUM_LIT:0> <EOL> if min < <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . minLen = min <EOL> if max > <NUM_LIT:0> : <EOL> self . maxLen = max <EOL> else : <EOL> self . maxLen = _MAX_INT <EOL> if exact > <NUM_LIT:0> : <EOL> self . maxLen = exact <EOL> self . minLen = exact <EOL> self . name = _ustr ( self ) <EOL> self . errmsg = "<STR_LIT>" + self . name <EOL> self . mayIndexError = False <EOL> self . asKeyword = asKeyword <EOL> if '<STR_LIT:U+0020>' not in self . initCharsOrig + self . bodyCharsOrig and ( min == <NUM_LIT:1> and max == <NUM_LIT:0> and exact == <NUM_LIT:0> ) : <EOL> if self . bodyCharsOrig == self . initCharsOrig : <EOL> self . reString = "<STR_LIT>" % _escapeRegexRangeChars ( self . initCharsOrig ) <EOL> elif len ( self . bodyCharsOrig ) == <NUM_LIT:1> : <EOL> self . reString = "<STR_LIT>" % ( re . escape ( self . initCharsOrig ) , <EOL> _escapeRegexRangeChars ( self . bodyCharsOrig ) , ) <EOL> else : <EOL> self . reString = "<STR_LIT>" % ( _escapeRegexRangeChars ( self . initCharsOrig ) , <EOL> _escapeRegexRangeChars ( self . bodyCharsOrig ) , ) <EOL> if self . asKeyword : <EOL> self . reString = r"<STR_LIT>" + self . reString + r"<STR_LIT>" <EOL> try : <EOL> self . re = re . compile ( self . reString ) <EOL> except : <EOL> self . re = None <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if self . re : <EOL> result = self . re . match ( instring , loc ) <EOL> if not result : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> loc = result . end ( ) <EOL> return loc , result . group ( ) <EOL> if not ( instring [ loc ] in self . initChars ) : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> start = loc <EOL> loc += <NUM_LIT:1> <EOL> instrlen = len ( instring ) <EOL> bodychars = self . bodyChars <EOL> maxloc = start + self . maxLen <EOL> maxloc = min ( maxloc , instrlen ) <EOL> while loc < maxloc and instring [ loc ] in bodychars : <EOL> loc += <NUM_LIT:1> <EOL> throwException = False <EOL> if loc - start < self . minLen : <EOL> throwException = True <EOL> if self . maxSpecified and loc < instrlen and instring [ loc ] in bodychars : <EOL> throwException = True <EOL> if self . asKeyword : <EOL> if ( start > <NUM_LIT:0> and instring [ start - <NUM_LIT:1> ] in bodychars ) or ( loc < instrlen and instring [ loc ] in bodychars ) : <EOL> throwException = True <EOL> if throwException : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> return loc , instring [ start : loc ] <EOL> def __str__ ( self ) : <EOL> try : <EOL> return super ( Word , self ) . __str__ ( ) <EOL> except : <EOL> pass <EOL> if self . strRepr is None : <EOL> def charsAsStr ( s ) : <EOL> if len ( s ) > <NUM_LIT:4> : <EOL> return s [ : <NUM_LIT:4> ] + "<STR_LIT>" <EOL> else : <EOL> return s <EOL> if ( self . initCharsOrig != self . bodyCharsOrig ) : <EOL> self . strRepr = "<STR_LIT>" % ( charsAsStr ( self . initCharsOrig ) , charsAsStr ( self . bodyCharsOrig ) ) <EOL> else : <EOL> self . strRepr = "<STR_LIT>" % charsAsStr ( self . initCharsOrig ) <EOL> return self . strRepr <EOL> class Regex ( Token ) : <EOL> """<STR_LIT>""" <EOL> compiledREtype = type ( re . compile ( "<STR_LIT>" ) ) <EOL> def __init__ ( self , pattern , flags = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> super ( Regex , self ) . __init__ ( ) <EOL> if isinstance ( pattern , basestring ) : <EOL> if len ( pattern ) == <NUM_LIT:0> : <EOL> warnings . warn ( "<STR_LIT>" , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> self . pattern = pattern <EOL> self . flags = flags <EOL> try : <EOL> self . re = re . compile ( self . pattern , self . flags ) <EOL> self . reString = self . pattern <EOL> except sre_constants . error : <EOL> warnings . warn ( "<STR_LIT>" % pattern , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> raise <EOL> elif isinstance ( pattern , Regex . compiledREtype ) : <EOL> self . re = pattern <EOL> self . pattern = self . reString = str ( pattern ) <EOL> self . flags = flags <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . name = _ustr ( self ) <EOL> self . errmsg = "<STR_LIT>" + self . name <EOL> self . mayIndexError = False <EOL> self . mayReturnEmpty = True <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> result = self . re . match ( instring , loc ) <EOL> if not result : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> loc = result . end ( ) <EOL> d = result . groupdict ( ) <EOL> ret = ParseResults ( result . group ( ) ) <EOL> if d : <EOL> for k in d : <EOL> ret [ k ] = d [ k ] <EOL> return loc , ret <EOL> def __str__ ( self ) : <EOL> try : <EOL> return super ( Regex , self ) . __str__ ( ) <EOL> except : <EOL> pass <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT>" % repr ( self . pattern ) <EOL> return self . strRepr <EOL> class QuotedString ( Token ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , quoteChar , escChar = None , escQuote = None , multiline = False , unquoteResults = True , endQuoteChar = None ) : <EOL> """<STR_LIT>""" <EOL> super ( QuotedString , self ) . __init__ ( ) <EOL> quoteChar = quoteChar . strip ( ) <EOL> if len ( quoteChar ) == <NUM_LIT:0> : <EOL> warnings . warn ( "<STR_LIT>" , SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> raise SyntaxError ( ) <EOL> if endQuoteChar is None : <EOL> endQuoteChar = quoteChar <EOL> else : <EOL> endQuoteChar = endQuoteChar . strip ( ) <EOL> if len ( endQuoteChar ) == <NUM_LIT:0> : <EOL> warnings . warn ( "<STR_LIT>" , SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> raise SyntaxError ( ) <EOL> self . quoteChar = quoteChar <EOL> self . quoteCharLen = len ( quoteChar ) <EOL> self . firstQuoteChar = quoteChar [ <NUM_LIT:0> ] <EOL> self . endQuoteChar = endQuoteChar <EOL> self . endQuoteCharLen = len ( endQuoteChar ) <EOL> self . escChar = escChar <EOL> self . escQuote = escQuote <EOL> self . unquoteResults = unquoteResults <EOL> if multiline : <EOL> self . flags = re . MULTILINE | re . DOTALL <EOL> self . pattern = r'<STR_LIT>' % ( re . escape ( self . quoteChar ) , <EOL> _escapeRegexRangeChars ( self . endQuoteChar [ <NUM_LIT:0> ] ) , <EOL> ( escChar is not None and _escapeRegexRangeChars ( escChar ) or '<STR_LIT>' ) ) <EOL> else : <EOL> self . flags = <NUM_LIT:0> <EOL> self . pattern = r'<STR_LIT>' % ( re . escape ( self . quoteChar ) , <EOL> _escapeRegexRangeChars ( self . endQuoteChar [ <NUM_LIT:0> ] ) , <EOL> ( escChar is not None and _escapeRegexRangeChars ( escChar ) or '<STR_LIT>' ) ) <EOL> if len ( self . endQuoteChar ) > <NUM_LIT:1> : <EOL> self . pattern += ( <EOL> '<STR_LIT>' + '<STR_LIT>' . join ( "<STR_LIT>" % ( re . escape ( self . endQuoteChar [ : i ] ) , <EOL> _escapeRegexRangeChars ( self . endQuoteChar [ i ] ) ) <EOL> for i in range ( len ( self . endQuoteChar ) - <NUM_LIT:1> , <NUM_LIT:0> , - <NUM_LIT:1> ) ) + '<STR_LIT:)>' <EOL> ) <EOL> if escQuote : <EOL> self . pattern += ( r'<STR_LIT>' % re . escape ( escQuote ) ) <EOL> if escChar : <EOL> self . pattern += ( r'<STR_LIT>' % re . escape ( escChar ) ) <EOL> self . escCharReplacePattern = re . escape ( self . escChar ) + "<STR_LIT>" <EOL> self . pattern += ( r'<STR_LIT>' % re . escape ( self . endQuoteChar ) ) <EOL> try : <EOL> self . re = re . compile ( self . pattern , self . flags ) <EOL> self . reString = self . pattern <EOL> except sre_constants . error : <EOL> warnings . warn ( "<STR_LIT>" % self . pattern , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> raise <EOL> self . name = _ustr ( self ) <EOL> self . errmsg = "<STR_LIT>" + self . name <EOL> self . mayIndexError = False <EOL> self . mayReturnEmpty = True <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> result = instring [ loc ] == self . firstQuoteChar and self . re . match ( instring , loc ) or None <EOL> if not result : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> loc = result . end ( ) <EOL> ret = result . group ( ) <EOL> if self . unquoteResults : <EOL> ret = ret [ self . quoteCharLen : - self . endQuoteCharLen ] <EOL> if isinstance ( ret , basestring ) : <EOL> if self . escChar : <EOL> ret = re . sub ( self . escCharReplacePattern , "<STR_LIT>" , ret ) <EOL> if self . escQuote : <EOL> ret = ret . replace ( self . escQuote , self . endQuoteChar ) <EOL> return loc , ret <EOL> def __str__ ( self ) : <EOL> try : <EOL> return super ( QuotedString , self ) . __str__ ( ) <EOL> except : <EOL> pass <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT>" % ( self . quoteChar , self . endQuoteChar ) <EOL> return self . strRepr <EOL> class CharsNotIn ( Token ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , notChars , min = <NUM_LIT:1> , max = <NUM_LIT:0> , exact = <NUM_LIT:0> ) : <EOL> super ( CharsNotIn , self ) . __init__ ( ) <EOL> self . skipWhitespace = False <EOL> self . notChars = notChars <EOL> if min < <NUM_LIT:1> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> self . minLen = min <EOL> if max > <NUM_LIT:0> : <EOL> self . maxLen = max <EOL> else : <EOL> self . maxLen = _MAX_INT <EOL> if exact > <NUM_LIT:0> : <EOL> self . maxLen = exact <EOL> self . minLen = exact <EOL> self . name = _ustr ( self ) <EOL> self . errmsg = "<STR_LIT>" + self . name <EOL> self . mayReturnEmpty = ( self . minLen == <NUM_LIT:0> ) <EOL> self . mayIndexError = False <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if instring [ loc ] in self . notChars : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> start = loc <EOL> loc += <NUM_LIT:1> <EOL> notchars = self . notChars <EOL> maxlen = min ( start + self . maxLen , len ( instring ) ) <EOL> while loc < maxlen and ( instring [ loc ] not in notchars ) : <EOL> loc += <NUM_LIT:1> <EOL> if loc - start < self . minLen : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> return loc , instring [ start : loc ] <EOL> def __str__ ( self ) : <EOL> try : <EOL> return super ( CharsNotIn , self ) . __str__ ( ) <EOL> except : <EOL> pass <EOL> if self . strRepr is None : <EOL> if len ( self . notChars ) > <NUM_LIT:4> : <EOL> self . strRepr = "<STR_LIT>" % self . notChars [ : <NUM_LIT:4> ] <EOL> else : <EOL> self . strRepr = "<STR_LIT>" % self . notChars <EOL> return self . strRepr <EOL> class White ( Token ) : <EOL> """<STR_LIT>""" <EOL> whiteStrs = { <EOL> "<STR_LIT:U+0020>" : "<STR_LIT>" , <EOL> "<STR_LIT:\t>" : "<STR_LIT>" , <EOL> "<STR_LIT:\n>" : "<STR_LIT>" , <EOL> "<STR_LIT:\r>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> def __init__ ( self , ws = "<STR_LIT>" , min = <NUM_LIT:1> , max = <NUM_LIT:0> , exact = <NUM_LIT:0> ) : <EOL> super ( White , self ) . __init__ ( ) <EOL> self . matchWhite = ws <EOL> self . setWhitespaceChars ( "<STR_LIT>" . join ( c for c in self . whiteChars if c not in self . matchWhite ) ) <EOL> self . name = ( "<STR_LIT>" . join ( White . whiteStrs [ c ] for c in self . matchWhite ) ) <EOL> self . mayReturnEmpty = True <EOL> self . errmsg = "<STR_LIT>" + self . name <EOL> self . minLen = min <EOL> if max > <NUM_LIT:0> : <EOL> self . maxLen = max <EOL> else : <EOL> self . maxLen = _MAX_INT <EOL> if exact > <NUM_LIT:0> : <EOL> self . maxLen = exact <EOL> self . minLen = exact <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if not ( instring [ loc ] in self . matchWhite ) : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> start = loc <EOL> loc += <NUM_LIT:1> <EOL> maxloc = start + self . maxLen <EOL> maxloc = min ( maxloc , len ( instring ) ) <EOL> while loc < maxloc and instring [ loc ] in self . matchWhite : <EOL> loc += <NUM_LIT:1> <EOL> if loc - start < self . minLen : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> return loc , instring [ start : loc ] <EOL> class _PositionToken ( Token ) : <EOL> def __init__ ( self ) : <EOL> super ( _PositionToken , self ) . __init__ ( ) <EOL> self . name = self . __class__ . __name__ <EOL> self . mayReturnEmpty = True <EOL> self . mayIndexError = False <EOL> class GoToColumn ( _PositionToken ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , colno ) : <EOL> super ( GoToColumn , self ) . __init__ ( ) <EOL> self . col = colno <EOL> def preParse ( self , instring , loc ) : <EOL> if col ( loc , instring ) != self . col : <EOL> instrlen = len ( instring ) <EOL> if self . ignoreExprs : <EOL> loc = self . _skipIgnorables ( instring , loc ) <EOL> while loc < instrlen and instring [ loc ] . isspace ( ) and col ( loc , instring ) != self . col : <EOL> loc += <NUM_LIT:1> <EOL> return loc <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> thiscol = col ( loc , instring ) <EOL> if thiscol > self . col : <EOL> raise ParseException ( instring , loc , "<STR_LIT>" , self ) <EOL> newloc = loc + self . col - thiscol <EOL> ret = instring [ loc : newloc ] <EOL> return newloc , ret <EOL> class LineStart ( _PositionToken ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( LineStart , self ) . __init__ ( ) <EOL> self . setWhitespaceChars ( ParserElement . DEFAULT_WHITE_CHARS . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) ) <EOL> self . errmsg = "<STR_LIT>" <EOL> def preParse ( self , instring , loc ) : <EOL> preloc = super ( LineStart , self ) . preParse ( instring , loc ) <EOL> if instring [ preloc ] == "<STR_LIT:\n>" : <EOL> loc += <NUM_LIT:1> <EOL> return loc <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if not ( loc == <NUM_LIT:0> or <EOL> ( loc == self . preParse ( instring , <NUM_LIT:0> ) ) or <EOL> ( instring [ loc - <NUM_LIT:1> ] == "<STR_LIT:\n>" ) ) : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> return loc , [ ] <EOL> class LineEnd ( _PositionToken ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( LineEnd , self ) . __init__ ( ) <EOL> self . setWhitespaceChars ( ParserElement . DEFAULT_WHITE_CHARS . replace ( "<STR_LIT:\n>" , "<STR_LIT>" ) ) <EOL> self . errmsg = "<STR_LIT>" <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if loc < len ( instring ) : <EOL> if instring [ loc ] == "<STR_LIT:\n>" : <EOL> return loc + <NUM_LIT:1> , "<STR_LIT:\n>" <EOL> else : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> elif loc == len ( instring ) : <EOL> return loc + <NUM_LIT:1> , [ ] <EOL> else : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> class StringStart ( _PositionToken ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( StringStart , self ) . __init__ ( ) <EOL> self . errmsg = "<STR_LIT>" <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if loc != <NUM_LIT:0> : <EOL> if loc != self . preParse ( instring , <NUM_LIT:0> ) : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> return loc , [ ] <EOL> class StringEnd ( _PositionToken ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> super ( StringEnd , self ) . __init__ ( ) <EOL> self . errmsg = "<STR_LIT>" <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if loc < len ( instring ) : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> elif loc == len ( instring ) : <EOL> return loc + <NUM_LIT:1> , [ ] <EOL> elif loc > len ( instring ) : <EOL> return loc , [ ] <EOL> else : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> class WordStart ( _PositionToken ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , wordChars = printables ) : <EOL> super ( WordStart , self ) . __init__ ( ) <EOL> self . wordChars = set ( wordChars ) <EOL> self . errmsg = "<STR_LIT>" <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if loc != <NUM_LIT:0> : <EOL> if ( instring [ loc - <NUM_LIT:1> ] in self . wordChars or <EOL> instring [ loc ] not in self . wordChars ) : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> return loc , [ ] <EOL> class WordEnd ( _PositionToken ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , wordChars = printables ) : <EOL> super ( WordEnd , self ) . __init__ ( ) <EOL> self . wordChars = set ( wordChars ) <EOL> self . skipWhitespace = False <EOL> self . errmsg = "<STR_LIT>" <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> instrlen = len ( instring ) <EOL> if instrlen > <NUM_LIT:0> and loc < instrlen : <EOL> if ( instring [ loc ] in self . wordChars or <EOL> instring [ loc - <NUM_LIT:1> ] not in self . wordChars ) : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> return loc , [ ] <EOL> class ParseExpression ( ParserElement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , exprs , savelist = False ) : <EOL> super ( ParseExpression , self ) . __init__ ( savelist ) <EOL> if isinstance ( exprs , _generatorType ) : <EOL> exprs = list ( exprs ) <EOL> if isinstance ( exprs , basestring ) : <EOL> self . exprs = [ Literal ( exprs ) ] <EOL> elif isinstance ( exprs , collections . Sequence ) : <EOL> if all ( isinstance ( expr , basestring ) for expr in exprs ) : <EOL> exprs = map ( Literal , exprs ) <EOL> self . exprs = list ( exprs ) <EOL> else : <EOL> try : <EOL> self . exprs = list ( exprs ) <EOL> except TypeError : <EOL> self . exprs = [ exprs ] <EOL> self . callPreparse = False <EOL> def __getitem__ ( self , i ) : <EOL> return self . exprs [ i ] <EOL> def append ( self , other ) : <EOL> self . exprs . append ( other ) <EOL> self . strRepr = None <EOL> return self <EOL> def leaveWhitespace ( self ) : <EOL> """<STR_LIT>""" <EOL> self . skipWhitespace = False <EOL> self . exprs = [ e . copy ( ) for e in self . exprs ] <EOL> for e in self . exprs : <EOL> e . leaveWhitespace ( ) <EOL> return self <EOL> def ignore ( self , other ) : <EOL> if isinstance ( other , Suppress ) : <EOL> if other not in self . ignoreExprs : <EOL> super ( ParseExpression , self ) . ignore ( other ) <EOL> for e in self . exprs : <EOL> e . ignore ( self . ignoreExprs [ - <NUM_LIT:1> ] ) <EOL> else : <EOL> super ( ParseExpression , self ) . ignore ( other ) <EOL> for e in self . exprs : <EOL> e . ignore ( self . ignoreExprs [ - <NUM_LIT:1> ] ) <EOL> return self <EOL> def __str__ ( self ) : <EOL> try : <EOL> return super ( ParseExpression , self ) . __str__ ( ) <EOL> except : <EOL> pass <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT>" % ( self . __class__ . __name__ , _ustr ( self . exprs ) ) <EOL> return self . strRepr <EOL> def streamline ( self ) : <EOL> super ( ParseExpression , self ) . streamline ( ) <EOL> for e in self . exprs : <EOL> e . streamline ( ) <EOL> if ( len ( self . exprs ) == <NUM_LIT:2> ) : <EOL> other = self . exprs [ <NUM_LIT:0> ] <EOL> if ( isinstance ( other , self . __class__ ) and <EOL> not ( other . parseAction ) and <EOL> other . resultsName is None and <EOL> not other . debug ) : <EOL> self . exprs = other . exprs [ : ] + [ self . exprs [ <NUM_LIT:1> ] ] <EOL> self . strRepr = None <EOL> self . mayReturnEmpty |= other . mayReturnEmpty <EOL> self . mayIndexError |= other . mayIndexError <EOL> other = self . exprs [ - <NUM_LIT:1> ] <EOL> if ( isinstance ( other , self . __class__ ) and <EOL> not ( other . parseAction ) and <EOL> other . resultsName is None and <EOL> not other . debug ) : <EOL> self . exprs = self . exprs [ : - <NUM_LIT:1> ] + other . exprs [ : ] <EOL> self . strRepr = None <EOL> self . mayReturnEmpty |= other . mayReturnEmpty <EOL> self . mayIndexError |= other . mayIndexError <EOL> return self <EOL> def setResultsName ( self , name , listAllMatches = False ) : <EOL> ret = super ( ParseExpression , self ) . setResultsName ( name , listAllMatches ) <EOL> return ret <EOL> def validate ( self , validateTrace = [ ] ) : <EOL> tmp = validateTrace [ : ] + [ self ] <EOL> for e in self . exprs : <EOL> e . validate ( tmp ) <EOL> self . checkRecursion ( [ ] ) <EOL> def copy ( self ) : <EOL> ret = super ( ParseExpression , self ) . copy ( ) <EOL> ret . exprs = [ e . copy ( ) for e in self . exprs ] <EOL> return ret <EOL> class And ( ParseExpression ) : <EOL> """<STR_LIT>""" <EOL> class _ErrorStop ( Empty ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( And . _ErrorStop , self ) . __init__ ( * args , ** kwargs ) <EOL> self . name = '<STR_LIT:->' <EOL> self . leaveWhitespace ( ) <EOL> def __init__ ( self , exprs , savelist = True ) : <EOL> super ( And , self ) . __init__ ( exprs , savelist ) <EOL> self . mayReturnEmpty = all ( e . mayReturnEmpty for e in self . exprs ) <EOL> self . setWhitespaceChars ( self . exprs [ <NUM_LIT:0> ] . whiteChars ) <EOL> self . skipWhitespace = self . exprs [ <NUM_LIT:0> ] . skipWhitespace <EOL> self . callPreparse = True <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> loc , resultlist = self . exprs [ <NUM_LIT:0> ] . _parse ( instring , loc , doActions , callPreParse = False ) <EOL> errorStop = False <EOL> for e in self . exprs [ <NUM_LIT:1> : ] : <EOL> if isinstance ( e , And . _ErrorStop ) : <EOL> errorStop = True <EOL> continue <EOL> if errorStop : <EOL> try : <EOL> loc , exprtokens = e . _parse ( instring , loc , doActions ) <EOL> except ParseSyntaxException : <EOL> raise <EOL> except ParseBaseException as pe : <EOL> pe . __traceback__ = None <EOL> raise ParseSyntaxException ( pe ) <EOL> except IndexError : <EOL> raise ParseSyntaxException ( ParseException ( instring , len ( instring ) , self . errmsg , self ) ) <EOL> else : <EOL> loc , exprtokens = e . _parse ( instring , loc , doActions ) <EOL> if exprtokens or exprtokens . haskeys ( ) : <EOL> resultlist += exprtokens <EOL> return loc , resultlist <EOL> def __iadd__ ( self , other ) : <EOL> if isinstance ( other , basestring ) : <EOL> other = Literal ( other ) <EOL> return self . append ( other ) <EOL> def checkRecursion ( self , parseElementList ) : <EOL> subRecCheckList = parseElementList [ : ] + [ self ] <EOL> for e in self . exprs : <EOL> e . checkRecursion ( subRecCheckList ) <EOL> if not e . mayReturnEmpty : <EOL> break <EOL> def __str__ ( self ) : <EOL> if hasattr ( self , "<STR_LIT:name>" ) : <EOL> return self . name <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT:{>" + "<STR_LIT:U+0020>" . join ( _ustr ( e ) for e in self . exprs ) + "<STR_LIT:}>" <EOL> return self . strRepr <EOL> class Or ( ParseExpression ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , exprs , savelist = False ) : <EOL> super ( Or , self ) . __init__ ( exprs , savelist ) <EOL> if self . exprs : <EOL> self . mayReturnEmpty = any ( e . mayReturnEmpty for e in self . exprs ) <EOL> else : <EOL> self . mayReturnEmpty = True <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> maxExcLoc = - <NUM_LIT:1> <EOL> maxMatchLoc = - <NUM_LIT:1> <EOL> maxException = None <EOL> for e in self . exprs : <EOL> try : <EOL> loc2 = e . tryParse ( instring , loc ) <EOL> except ParseException as err : <EOL> err . __traceback__ = None <EOL> if err . loc > maxExcLoc : <EOL> maxException = err <EOL> maxExcLoc = err . loc <EOL> except IndexError : <EOL> if len ( instring ) > maxExcLoc : <EOL> maxException = ParseException ( instring , len ( instring ) , e . errmsg , self ) <EOL> maxExcLoc = len ( instring ) <EOL> else : <EOL> if loc2 > maxMatchLoc : <EOL> maxMatchLoc = loc2 <EOL> maxMatchExp = e <EOL> if maxMatchLoc < <NUM_LIT:0> : <EOL> if maxException is not None : <EOL> raise maxException <EOL> else : <EOL> raise ParseException ( instring , loc , "<STR_LIT>" , self ) <EOL> return maxMatchExp . _parse ( instring , loc , doActions ) <EOL> def __ixor__ ( self , other ) : <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> return self . append ( other ) <EOL> def __str__ ( self ) : <EOL> if hasattr ( self , "<STR_LIT:name>" ) : <EOL> return self . name <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT:{>" + "<STR_LIT>" . join ( _ustr ( e ) for e in self . exprs ) + "<STR_LIT:}>" <EOL> return self . strRepr <EOL> def checkRecursion ( self , parseElementList ) : <EOL> subRecCheckList = parseElementList [ : ] + [ self ] <EOL> for e in self . exprs : <EOL> e . checkRecursion ( subRecCheckList ) <EOL> class MatchFirst ( ParseExpression ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , exprs , savelist = False ) : <EOL> super ( MatchFirst , self ) . __init__ ( exprs , savelist ) <EOL> if self . exprs : <EOL> self . mayReturnEmpty = any ( e . mayReturnEmpty for e in self . exprs ) <EOL> else : <EOL> self . mayReturnEmpty = True <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> maxExcLoc = - <NUM_LIT:1> <EOL> maxException = None <EOL> for e in self . exprs : <EOL> try : <EOL> ret = e . _parse ( instring , loc , doActions ) <EOL> return ret <EOL> except ParseException as err : <EOL> if err . loc > maxExcLoc : <EOL> maxException = err <EOL> maxExcLoc = err . loc <EOL> except IndexError : <EOL> if len ( instring ) > maxExcLoc : <EOL> maxException = ParseException ( instring , len ( instring ) , e . errmsg , self ) <EOL> maxExcLoc = len ( instring ) <EOL> else : <EOL> if maxException is not None : <EOL> raise maxException <EOL> else : <EOL> raise ParseException ( instring , loc , "<STR_LIT>" , self ) <EOL> def __ior__ ( self , other ) : <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> return self . append ( other ) <EOL> def __str__ ( self ) : <EOL> if hasattr ( self , "<STR_LIT:name>" ) : <EOL> return self . name <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT:{>" + "<STR_LIT>" . join ( _ustr ( e ) for e in self . exprs ) + "<STR_LIT:}>" <EOL> return self . strRepr <EOL> def checkRecursion ( self , parseElementList ) : <EOL> subRecCheckList = parseElementList [ : ] + [ self ] <EOL> for e in self . exprs : <EOL> e . checkRecursion ( subRecCheckList ) <EOL> class Each ( ParseExpression ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , exprs , savelist = True ) : <EOL> super ( Each , self ) . __init__ ( exprs , savelist ) <EOL> self . mayReturnEmpty = all ( e . mayReturnEmpty for e in self . exprs ) <EOL> self . skipWhitespace = True <EOL> self . initExprGroups = True <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if self . initExprGroups : <EOL> opt1 = [ e . expr for e in self . exprs if isinstance ( e , Optional ) ] <EOL> opt2 = [ e for e in self . exprs if e . mayReturnEmpty and e not in opt1 ] <EOL> self . optionals = opt1 + opt2 <EOL> self . multioptionals = [ e . expr for e in self . exprs if isinstance ( e , ZeroOrMore ) ] <EOL> self . multirequired = [ e . expr for e in self . exprs if isinstance ( e , OneOrMore ) ] <EOL> self . required = [ e for e in self . exprs if not isinstance ( e , ( Optional , ZeroOrMore , OneOrMore ) ) ] <EOL> self . required += self . multirequired <EOL> self . initExprGroups = False <EOL> tmpLoc = loc <EOL> tmpReqd = self . required [ : ] <EOL> tmpOpt = self . optionals [ : ] <EOL> matchOrder = [ ] <EOL> keepMatching = True <EOL> while keepMatching : <EOL> tmpExprs = tmpReqd + tmpOpt + self . multioptionals + self . multirequired <EOL> failed = [ ] <EOL> for e in tmpExprs : <EOL> try : <EOL> tmpLoc = e . tryParse ( instring , tmpLoc ) <EOL> except ParseException : <EOL> failed . append ( e ) <EOL> else : <EOL> matchOrder . append ( e ) <EOL> if e in tmpReqd : <EOL> tmpReqd . remove ( e ) <EOL> elif e in tmpOpt : <EOL> tmpOpt . remove ( e ) <EOL> if len ( failed ) == len ( tmpExprs ) : <EOL> keepMatching = False <EOL> if tmpReqd : <EOL> missing = "<STR_LIT:U+002CU+0020>" . join ( _ustr ( e ) for e in tmpReqd ) <EOL> raise ParseException ( instring , loc , "<STR_LIT>" % missing ) <EOL> matchOrder += [ e for e in self . exprs if isinstance ( e , Optional ) and e . expr in tmpOpt ] <EOL> resultlist = [ ] <EOL> for e in matchOrder : <EOL> loc , results = e . _parse ( instring , loc , doActions ) <EOL> resultlist . append ( results ) <EOL> finalResults = ParseResults ( [ ] ) <EOL> for r in resultlist : <EOL> dups = { } <EOL> for k in r . keys ( ) : <EOL> if k in finalResults : <EOL> tmp = ParseResults ( finalResults [ k ] ) <EOL> tmp += ParseResults ( r [ k ] ) <EOL> dups [ k ] = tmp <EOL> finalResults += ParseResults ( r ) <EOL> for k , v in dups . items ( ) : <EOL> finalResults [ k ] = v <EOL> return loc , finalResults <EOL> def __str__ ( self ) : <EOL> if hasattr ( self , "<STR_LIT:name>" ) : <EOL> return self . name <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT:{>" + "<STR_LIT>" . join ( _ustr ( e ) for e in self . exprs ) + "<STR_LIT:}>" <EOL> return self . strRepr <EOL> def checkRecursion ( self , parseElementList ) : <EOL> subRecCheckList = parseElementList [ : ] + [ self ] <EOL> for e in self . exprs : <EOL> e . checkRecursion ( subRecCheckList ) <EOL> class ParseElementEnhance ( ParserElement ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , expr , savelist = False ) : <EOL> super ( ParseElementEnhance , self ) . __init__ ( savelist ) <EOL> if isinstance ( expr , basestring ) : <EOL> expr = Literal ( expr ) <EOL> self . expr = expr <EOL> self . strRepr = None <EOL> if expr is not None : <EOL> self . mayIndexError = expr . mayIndexError <EOL> self . mayReturnEmpty = expr . mayReturnEmpty <EOL> self . setWhitespaceChars ( expr . whiteChars ) <EOL> self . skipWhitespace = expr . skipWhitespace <EOL> self . saveAsList = expr . saveAsList <EOL> self . callPreparse = expr . callPreparse <EOL> self . ignoreExprs . extend ( expr . ignoreExprs ) <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> if self . expr is not None : <EOL> return self . expr . _parse ( instring , loc , doActions , callPreParse = False ) <EOL> else : <EOL> raise ParseException ( "<STR_LIT>" , loc , self . errmsg , self ) <EOL> def leaveWhitespace ( self ) : <EOL> self . skipWhitespace = False <EOL> self . expr = self . expr . copy ( ) <EOL> if self . expr is not None : <EOL> self . expr . leaveWhitespace ( ) <EOL> return self <EOL> def ignore ( self , other ) : <EOL> if isinstance ( other , Suppress ) : <EOL> if other not in self . ignoreExprs : <EOL> super ( ParseElementEnhance , self ) . ignore ( other ) <EOL> if self . expr is not None : <EOL> self . expr . ignore ( self . ignoreExprs [ - <NUM_LIT:1> ] ) <EOL> else : <EOL> super ( ParseElementEnhance , self ) . ignore ( other ) <EOL> if self . expr is not None : <EOL> self . expr . ignore ( self . ignoreExprs [ - <NUM_LIT:1> ] ) <EOL> return self <EOL> def streamline ( self ) : <EOL> super ( ParseElementEnhance , self ) . streamline ( ) <EOL> if self . expr is not None : <EOL> self . expr . streamline ( ) <EOL> return self <EOL> def checkRecursion ( self , parseElementList ) : <EOL> if self in parseElementList : <EOL> raise RecursiveGrammarException ( parseElementList + [ self ] ) <EOL> subRecCheckList = parseElementList [ : ] + [ self ] <EOL> if self . expr is not None : <EOL> self . expr . checkRecursion ( subRecCheckList ) <EOL> def validate ( self , validateTrace = [ ] ) : <EOL> tmp = validateTrace [ : ] + [ self ] <EOL> if self . expr is not None : <EOL> self . expr . validate ( tmp ) <EOL> self . checkRecursion ( [ ] ) <EOL> def __str__ ( self ) : <EOL> try : <EOL> return super ( ParseElementEnhance , self ) . __str__ ( ) <EOL> except : <EOL> pass <EOL> if self . strRepr is None and self . expr is not None : <EOL> self . strRepr = "<STR_LIT>" % ( self . __class__ . __name__ , _ustr ( self . expr ) ) <EOL> return self . strRepr <EOL> class FollowedBy ( ParseElementEnhance ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , expr ) : <EOL> super ( FollowedBy , self ) . __init__ ( expr ) <EOL> self . mayReturnEmpty = True <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> self . expr . tryParse ( instring , loc ) <EOL> return loc , [ ] <EOL> class NotAny ( ParseElementEnhance ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , expr ) : <EOL> super ( NotAny , self ) . __init__ ( expr ) <EOL> self . skipWhitespace = False <EOL> self . mayReturnEmpty = True <EOL> self . errmsg = "<STR_LIT>" + _ustr ( self . expr ) <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> try : <EOL> self . expr . tryParse ( instring , loc ) <EOL> except ( ParseException , IndexError ) : <EOL> pass <EOL> else : <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> return loc , [ ] <EOL> def __str__ ( self ) : <EOL> if hasattr ( self , "<STR_LIT:name>" ) : <EOL> return self . name <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT>" + _ustr ( self . expr ) + "<STR_LIT:}>" <EOL> return self . strRepr <EOL> class ZeroOrMore ( ParseElementEnhance ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , expr ) : <EOL> super ( ZeroOrMore , self ) . __init__ ( expr ) <EOL> self . mayReturnEmpty = True <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> tokens = [ ] <EOL> try : <EOL> loc , tokens = self . expr . _parse ( instring , loc , doActions , callPreParse = False ) <EOL> hasIgnoreExprs = ( len ( self . ignoreExprs ) > <NUM_LIT:0> ) <EOL> while <NUM_LIT:1> : <EOL> if hasIgnoreExprs : <EOL> preloc = self . _skipIgnorables ( instring , loc ) <EOL> else : <EOL> preloc = loc <EOL> loc , tmptokens = self . expr . _parse ( instring , preloc , doActions ) <EOL> if tmptokens or tmptokens . haskeys ( ) : <EOL> tokens += tmptokens <EOL> except ( ParseException , IndexError ) : <EOL> pass <EOL> return loc , tokens <EOL> def __str__ ( self ) : <EOL> if hasattr ( self , "<STR_LIT:name>" ) : <EOL> return self . name <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT:[>" + _ustr ( self . expr ) + "<STR_LIT>" <EOL> return self . strRepr <EOL> def setResultsName ( self , name , listAllMatches = False ) : <EOL> ret = super ( ZeroOrMore , self ) . setResultsName ( name , listAllMatches ) <EOL> ret . saveAsList = True <EOL> return ret <EOL> class OneOrMore ( ParseElementEnhance ) : <EOL> """<STR_LIT>""" <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> loc , tokens = self . expr . _parse ( instring , loc , doActions , callPreParse = False ) <EOL> try : <EOL> hasIgnoreExprs = ( len ( self . ignoreExprs ) > <NUM_LIT:0> ) <EOL> while <NUM_LIT:1> : <EOL> if hasIgnoreExprs : <EOL> preloc = self . _skipIgnorables ( instring , loc ) <EOL> else : <EOL> preloc = loc <EOL> loc , tmptokens = self . expr . _parse ( instring , preloc , doActions ) <EOL> if tmptokens or tmptokens . haskeys ( ) : <EOL> tokens += tmptokens <EOL> except ( ParseException , IndexError ) : <EOL> pass <EOL> return loc , tokens <EOL> def __str__ ( self ) : <EOL> if hasattr ( self , "<STR_LIT:name>" ) : <EOL> return self . name <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT:{>" + _ustr ( self . expr ) + "<STR_LIT>" <EOL> return self . strRepr <EOL> def setResultsName ( self , name , listAllMatches = False ) : <EOL> ret = super ( OneOrMore , self ) . setResultsName ( name , listAllMatches ) <EOL> ret . saveAsList = True <EOL> return ret <EOL> class _NullToken ( object ) : <EOL> def __bool__ ( self ) : <EOL> return False <EOL> __nonzero__ = __bool__ <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" <EOL> _optionalNotMatched = _NullToken ( ) <EOL> class Optional ( ParseElementEnhance ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , expr , default = _optionalNotMatched ) : <EOL> super ( Optional , self ) . __init__ ( expr , savelist = False ) <EOL> self . defaultValue = default <EOL> self . mayReturnEmpty = True <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> try : <EOL> loc , tokens = self . expr . _parse ( instring , loc , doActions , callPreParse = False ) <EOL> except ( ParseException , IndexError ) : <EOL> if self . defaultValue is not _optionalNotMatched : <EOL> if self . expr . resultsName : <EOL> tokens = ParseResults ( [ self . defaultValue ] ) <EOL> tokens [ self . expr . resultsName ] = self . defaultValue <EOL> else : <EOL> tokens = [ self . defaultValue ] <EOL> else : <EOL> tokens = [ ] <EOL> return loc , tokens <EOL> def __str__ ( self ) : <EOL> if hasattr ( self , "<STR_LIT:name>" ) : <EOL> return self . name <EOL> if self . strRepr is None : <EOL> self . strRepr = "<STR_LIT:[>" + _ustr ( self . expr ) + "<STR_LIT:]>" <EOL> return self . strRepr <EOL> class SkipTo ( ParseElementEnhance ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , other , include = False , ignore = None , failOn = None ) : <EOL> super ( SkipTo , self ) . __init__ ( other ) <EOL> self . ignoreExpr = ignore <EOL> self . mayReturnEmpty = True <EOL> self . mayIndexError = False <EOL> self . includeMatch = include <EOL> self . asList = False <EOL> if failOn is not None and isinstance ( failOn , basestring ) : <EOL> self . failOn = Literal ( failOn ) <EOL> else : <EOL> self . failOn = failOn <EOL> self . errmsg = "<STR_LIT>" + _ustr ( self . expr ) <EOL> def parseImpl ( self , instring , loc , doActions = True ) : <EOL> startLoc = loc <EOL> instrlen = len ( instring ) <EOL> expr = self . expr <EOL> failParse = False <EOL> while loc <= instrlen : <EOL> try : <EOL> if self . failOn : <EOL> try : <EOL> self . failOn . tryParse ( instring , loc ) <EOL> except ParseBaseException : <EOL> pass <EOL> else : <EOL> failParse = True <EOL> raise ParseException ( instring , loc , "<STR_LIT>" + str ( self . failOn ) ) <EOL> failParse = False <EOL> if self . ignoreExpr is not None : <EOL> while <NUM_LIT:1> : <EOL> try : <EOL> loc = self . ignoreExpr . tryParse ( instring , loc ) <EOL> except ParseBaseException : <EOL> break <EOL> expr . _parse ( instring , loc , doActions = False , callPreParse = False ) <EOL> skipText = instring [ startLoc : loc ] <EOL> if self . includeMatch : <EOL> loc , mat = expr . _parse ( instring , loc , doActions , callPreParse = False ) <EOL> if mat : <EOL> skipRes = ParseResults ( skipText ) <EOL> skipRes += mat <EOL> return loc , [ skipRes ] <EOL> else : <EOL> return loc , [ skipText ] <EOL> else : <EOL> return loc , [ skipText ] <EOL> except ( ParseException , IndexError ) : <EOL> if failParse : <EOL> raise <EOL> else : <EOL> loc += <NUM_LIT:1> <EOL> raise ParseException ( instring , loc , self . errmsg , self ) <EOL> class Forward ( ParseElementEnhance ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , other = None ) : <EOL> super ( Forward , self ) . __init__ ( other , savelist = False ) <EOL> def __lshift__ ( self , other ) : <EOL> if isinstance ( other , basestring ) : <EOL> other = ParserElement . literalStringClass ( other ) <EOL> self . expr = other <EOL> self . mayReturnEmpty = other . mayReturnEmpty <EOL> self . strRepr = None <EOL> self . mayIndexError = self . expr . mayIndexError <EOL> self . mayReturnEmpty = self . expr . mayReturnEmpty <EOL> self . setWhitespaceChars ( self . expr . whiteChars ) <EOL> self . skipWhitespace = self . expr . skipWhitespace <EOL> self . saveAsList = self . expr . saveAsList <EOL> self . ignoreExprs . extend ( self . expr . ignoreExprs ) <EOL> return self <EOL> def __ilshift__ ( self , other ) : <EOL> return self << other <EOL> def leaveWhitespace ( self ) : <EOL> self . skipWhitespace = False <EOL> return self <EOL> def streamline ( self ) : <EOL> if not self . streamlined : <EOL> self . streamlined = True <EOL> if self . expr is not None : <EOL> self . expr . streamline ( ) <EOL> return self <EOL> def validate ( self , validateTrace = [ ] ) : <EOL> if self not in validateTrace : <EOL> tmp = validateTrace [ : ] + [ self ] <EOL> if self . expr is not None : <EOL> self . expr . validate ( tmp ) <EOL> self . checkRecursion ( [ ] ) <EOL> def __str__ ( self ) : <EOL> if hasattr ( self , "<STR_LIT:name>" ) : <EOL> return self . name <EOL> self . _revertClass = self . __class__ <EOL> self . __class__ = _ForwardNoRecurse <EOL> try : <EOL> if self . expr is not None : <EOL> retString = _ustr ( self . expr ) <EOL> else : <EOL> retString = "<STR_LIT:None>" <EOL> finally : <EOL> self . __class__ = self . _revertClass <EOL> return self . __class__ . __name__ + "<STR_LIT>" + retString <EOL> def copy ( self ) : <EOL> if self . expr is not None : <EOL> return super ( Forward , self ) . copy ( ) <EOL> else : <EOL> ret = Forward ( ) <EOL> ret <<= self <EOL> return ret <EOL> class _ForwardNoRecurse ( Forward ) : <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" <EOL> class TokenConverter ( ParseElementEnhance ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , expr , savelist = False ) : <EOL> super ( TokenConverter , self ) . __init__ ( expr ) <EOL> self . saveAsList = False <EOL> class Upcase ( TokenConverter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args ) : <EOL> super ( Upcase , self ) . __init__ ( * args ) <EOL> warnings . warn ( "<STR_LIT>" , <EOL> DeprecationWarning , stacklevel = <NUM_LIT:2> ) <EOL> def postParse ( self , instring , loc , tokenlist ) : <EOL> return list ( map ( str . upper , tokenlist ) ) <EOL> class Combine ( TokenConverter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , expr , joinString = "<STR_LIT>" , adjacent = True ) : <EOL> super ( Combine , self ) . __init__ ( expr ) <EOL> if adjacent : <EOL> self . leaveWhitespace ( ) <EOL> self . adjacent = adjacent <EOL> self . skipWhitespace = True <EOL> self . joinString = joinString <EOL> self . callPreparse = True <EOL> def ignore ( self , other ) : <EOL> if self . adjacent : <EOL> ParserElement . ignore ( self , other ) <EOL> else : <EOL> super ( Combine , self ) . ignore ( other ) <EOL> return self <EOL> def postParse ( self , instring , loc , tokenlist ) : <EOL> retToks = tokenlist . copy ( ) <EOL> del retToks [ : ] <EOL> retToks += ParseResults ( [ "<STR_LIT>" . join ( tokenlist . _asStringList ( self . joinString ) ) ] , modal = self . modalResults ) <EOL> if self . resultsName and retToks . haskeys ( ) : <EOL> return [ retToks ] <EOL> else : <EOL> return retToks <EOL> class Group ( TokenConverter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , expr ) : <EOL> super ( Group , self ) . __init__ ( expr ) <EOL> self . saveAsList = True <EOL> def postParse ( self , instring , loc , tokenlist ) : <EOL> return [ tokenlist ] <EOL> class Dict ( TokenConverter ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , expr ) : <EOL> super ( Dict , self ) . __init__ ( expr ) <EOL> self . saveAsList = True <EOL> def postParse ( self , instring , loc , tokenlist ) : <EOL> for i , tok in enumerate ( tokenlist ) : <EOL> if len ( tok ) == <NUM_LIT:0> : <EOL> continue <EOL> ikey = tok [ <NUM_LIT:0> ] <EOL> if isinstance ( ikey , int ) : <EOL> ikey = _ustr ( tok [ <NUM_LIT:0> ] ) . strip ( ) <EOL> if len ( tok ) == <NUM_LIT:1> : <EOL> tokenlist [ ikey ] = _ParseResultsWithOffset ( "<STR_LIT>" , i ) <EOL> elif len ( tok ) == <NUM_LIT:2> and not isinstance ( tok [ <NUM_LIT:1> ] , ParseResults ) : <EOL> tokenlist [ ikey ] = _ParseResultsWithOffset ( tok [ <NUM_LIT:1> ] , i ) <EOL> else : <EOL> dictvalue = tok . copy ( ) <EOL> del dictvalue [ <NUM_LIT:0> ] <EOL> if len ( dictvalue ) != <NUM_LIT:1> or ( isinstance ( dictvalue , ParseResults ) and dictvalue . haskeys ( ) ) : <EOL> tokenlist [ ikey ] = _ParseResultsWithOffset ( dictvalue , i ) <EOL> else : <EOL> tokenlist [ ikey ] = _ParseResultsWithOffset ( dictvalue [ <NUM_LIT:0> ] , i ) <EOL> if self . resultsName : <EOL> return [ tokenlist ] <EOL> else : <EOL> return tokenlist <EOL> class Suppress ( TokenConverter ) : <EOL> """<STR_LIT>""" <EOL> def postParse ( self , instring , loc , tokenlist ) : <EOL> return [ ] <EOL> def suppress ( self ) : <EOL> return self <EOL> class OnlyOnce ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , methodCall ) : <EOL> self . callable = _trim_arity ( methodCall ) <EOL> self . called = False <EOL> def __call__ ( self , s , l , t ) : <EOL> if not self . called : <EOL> results = self . callable ( s , l , t ) <EOL> self . called = True <EOL> return results <EOL> raise ParseException ( s , l , "<STR_LIT>" ) <EOL> def reset ( self ) : <EOL> self . called = False <EOL> def traceParseAction ( f ) : <EOL> """<STR_LIT>""" <EOL> f = _trim_arity ( f ) <EOL> def z ( * paArgs ) : <EOL> thisFunc = f . func_name <EOL> s , l , t = paArgs [ - <NUM_LIT:3> : ] <EOL> if len ( paArgs ) > <NUM_LIT:3> : <EOL> thisFunc = paArgs [ <NUM_LIT:0> ] . __class__ . __name__ + '<STR_LIT:.>' + thisFunc <EOL> sys . stderr . write ( "<STR_LIT>" % ( thisFunc , line ( l , s ) , l , t ) ) <EOL> try : <EOL> ret = f ( * paArgs ) <EOL> except Exception as exc : <EOL> sys . stderr . write ( "<STR_LIT>" % ( thisFunc , exc ) ) <EOL> raise <EOL> sys . stderr . write ( "<STR_LIT>" % ( thisFunc , ret ) ) <EOL> return ret <EOL> try : <EOL> z . __name__ = f . __name__ <EOL> except AttributeError : <EOL> pass <EOL> return z <EOL> def delimitedList ( expr , delim = "<STR_LIT:U+002C>" , combine = False ) : <EOL> """<STR_LIT>""" <EOL> dlName = _ustr ( expr ) + "<STR_LIT>" + _ustr ( delim ) + "<STR_LIT:U+0020>" + _ustr ( expr ) + "<STR_LIT>" <EOL> if combine : <EOL> return Combine ( expr + ZeroOrMore ( delim + expr ) ) . setName ( dlName ) <EOL> else : <EOL> return ( expr + ZeroOrMore ( Suppress ( delim ) + expr ) ) . setName ( dlName ) <EOL> def countedArray ( expr , intExpr = None ) : <EOL> """<STR_LIT>""" <EOL> arrayExpr = Forward ( ) <EOL> def countFieldParseAction ( s , l , t ) : <EOL> n = t [ <NUM_LIT:0> ] <EOL> arrayExpr << ( n and Group ( And ( [ expr ] * n ) ) or Group ( empty ) ) <EOL> return [ ] <EOL> if intExpr is None : <EOL> intExpr = Word ( nums ) . setParseAction ( lambda t : int ( t [ <NUM_LIT:0> ] ) ) <EOL> else : <EOL> intExpr = intExpr . copy ( ) <EOL> intExpr . setName ( "<STR_LIT>" ) <EOL> intExpr . addParseAction ( countFieldParseAction , callDuringTry = True ) <EOL> return ( intExpr + arrayExpr ) <EOL> def _flatten ( L ) : <EOL> ret = [ ] <EOL> for i in L : <EOL> if isinstance ( i , list ) : <EOL> ret . extend ( _flatten ( i ) ) <EOL> else : <EOL> ret . append ( i ) <EOL> return ret <EOL> def matchPreviousLiteral ( expr ) : <EOL> """<STR_LIT>""" <EOL> rep = Forward ( ) <EOL> def copyTokenToRepeater ( s , l , t ) : <EOL> if t : <EOL> if len ( t ) == <NUM_LIT:1> : <EOL> rep << t [ <NUM_LIT:0> ] <EOL> else : <EOL> tflat = _flatten ( t . asList ( ) ) <EOL> rep << And ( [ Literal ( tt ) for tt in tflat ] ) <EOL> else : <EOL> rep << Empty ( ) <EOL> expr . addParseAction ( copyTokenToRepeater , callDuringTry = True ) <EOL> return rep <EOL> def matchPreviousExpr ( expr ) : <EOL> """<STR_LIT>""" <EOL> rep = Forward ( ) <EOL> e2 = expr . copy ( ) <EOL> rep <<= e2 <EOL> def copyTokenToRepeater ( s , l , t ) : <EOL> matchTokens = _flatten ( t . asList ( ) ) <EOL> def mustMatchTheseTokens ( s , l , t ) : <EOL> theseTokens = _flatten ( t . asList ( ) ) <EOL> if theseTokens != matchTokens : <EOL> raise ParseException ( "<STR_LIT>" , <NUM_LIT:0> , "<STR_LIT>" ) <EOL> rep . setParseAction ( mustMatchTheseTokens , callDuringTry = True ) <EOL> expr . addParseAction ( copyTokenToRepeater , callDuringTry = True ) <EOL> return rep <EOL> def _escapeRegexRangeChars ( s ) : <EOL> for c in r"<STR_LIT>" : <EOL> s = s . replace ( c , _bslash + c ) <EOL> s = s . replace ( "<STR_LIT:\n>" , r"<STR_LIT:\n>" ) <EOL> s = s . replace ( "<STR_LIT:\t>" , r"<STR_LIT:\t>" ) <EOL> return _ustr ( s ) <EOL> def oneOf ( strs , caseless = False , useRegex = True ) : <EOL> """<STR_LIT>""" <EOL> if caseless : <EOL> isequal = ( lambda a , b : a . upper ( ) == b . upper ( ) ) <EOL> masks = ( lambda a , b : b . upper ( ) . startswith ( a . upper ( ) ) ) <EOL> parseElementClass = CaselessLiteral <EOL> else : <EOL> isequal = ( lambda a , b : a == b ) <EOL> masks = ( lambda a , b : b . startswith ( a ) ) <EOL> parseElementClass = Literal <EOL> symbols = [ ] <EOL> if isinstance ( strs , basestring ) : <EOL> symbols = strs . split ( ) <EOL> elif isinstance ( strs , collections . Sequence ) : <EOL> symbols = list ( strs [ : ] ) <EOL> elif isinstance ( strs , _generatorType ) : <EOL> symbols = list ( strs ) <EOL> else : <EOL> warnings . warn ( "<STR_LIT>" , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> if not symbols : <EOL> return NoMatch ( ) <EOL> i = <NUM_LIT:0> <EOL> while i < len ( symbols ) - <NUM_LIT:1> : <EOL> cur = symbols [ i ] <EOL> for j , other in enumerate ( symbols [ i + <NUM_LIT:1> : ] ) : <EOL> if ( isequal ( other , cur ) ) : <EOL> del symbols [ i + j + <NUM_LIT:1> ] <EOL> break <EOL> elif ( masks ( cur , other ) ) : <EOL> del symbols [ i + j + <NUM_LIT:1> ] <EOL> symbols . insert ( i , other ) <EOL> cur = other <EOL> break <EOL> else : <EOL> i += <NUM_LIT:1> <EOL> if not caseless and useRegex : <EOL> try : <EOL> if len ( symbols ) == len ( "<STR_LIT>" . join ( symbols ) ) : <EOL> return Regex ( "<STR_LIT>" % "<STR_LIT>" . join ( _escapeRegexRangeChars ( sym ) for sym in symbols ) ) <EOL> else : <EOL> return Regex ( "<STR_LIT:|>" . join ( re . escape ( sym ) for sym in symbols ) ) <EOL> except : <EOL> warnings . warn ( "<STR_LIT>" , <EOL> SyntaxWarning , stacklevel = <NUM_LIT:2> ) <EOL> return MatchFirst ( [ parseElementClass ( sym ) for sym in symbols ] ) <EOL> def dictOf ( key , value ) : <EOL> """<STR_LIT>""" <EOL> return Dict ( ZeroOrMore ( Group ( key + value ) ) ) <EOL> def originalTextFor ( expr , asString = True ) : <EOL> """<STR_LIT>""" <EOL> locMarker = Empty ( ) . setParseAction ( lambda s , loc , t : loc ) <EOL> endlocMarker = locMarker . copy ( ) <EOL> endlocMarker . callPreparse = False <EOL> matchExpr = locMarker ( "<STR_LIT>" ) + expr + endlocMarker ( "<STR_LIT>" ) <EOL> if asString : <EOL> extractText = lambda s , l , t : s [ t . _original_start : t . _original_end ] <EOL> else : <EOL> def extractText ( s , l , t ) : <EOL> del t [ : ] <EOL> t . insert ( <NUM_LIT:0> , s [ t . _original_start : t . _original_end ] ) <EOL> del t [ "<STR_LIT>" ] <EOL> del t [ "<STR_LIT>" ] <EOL> matchExpr . setParseAction ( extractText ) <EOL> return matchExpr <EOL> def ungroup ( expr ) : <EOL> """<STR_LIT>""" <EOL> return TokenConverter ( expr ) . setParseAction ( lambda t : t [ <NUM_LIT:0> ] ) <EOL> def locatedExpr ( expr ) : <EOL> """<STR_LIT>""" <EOL> locator = Empty ( ) . setParseAction ( lambda s , l , t : l ) <EOL> return Group ( locator ( "<STR_LIT>" ) + expr ( "<STR_LIT:value>" ) + locator . copy ( ) . leaveWhitespace ( ) ( "<STR_LIT>" ) ) <EOL> empty = Empty ( ) . setName ( "<STR_LIT>" ) <EOL> lineStart = LineStart ( ) . setName ( "<STR_LIT>" ) <EOL> lineEnd = LineEnd ( ) . setName ( "<STR_LIT>" ) <EOL> stringStart = StringStart ( ) . setName ( "<STR_LIT>" ) <EOL> stringEnd = StringEnd ( ) . setName ( "<STR_LIT>" ) <EOL> _escapedPunc = Word ( _bslash , r"<STR_LIT>" , exact = <NUM_LIT:2> ) . setParseAction ( lambda s , l , t : t [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] ) <EOL> _escapedHexChar = Regex ( r"<STR_LIT>" ) . setParseAction ( lambda s , l , t : unichr ( int ( t [ <NUM_LIT:0> ] . lstrip ( r'<STR_LIT>' ) , <NUM_LIT:16> ) ) ) <EOL> _escapedOctChar = Regex ( r"<STR_LIT>" ) . setParseAction ( lambda s , l , t : unichr ( int ( t [ <NUM_LIT:0> ] [ <NUM_LIT:1> : ] , <NUM_LIT:8> ) ) ) <EOL> _singleChar = _escapedPunc | _escapedHexChar | _escapedOctChar | Word ( printables , excludeChars = r'<STR_LIT>' , exact = <NUM_LIT:1> ) <EOL> _charRange = Group ( _singleChar + Suppress ( "<STR_LIT:->" ) + _singleChar ) <EOL> _reBracketExpr = Literal ( "<STR_LIT:[>" ) + Optional ( "<STR_LIT>" ) . setResultsName ( "<STR_LIT>" ) + Group ( OneOrMore ( _charRange | _singleChar ) ) . setResultsName ( "<STR_LIT:body>" ) + "<STR_LIT:]>" <EOL> def srange ( s ) : <EOL> r"""<STR_LIT>""" <EOL> _expanded = lambda p : p if not isinstance ( p , ParseResults ) else '<STR_LIT>' . join ( unichr ( c ) for c in range ( ord ( p [ <NUM_LIT:0> ] ) , ord ( p [ <NUM_LIT:1> ] ) + <NUM_LIT:1> ) ) <EOL> try : <EOL> return "<STR_LIT>" . join ( _expanded ( part ) for part in _reBracketExpr . parseString ( s ) . body ) <EOL> except : <EOL> return "<STR_LIT>" <EOL> def matchOnlyAtCol ( n ) : <EOL> """<STR_LIT>""" <EOL> def verifyCol ( strg , locn , toks ) : <EOL> if col ( locn , strg ) != n : <EOL> raise ParseException ( strg , locn , "<STR_LIT>" % n ) <EOL> return verifyCol <EOL> def replaceWith ( replStr ) : <EOL> """<STR_LIT>""" <EOL> def _replFunc ( * args ) : <EOL> return [ replStr ] <EOL> return _replFunc <EOL> def removeQuotes ( s , l , t ) : <EOL> """<STR_LIT>""" <EOL> return t [ <NUM_LIT:0> ] [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> def upcaseTokens ( s , l , t ) : <EOL> """<STR_LIT>""" <EOL> return [ tt . upper ( ) for tt in map ( _ustr , t ) ] <EOL> def downcaseTokens ( s , l , t ) : <EOL> """<STR_LIT>""" <EOL> return [ tt . lower ( ) for tt in map ( _ustr , t ) ] <EOL> def keepOriginalText ( s , startLoc , t ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> endloc = getTokensEndLoc ( ) <EOL> except ParseException : <EOL> raise ParseFatalException ( "<STR_LIT>" ) <EOL> del t [ : ] <EOL> t += ParseResults ( s [ startLoc : endloc ] ) <EOL> return t <EOL> def getTokensEndLoc ( ) : <EOL> """<STR_LIT>""" <EOL> import inspect <EOL> fstack = inspect . stack ( ) <EOL> try : <EOL> for f in fstack [ <NUM_LIT:2> : ] : <EOL> if f [ <NUM_LIT:3> ] == "<STR_LIT>" : <EOL> endloc = f [ <NUM_LIT:0> ] . f_locals [ "<STR_LIT>" ] <EOL> return endloc <EOL> else : <EOL> raise ParseFatalException ( "<STR_LIT>" ) <EOL> finally : <EOL> del fstack <EOL> def _makeTags ( tagStr , xml ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( tagStr , basestring ) : <EOL> resname = tagStr <EOL> tagStr = Keyword ( tagStr , caseless = not xml ) <EOL> else : <EOL> resname = tagStr . name <EOL> tagAttrName = Word ( alphas , alphanums + "<STR_LIT>" ) <EOL> if ( xml ) : <EOL> tagAttrValue = dblQuotedString . copy ( ) . setParseAction ( removeQuotes ) <EOL> openTag = Suppress ( "<STR_LIT:<>" ) + tagStr ( "<STR_LIT>" ) + Dict ( ZeroOrMore ( Group ( tagAttrName + Suppress ( "<STR_LIT:=>" ) + tagAttrValue ) ) ) + Optional ( "<STR_LIT:/>" , default = [ False ] ) . setResultsName ( "<STR_LIT>" ) . setParseAction ( lambda s , l , t : t [ <NUM_LIT:0> ] == '<STR_LIT:/>' ) + Suppress ( "<STR_LIT:>>" ) <EOL> else : <EOL> printablesLessRAbrack = "<STR_LIT>" . join ( c for c in printables if c not in "<STR_LIT:>>" ) <EOL> tagAttrValue = quotedString . copy ( ) . setParseAction ( removeQuotes ) | Word ( printablesLessRAbrack ) <EOL> openTag = Suppress ( "<STR_LIT:<>" ) + tagStr ( "<STR_LIT>" ) + Dict ( ZeroOrMore ( Group ( tagAttrName . setParseAction ( downcaseTokens ) + Optional ( Suppress ( "<STR_LIT:=>" ) + tagAttrValue ) ) ) ) + Optional ( "<STR_LIT:/>" , default = [ False ] ) . setResultsName ( "<STR_LIT>" ) . setParseAction ( lambda s , l , t : t [ <NUM_LIT:0> ] == '<STR_LIT:/>' ) + Suppress ( "<STR_LIT:>>" ) <EOL> closeTag = Combine ( _L ( "<STR_LIT>" ) + tagStr + "<STR_LIT:>>" ) <EOL> openTag = openTag . setResultsName ( "<STR_LIT:start>" + "<STR_LIT>" . join ( resname . replace ( "<STR_LIT::>" , "<STR_LIT:U+0020>" ) . title ( ) . split ( ) ) ) . setName ( "<STR_LIT>" % tagStr ) <EOL> closeTag = closeTag . setResultsName ( "<STR_LIT:end>" + "<STR_LIT>" . join ( resname . replace ( "<STR_LIT::>" , "<STR_LIT:U+0020>" ) . title ( ) . split ( ) ) ) . setName ( "<STR_LIT>" % tagStr ) <EOL> openTag . tag = resname <EOL> closeTag . tag = resname <EOL> return openTag , closeTag <EOL> def makeHTMLTags ( tagStr ) : <EOL> """<STR_LIT>""" <EOL> return _makeTags ( tagStr , False ) <EOL> def makeXMLTags ( tagStr ) : <EOL> """<STR_LIT>""" <EOL> return _makeTags ( tagStr , True ) <EOL> def withAttribute ( * args , ** attrDict ) : <EOL> """<STR_LIT>""" <EOL> if args : <EOL> attrs = args [ : ] <EOL> else : <EOL> attrs = attrDict . items ( ) <EOL> attrs = [ ( k , v ) for k , v in attrs ] <EOL> def pa ( s , l , tokens ) : <EOL> for attrName , attrValue in attrs : <EOL> if attrName not in tokens : <EOL> raise ParseException ( s , l , "<STR_LIT>" + attrName ) <EOL> if attrValue != withAttribute . ANY_VALUE and tokens [ attrName ] != attrValue : <EOL> raise ParseException ( s , l , "<STR_LIT>" % <EOL> ( attrName , tokens [ attrName ] , attrValue ) ) <EOL> return pa <EOL> withAttribute . ANY_VALUE = object ( ) <EOL> opAssoc = _Constants ( ) <EOL> opAssoc . LEFT = object ( ) <EOL> opAssoc . RIGHT = object ( ) <EOL> def infixNotation ( baseExpr , opList , lpar = Suppress ( '<STR_LIT:(>' ) , rpar = Suppress ( '<STR_LIT:)>' ) ) : <EOL> """<STR_LIT>""" <EOL> ret = Forward ( ) <EOL> lastExpr = baseExpr | ( lpar + ret + rpar ) <EOL> for i , operDef in enumerate ( opList ) : <EOL> opExpr , arity , rightLeftAssoc , pa = ( operDef + ( None , ) ) [ : <NUM_LIT:4> ] <EOL> if arity == <NUM_LIT:3> : <EOL> if opExpr is None or len ( opExpr ) != <NUM_LIT:2> : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> opExpr1 , opExpr2 = opExpr <EOL> thisExpr = Forward ( ) <EOL> if rightLeftAssoc == opAssoc . LEFT : <EOL> if arity == <NUM_LIT:1> : <EOL> matchExpr = FollowedBy ( lastExpr + opExpr ) + Group ( lastExpr + OneOrMore ( opExpr ) ) <EOL> elif arity == <NUM_LIT:2> : <EOL> if opExpr is not None : <EOL> matchExpr = FollowedBy ( lastExpr + opExpr + lastExpr ) + Group ( lastExpr + OneOrMore ( opExpr + lastExpr ) ) <EOL> else : <EOL> matchExpr = FollowedBy ( lastExpr + lastExpr ) + Group ( lastExpr + OneOrMore ( lastExpr ) ) <EOL> elif arity == <NUM_LIT:3> : <EOL> matchExpr = FollowedBy ( lastExpr + opExpr1 + lastExpr + opExpr2 + lastExpr ) + Group ( lastExpr + opExpr1 + lastExpr + opExpr2 + lastExpr ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> elif rightLeftAssoc == opAssoc . RIGHT : <EOL> if arity == <NUM_LIT:1> : <EOL> if not isinstance ( opExpr , Optional ) : <EOL> opExpr = Optional ( opExpr ) <EOL> matchExpr = FollowedBy ( opExpr . expr + thisExpr ) + Group ( opExpr + thisExpr ) <EOL> elif arity == <NUM_LIT:2> : <EOL> if opExpr is not None : <EOL> matchExpr = FollowedBy ( lastExpr + opExpr + thisExpr ) + Group ( lastExpr + OneOrMore ( opExpr + thisExpr ) ) <EOL> else : <EOL> matchExpr = FollowedBy ( lastExpr + thisExpr ) + Group ( lastExpr + OneOrMore ( thisExpr ) ) <EOL> elif arity == <NUM_LIT:3> : <EOL> matchExpr = FollowedBy ( lastExpr + opExpr1 + thisExpr + opExpr2 + thisExpr ) + Group ( lastExpr + opExpr1 + thisExpr + opExpr2 + thisExpr ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if pa : <EOL> matchExpr . setParseAction ( pa ) <EOL> thisExpr <<= ( matchExpr | lastExpr ) <EOL> lastExpr = thisExpr <EOL> ret <<= lastExpr <EOL> return ret <EOL> operatorPrecedence = infixNotation <EOL> dblQuotedString = Regex ( r'<STR_LIT>' ) . setName ( "<STR_LIT>" ) <EOL> sglQuotedString = Regex ( r"<STR_LIT>" ) . setName ( "<STR_LIT>" ) <EOL> quotedString = Regex ( r'''<STR_LIT>''' ) . setName ( "<STR_LIT>" ) <EOL> unicodeString = Combine ( _L ( '<STR_LIT:u>' ) + quotedString . copy ( ) ) <EOL> def nestedExpr ( opener = "<STR_LIT:(>" , closer = "<STR_LIT:)>" , content = None , ignoreExpr = quotedString . copy ( ) ) : <EOL> """<STR_LIT>""" <EOL> if opener == closer : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if content is None : <EOL> if isinstance ( opener , basestring ) and isinstance ( closer , basestring ) : <EOL> if len ( opener ) == <NUM_LIT:1> and len ( closer ) == <NUM_LIT:1> : <EOL> if ignoreExpr is not None : <EOL> content = ( Combine ( OneOrMore ( ~ ignoreExpr + <EOL> CharsNotIn ( opener + closer + ParserElement . DEFAULT_WHITE_CHARS , exact = <NUM_LIT:1> ) ) <EOL> ) . setParseAction ( lambda t : t [ <NUM_LIT:0> ] . strip ( ) ) ) <EOL> else : <EOL> content = ( empty . copy ( ) + CharsNotIn ( opener + closer + ParserElement . DEFAULT_WHITE_CHARS <EOL> ) . setParseAction ( lambda t : t [ <NUM_LIT:0> ] . strip ( ) ) ) <EOL> else : <EOL> if ignoreExpr is not None : <EOL> content = ( Combine ( OneOrMore ( ~ ignoreExpr + <EOL> ~ Literal ( opener ) + ~ Literal ( closer ) + <EOL> CharsNotIn ( ParserElement . DEFAULT_WHITE_CHARS , exact = <NUM_LIT:1> ) ) <EOL> ) . setParseAction ( lambda t : t [ <NUM_LIT:0> ] . strip ( ) ) ) <EOL> else : <EOL> content = ( Combine ( OneOrMore ( ~ Literal ( opener ) + ~ Literal ( closer ) + <EOL> CharsNotIn ( ParserElement . DEFAULT_WHITE_CHARS , exact = <NUM_LIT:1> ) ) <EOL> ) . setParseAction ( lambda t : t [ <NUM_LIT:0> ] . strip ( ) ) ) <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> ret = Forward ( ) <EOL> if ignoreExpr is not None : <EOL> ret <<= Group ( Suppress ( opener ) + ZeroOrMore ( ignoreExpr | ret | content ) + Suppress ( closer ) ) <EOL> else : <EOL> ret <<= Group ( Suppress ( opener ) + ZeroOrMore ( ret | content ) + Suppress ( closer ) ) <EOL> return ret <EOL> def indentedBlock ( blockStatementExpr , indentStack , indent = True ) : <EOL> """<STR_LIT>""" <EOL> def checkPeerIndent ( s , l , t ) : <EOL> if l >= len ( s ) : return <EOL> curCol = col ( l , s ) <EOL> if curCol != indentStack [ - <NUM_LIT:1> ] : <EOL> if curCol > indentStack [ - <NUM_LIT:1> ] : <EOL> raise ParseFatalException ( s , l , "<STR_LIT>" ) <EOL> raise ParseException ( s , l , "<STR_LIT>" ) <EOL> def checkSubIndent ( s , l , t ) : <EOL> curCol = col ( l , s ) <EOL> if curCol > indentStack [ - <NUM_LIT:1> ] : <EOL> indentStack . append ( curCol ) <EOL> else : <EOL> raise ParseException ( s , l , "<STR_LIT>" ) <EOL> def checkUnindent ( s , l , t ) : <EOL> if l >= len ( s ) : return <EOL> curCol = col ( l , s ) <EOL> if not ( indentStack and curCol < indentStack [ - <NUM_LIT:1> ] and curCol <= indentStack [ - <NUM_LIT:2> ] ) : <EOL> raise ParseException ( s , l , "<STR_LIT>" ) <EOL> indentStack . pop ( ) <EOL> NL = OneOrMore ( LineEnd ( ) . setWhitespaceChars ( "<STR_LIT>" ) . suppress ( ) ) <EOL> INDENT = Empty ( ) + Empty ( ) . setParseAction ( checkSubIndent ) <EOL> PEER = Empty ( ) . setParseAction ( checkPeerIndent ) <EOL> UNDENT = Empty ( ) . setParseAction ( checkUnindent ) <EOL> if indent : <EOL> smExpr = Group ( Optional ( NL ) + <EOL> INDENT + ( OneOrMore ( PEER + Group ( blockStatementExpr ) + Optional ( NL ) ) ) + UNDENT ) <EOL> else : <EOL> smExpr = Group ( Optional ( NL ) + <EOL> ( OneOrMore ( PEER + Group ( blockStatementExpr ) + Optional ( NL ) ) ) ) <EOL> blockStatementExpr . ignore ( _bslash + LineEnd ( ) ) <EOL> return smExpr <EOL> alphas8bit = srange ( r"<STR_LIT>" ) <EOL> punc8bit = srange ( r"<STR_LIT>" ) <EOL> anyOpenTag , anyCloseTag = makeHTMLTags ( Word ( alphas , alphanums + "<STR_LIT>" ) ) <EOL> commonHTMLEntity = Combine ( _L ( "<STR_LIT:&>" ) + oneOf ( "<STR_LIT>" ) . setResultsName ( "<STR_LIT>" ) + "<STR_LIT:;>" ) . streamline ( ) <EOL> _htmlEntityMap = dict ( zip ( "<STR_LIT>" . split ( ) , '<STR_LIT>' ) ) <EOL> replaceHTMLEntity = lambda t : t . entity in _htmlEntityMap and _htmlEntityMap [ t . entity ] or None <EOL> cStyleComment = Regex ( r"<STR_LIT>" ) . setName ( "<STR_LIT>" ) <EOL> htmlComment = Regex ( r"<STR_LIT>" ) <EOL> restOfLine = Regex ( r"<STR_LIT>" ) . leaveWhitespace ( ) <EOL> dblSlashComment = Regex ( r"<STR_LIT>" ) . setName ( "<STR_LIT>" ) <EOL> cppStyleComment = Regex ( r"<STR_LIT>" ) . setName ( "<STR_LIT>" ) <EOL> javaStyleComment = cppStyleComment <EOL> pythonStyleComment = Regex ( r"<STR_LIT>" ) . setName ( "<STR_LIT>" ) <EOL> _commasepitem = Combine ( OneOrMore ( Word ( printables , excludeChars = '<STR_LIT:U+002C>' ) + <EOL> Optional ( Word ( "<STR_LIT>" ) + <EOL> ~ Literal ( "<STR_LIT:U+002C>" ) + ~ LineEnd ( ) ) ) ) . streamline ( ) . setName ( "<STR_LIT>" ) <EOL> commaSeparatedList = delimitedList ( Optional ( quotedString . copy ( ) | _commasepitem , default = "<STR_LIT>" ) ) . setName ( "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> def test ( teststring ) : <EOL> try : <EOL> tokens = simpleSQL . parseString ( teststring ) <EOL> tokenlist = tokens . asList ( ) <EOL> print ( teststring + "<STR_LIT>" + str ( tokenlist ) ) <EOL> print ( "<STR_LIT>" + str ( tokens ) ) <EOL> print ( "<STR_LIT>" + str ( tokens . columns ) ) <EOL> print ( "<STR_LIT>" + str ( tokens . tables ) ) <EOL> print ( tokens . asXML ( "<STR_LIT>" , True ) ) <EOL> except ParseBaseException as err : <EOL> print ( teststring + "<STR_LIT>" ) <EOL> print ( err . line ) <EOL> print ( "<STR_LIT:U+0020>" * ( err . column - <NUM_LIT:1> ) + "<STR_LIT>" ) <EOL> print ( err ) <EOL> print ( ) <EOL> selectToken = CaselessLiteral ( "<STR_LIT>" ) <EOL> fromToken = CaselessLiteral ( "<STR_LIT>" ) <EOL> ident = Word ( alphas , alphanums + "<STR_LIT>" ) <EOL> columnName = delimitedList ( ident , "<STR_LIT:.>" , combine = True ) . setParseAction ( upcaseTokens ) <EOL> columnNameList = Group ( delimitedList ( columnName ) ) <EOL> tableName = delimitedList ( ident , "<STR_LIT:.>" , combine = True ) . setParseAction ( upcaseTokens ) <EOL> tableNameList = Group ( delimitedList ( tableName ) ) <EOL> simpleSQL = ( selectToken + ( '<STR_LIT:*>' | columnNameList ) . setResultsName ( "<STR_LIT>" ) + fromToken + tableNameList . setResultsName ( "<STR_LIT>" ) ) <EOL> test ( "<STR_LIT>" ) <EOL> test ( "<STR_LIT>" ) <EOL> test ( "<STR_LIT>" ) <EOL> test ( "<STR_LIT>" ) <EOL> test ( "<STR_LIT>" ) <EOL> test ( "<STR_LIT>" ) <EOL> test ( "<STR_LIT>" ) <EOL> test ( "<STR_LIT>" ) <EOL> test ( "<STR_LIT>" ) <EOL> test ( "<STR_LIT>" ) <EOL> test ( "<STR_LIT>" ) </s>
