NAME_STR = 'ala ma kota' NAME_AST = AST.Name(NAME_STR) CONTEXT_STR = '{%s:%s}' % (NAME_STR, DATE_STR) CONTEXT_AST = AST.Context([(NAME_AST, DATE_AST)]) FUNCTION_STR = 'function()%s' % CONTEXT_STR FUNCTION_AST = AST.FunctionDefinition([], False, CONTEXT_AST) LIST_STR = '[%s, %s]' % (FUNCTION_STR, CONTEXT_STR) LIST_AST = AST.List([FUNCTION_AST, CONTEXT_AST]) INSTANCE_OF_STR = '%s instance of ala.ma.kota' % LIST_STR # INSTANCE_OF_STR = '%s instance of ala.ma.kota' % LIST_STR INSTANCE_OF_AST = AST.InstanceOf(LIST_AST, AST.Type([AST.Name('ala.ma.kota')])) FILTER_EXPRESSION_STR = '%s [%s]' % (LIST_STR, INSTANCE_OF_STR) FILTER_EXPRESSION_AST = AST.FilterExpression(LIST_AST, INSTANCE_OF_AST) CONJUNCTION_STR = '%s and %s' % (operator_str_gen('='), INSTANCE_OF_STR) CONJUNCTION_AST = AST.Conjunction(operator_ast_gen(AST.Eq), INSTANCE_OF_AST) DISJUNCTION_STR = '%s or %s' % (CONJUNCTION_STR, operator_str_gen('<=')) DISJUNCTION_AST = AST.Disjunction(CONJUNCTION_AST, operator_ast_gen(AST.Lte)) QUANTIFIED_STR = 'some ala in %s satisfies %s' % (DISJUNCTION_STR, CONJUNCTION_STR) QUANTIFIED_AST = AST.QuantifiedExpr(True, [(AST.Name('ala'), DISJUNCTION_AST)], CONJUNCTION_AST) IF_STR = 'if %s then %s else %s' % (QUANTIFIED_STR, DISJUNCTION_STR, CONJUNCTION_STR) IF_AST = AST.If(QUANTIFIED_AST, DISJUNCTION_AST, CONJUNCTION_AST)
def test_instance_of(self): self.check_parser('%s instance of a.b.c' % DATE_STR, AST.InstanceOf(DATE_AST, AST.Type([AST.Name('a.b.c')])))
def p_type(self, p): """type : qualified_name""" p[0] = AST.Type(p[1])