def test_parse_block(self): self.assertEqual( self.parser.parse('{ 1; 3; }'), ast.Block(statements=[ ast.ExpressionStatement(expression=ast.Literal(value=1)), ast.ExpressionStatement(expression=ast.Literal(value=3)) ]))
def p_block_value(self, p): """block_value : LBRACE statement_list_v_opt RBRACE""" ls=p[2] if len(ls)>0: #print((ls[0])) #print("VDEAL") ls[len(ls)-1]=ast.ReturnStatement(expression=ls[len(ls)-1]) p[0] = ast.Block(statements=ls)
def test_parse_function_expression(self): self.assertEqual(self.parser.parse('function (x, y) { return x + y; }'), ast.FunctionDefinition(parameters=[ast.Identifier(name='x'), ast.Identifier(name='y')], body=ast.Block( statements=[ast.ReturnStatement(expression=ast.BinaryOp(op='+', left_expression=ast.Identifier(name='x'), right_expression=ast.Identifier(name='y')))])))
def p_program(self, p): """program : statement_list_opt""" p[0] = ast.Block(statements=p[1])
def p_block_void(self, p): """block_void : LBRACE statement_list_opt RBRACE""" p[0] = ast.Block(statements=p[2])