<s> from distutils . version import StrictVersion <EOL> from pyparsing import ( <EOL> ParserElement , Forward , Combine , Optional , Word , Literal , CaselessKeyword , <EOL> CaselessLiteral , Group , FollowedBy , LineEnd , OneOrMore , ZeroOrMore , <EOL> nums , alphas , alphanums , printables , delimitedList , quotedString , <EOL> __version__ <EOL> ) <EOL> ParserElement . enablePackrat ( ) <EOL> grammar = Forward ( ) <EOL> expression = Forward ( ) <EOL> intNumber = Combine ( <EOL> Optional ( '<STR_LIT:->' ) + Word ( nums ) <EOL> ) ( '<STR_LIT>' ) <EOL> floatNumber = Combine ( <EOL> Optional ( '<STR_LIT:->' ) + Word ( nums ) + Literal ( '<STR_LIT:.>' ) + Word ( nums ) <EOL> ) ( '<STR_LIT:float>' ) <EOL> sciNumber = Combine ( <EOL> ( floatNumber | intNumber ) + CaselessLiteral ( '<STR_LIT:e>' ) + intNumber <EOL> ) ( '<STR_LIT>' ) <EOL> aString = quotedString ( '<STR_LIT:string>' ) <EOL> afterNumber = FollowedBy ( "<STR_LIT:U+002C>" ) ^ FollowedBy ( "<STR_LIT:)>" ) ^ FollowedBy ( LineEnd ( ) ) <EOL> number = Group ( <EOL> ( sciNumber + afterNumber ) | <EOL> ( floatNumber + afterNumber ) | <EOL> ( intNumber + afterNumber ) <EOL> ) ( '<STR_LIT>' ) <EOL> boolean = Group ( <EOL> CaselessKeyword ( "<STR_LIT:true>" ) | <EOL> CaselessKeyword ( "<STR_LIT:false>" ) <EOL> ) ( '<STR_LIT>' ) <EOL> argname = Word ( alphas + '<STR_LIT:_>' , alphanums + '<STR_LIT:_>' ) ( '<STR_LIT>' ) <EOL> funcname = Word ( alphas + '<STR_LIT:_>' , alphanums + '<STR_LIT:_>' ) ( '<STR_LIT>' ) <EOL> leftParen = Literal ( '<STR_LIT:(>' ) . suppress ( ) <EOL> rightParen = Literal ( '<STR_LIT:)>' ) . suppress ( ) <EOL> comma = Literal ( '<STR_LIT:U+002C>' ) . suppress ( ) <EOL> equal = Literal ( '<STR_LIT:=>' ) . suppress ( ) <EOL> leftBrace = Literal ( '<STR_LIT:{>' ) <EOL> rightBrace = Literal ( '<STR_LIT:}>' ) <EOL> leftParen = Literal ( '<STR_LIT:(>' ) . suppress ( ) <EOL> rightParen = Literal ( '<STR_LIT:)>' ) . suppress ( ) <EOL> comma = Literal ( '<STR_LIT:U+002C>' ) . suppress ( ) <EOL> equal = Literal ( '<STR_LIT:=>' ) . suppress ( ) <EOL> backslash = Literal ( '<STR_LIT:\\>' ) . suppress ( ) <EOL> symbols = '''<STR_LIT>''' <EOL> arg = Group ( <EOL> boolean | <EOL> number | <EOL> aString | <EOL> expression <EOL> ) ( '<STR_LIT>' ) <EOL> kwarg = Group ( argname + equal + arg ) ( '<STR_LIT>' ) <EOL> args = delimitedList ( ~ kwarg + arg ) <EOL> kwargs = delimitedList ( kwarg ) <EOL> call = Group ( <EOL> funcname + leftParen + <EOL> Optional ( <EOL> args + Optional ( <EOL> comma + kwargs <EOL> ) <EOL> ) + rightParen <EOL> ) ( '<STR_LIT>' ) <EOL> validMetricChars = '<STR_LIT>' . join ( ( set ( printables ) - set ( symbols ) ) ) <EOL> escapedChar = backslash + Word ( symbols , exact = <NUM_LIT:1> ) <EOL> partialPathElem = Combine ( <EOL> OneOrMore ( <EOL> escapedChar | Word ( validMetricChars ) <EOL> ) <EOL> ) <EOL> matchEnum = Combine ( <EOL> leftBrace + <EOL> delimitedList ( partialPathElem , combine = True ) + <EOL> rightBrace <EOL> ) <EOL> pathElement = Combine ( <EOL> Group ( partialPathElem | matchEnum ) + <EOL> ZeroOrMore ( matchEnum | partialPathElem ) <EOL> ) <EOL> pathExpression = delimitedList ( pathElement , <EOL> delim = '<STR_LIT:.>' , combine = True ) ( '<STR_LIT>' ) <EOL> if StrictVersion ( __version__ ) >= StrictVersion ( '<STR_LIT>' ) : <EOL> expression <<= Group ( call | pathExpression ) ( '<STR_LIT>' ) <EOL> grammar <<= expression <EOL> else : <EOL> expression << ( Group ( call | pathExpression ) ( '<STR_LIT>' ) ) <EOL> grammar << expression </s>
