Esempio n. 1
0
 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')))])))
Esempio n. 2
0
 def p_function_expression(self, p):
     """function_expression : FUNCTION LPAREN formal_parameter_list_opt RPAREN block"""
     p[0] = ast.FunctionDefinition(parameters=p[3], body=p[5])
Esempio n. 3
0
 def p_function_expression_scope(self, p):
     """function_expression_scope : LPAREN formal_parameter_list_opt RPAREN RARROW block"""
     p[0] = ast.FunctionDefinition(parameters=p[2], body=p[5])