Exemplo n.º 1
0
 def test_if_expression(self):
     self.check_parser('if  %s then  %s else  %s' % ((DATE_STR,) * 3),
                       AST.If(*(DATE_AST,) * 3))
     self.check_parser(IF_STR,
                       IF_AST)
Exemplo n.º 2
0
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)

FOR_STR = 'for  ala  in  %s  return  %s' % (IF_STR, QUANTIFIED_STR)
FOR_AST = AST.For([(AST.Name('ala'), IF_AST)], QUANTIFIED_AST)

PATH_STR = '%s.ala' % DATE_STR
PATH_AST = AST.Path(DATE_AST, AST.Name('ala'))

INVOCATION_STR = '%s(%s, %s)' % (PATH_STR, FOR_STR, IF_STR)
INVOCATION_AST = AST.Invocation(PATH_AST, [FOR_AST, IF_AST])

NEGATION_STR = '-?A_zÊÝĄͼൺ⁶Ⰲ〠邏2𐎅'
NEGATION_AST = AST.Negation(AST.Name('?A_zÊÝĄͼൺ⁶Ⰲ〠邏2𐎅'))

ARITHMETIC_EXPRESSION_STR = '1.2-%s  /true  **%s' % (NEGATION_STR, NAME_STR)
ARITHMETIC_EXPRESSION_AST = AST.Dif(AST.Number(1.2), AST.Div(NEGATION_AST, AST.Exp(AST.Boolean(True), NAME_AST)))
Exemplo n.º 3
0
 def p_missing_then_error(self, p):
     """missing_then_error : IF expression error ELSE"""
     missing_token_error("missing 'then' branch in 'if' expression", p[3], self.logger)
     self.parser.errok()
     p[0] = AST.If(p[2], AST.Null(), AST.Null())
Exemplo n.º 4
0
 def p_missing_else_error(self, p):
     """missing_else_error : IF expression THEN expression error"""
     missing_token_error("missing 'else' branch in 'if' expression", p[5], self.logger)
     self.parser.errok()
     p[0] = AST.If(p[2], p[4], AST.Null())
Exemplo n.º 5
0
 def p_valid_if(self, p):
     """valid_if : IF expression THEN expression ELSE expression %prec if_p"""
     p[0] = AST.If(p[2], p[4], p[6])