def test_quantified_expression(self): self.check_parser(QUANTIFIED_STR, QUANTIFIED_AST) self.check_parser('every ala in %s satisfies %s' % (DISJUNCTION_STR, CONJUNCTION_STR), AST.QuantifiedExpr(False, [(AST.Name('ala'), DISJUNCTION_AST)], CONJUNCTION_AST)) self.check_parser('every ala in %s ola in %s satisfies %s' % (DISJUNCTION_STR, operator_str_gen('!='), CONJUNCTION_STR), AST.QuantifiedExpr(False, [(AST.Name('ala'), DISJUNCTION_AST), (AST.Name('ola'), operator_ast_gen(AST.Neq))], CONJUNCTION_AST))
def check_name(self, name): self.check_parser(name, AST.Name(name))
def test_named_parameters(self): self.check_parser('%s(ala: %s)' % (PATH_STR, INVOCATION_STR), AST.Invocation(PATH_AST, [(AST.Name('ala'), INVOCATION_AST)])) self.check_parser('%s(ala : %s, ola :%s)' % ((DATE_STR,) * 3), AST.Invocation(DATE_AST, [(AST.Name('ala'), DATE_AST), (AST.Name('ola'), DATE_AST)]))
def test_for_expression(self): self.check_parser(FOR_STR, FOR_AST) self.check_parser('for ala in %s ola in %s return %s' % (IF_STR, QUANTIFIED_STR, DISJUNCTION_STR), AST.For([(AST.Name('ala'), IF_AST), (AST.Name('ola'), QUANTIFIED_AST)], DISJUNCTION_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 test_function_definition(self): self.check_parser(FUNCTION_STR, FUNCTION_AST) self.check_parser('function(ola, iza) external %s' % CONTEXT_STR, AST.FunctionDefinition([AST.Name('ola'), AST.Name('iza')], True, CONTEXT_AST)) self.check_parser('function(ola, iza) external %s' % DATE_STR, AST.FunctionDefinition([AST.Name('ola'), AST.Name('iza')], True, DATE_AST))
from utils.StoreLogger import StoreLogger def operator_ast_gen(operator_ast): return operator_ast(FILTER_EXPRESSION_AST, LIST_AST) def operator_str_gen(operator_str): return '%s %s %s' % (FILTER_EXPRESSION_STR, operator_str, LIST_STR) DATE_STR = 'date("1")' DATE_AST = AST.Date('1') 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)
def p_name(self, p): """name : NAME""" p[0] = AST.Name(p[1])