def compBreaker(self, node): assert isinstance(node, Compare) if len(node.comparators) == 1: return node else: comp1 = Compare(node.left, node.ops[0:1], node.comparators[0:1]) comp2 = Compare(node.comparators[0], node.ops[1:], node.comparators[1:]) newNode = BoolOp(And(), [comp1, self.compBreaker(comp2)]) return newNode
def parsePredicate(parser): predicate = None if parser.matchLexeme('!'): parser.next() #skip !. return Not(parsePredicate(parser)) predicate = parseExpression(parser) if parser.matchLexeme("."): # var.type? parser.next("list?, record?, string?", tokensort=KEYWORD) if parser.matchLexeme(keywords['LIST']): ptype = "LIST" if parser.matchLexeme(keywords['RECORD']): ptype = "RECORD" if parser.matchLexeme(keywords['STRING']): ptype = "STRING" parser.next() parser.check('type?', lexeme='?') predicate = Is_a(predicate, ptype, lineo=parser.currentToken[2]) parser.next() if parser.matchLexeme('&') and parser.peek(lexeme='&'): parser.next() #skip && parser.next() right = parsePredicate(parser) #and predicate = And(predicate, right, lineo=parser.currentToken[2]) if parser.matchLexeme('|') and parser.peek(lexeme='|'): parser.next() #skip || parser.next() right = parsePredicate(parser) predicate = Or(predicate, right, lineo=parser.currentToken[2]) #parser.next() if not predicate: raise SyntaxError(currentToken, "pasing predicate failed && || type? variable") return predicate
def _(ra: ras.And, ctx: Context): return ast.BoolOp(op=And(), values=[ convert(ra[0], ctx), convert(ra[1], ctx), ])
def handle_f(self, f): # Do we need to use .attname here? # What about transforms/lookups? f.contains_aggregate = False if "__" in f.name: # We need to chain a bunch of attr lookups, returning None # if any of them give us a None, we should be returning a None. # # . while x is not None and parts: # . x = getattr(x, parts.pop(0), None) # return x return [ Assign(targets=[Name(id="source", **self.file_store)], value=Name(id="self", **self.file), **self.file), Assign( targets=[Name(id="parts", **self.file_store)], value=Call( func=Attribute(value=Constant(value=f.name, **self.file), attr="split", **self.file), args=[Constant(value="__", **self.file)], keywords=[], kwonlyargs=[], **self.file, ), **self.file, ), While( test=BoolOp( op=And(), values=[ Compare( left=Name(id="source", **self.file), ops=[IsNot()], comparators=[ Constant(value=None, **self.file) ], **self.file, ), Name(id="parts", **self.file), ], **self.file, ), body=[ Assign( targets=[Name(id="source", **self.file_store)], value=Call( func=Name(id="getattr", **self.file), args=[ Name(id="source", **self.file), Call( func=Attribute(value=Name(id="parts", **self.file), attr="pop", **self.file), args=[Constant(value=0, **self.file)], keywords=[], kwonlyargs=[], **self.file, ), Constant(value=None, **self.file), ], keywords=[], kwonlyargs=[], **self.file, ), **self.file, ), ], orelse=[], **self.file, ), Return(value=Name(id="source", **self.file), **self.file), ] return Attribute(value=Name(id="self", **self.file), attr=f.name, **self.file)