Method: Minjs::Lex::Function#func_exp
- Defined in:
- lib/minjs/lex/function.rb
#func_exp(var_env) ⇒ Object
Note:
The function expression and declaration uses same class for convenience.
Tests next literal is FunctionExpression or not.
If literal is FunctionExpression return ECMA262::StFunc object and forward lexical parser position. Otherwise return nil and position is not changed.
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/minjs/lex/function.rb', line 59 def func_exp(var_env) # FunctionExpression : # function Identifieropt ( FormalParameterListopt ) { FunctionBody } return nil if eql_lit?(ECMA262::ID_FUNCTION).nil? @logger.debug "*** func_exp" id_opt = identifier(var_env) new_var_env = ECMA262::LexEnv.new(outer: var_env) if eql_lit?(ECMA262::PUNC_LPARENTHESIS) and args = formal_parameter_list(new_var_env) and eql_lit?(ECMA262::PUNC_RPARENTHESIS) and eql_lit?(ECMA262::PUNC_LCURLYBRAC) and b = func_body(new_var_env) and eql_lit?(ECMA262::PUNC_RCURLYBRAC) f = ECMA262::StFunc.new(new_var_env, id_opt, args, b) #new_var_env.func = f if id_opt var_env.record.create_mutable_binding(id_opt, nil) var_env.record.set_mutable_binding(id_opt, f, nil) end f else if b raise ParseError.new("No `}' at end of function", self) else raise ParseError.new("Bad function expression", self) end end end |