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) 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('<='))
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))
def p_function_definition(self, p): """function_definition : FUNCTION '(' empty_list ')' external expression %prec function_definition_p | FUNCTION '(' formal_parameters ')' external expression %prec function_definition_p""" p[0] = AST.FunctionDefinition(p[3], p[5], p[6])