lib/minjs/expression.rb in minjs-0.1.2 vs lib/minjs/expression.rb in minjs-0.1.3
- old
+ new
@@ -17,11 +17,11 @@
if lex.match_lit(ECMA262::PUNC_LPARENTHESIS)
if a=exp(lex, context, options) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS)
STDERR.puts "*** primary_exp => ()" if @debug
return ECMA262::ExpParen.new(a)
else
- raise 'error'
+ raise ParseError.new("no `)' at end of expression", lex)
end
end
# identifier || literal || array_literal || object_literal
t = lex.eval_lit {
@@ -101,22 +101,21 @@
while !lex.eof?
if lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
break
end
lex.eval_lit{
+ if lex.match_lit(ECMA262::ID_GET) and a=property_name(lex, context) and lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and lex.match_lit(ECMA262::PUNC_LCURLYBRAC) and b=func_body(lex, context) and lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
+ h.push([a, ECMA262::StFunc.new(context, ECMA262::ID_GET, [], b, :getter => true)])
+ elsif lex.match_lit(ECMA262::ID_SET) and a=property_name(lex, context) and lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and arg=property_set_parameter_list(lex, context) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and lex.match_lit(ECMA262::PUNC_LCURLYBRAC) and b=func_body(lex, context) and lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
+ h.push([a, ECMA262::StFunc.new(context, ECMA262::ID_SET, arg, b, :setter => true)])
+ else
+ nil
+ end
+ } or lex.eval_lit{
a=property_name(lex, context) and lex.match_lit(ECMA262::PUNC_COLON) and b=assignment_exp(lex, context, options)
h.push([a, b])
}
-# or lex.eval_lit{
-# if lex.match_lit(ECMA262::ID_GET) and a=property_name(lex, context) and lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and lex.match_lit(ECMA262::PUNC_LCURLYBRAC) and func_body(lex, context) and lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
-# h[a] = "getter" #TODO
-# elsif lex.match_lit(ECMA262::ID_SET) and a=property_name(lex, context) and lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and property_set_parameter_list(lex, context) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and lex.match_lit(ECMA262::PUNC_LCURLYBRAC) and func_body(lex, context) and lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
-# h[a] = "setter" #TODO
-# else
-# return nil
-# end
-# }
if lex.match_lit(ECMA262::PUNC_COMMA)
break if lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
elsif lex.match_lit(ECMA262::PUNC_RCURLYBRAC)
break
@@ -136,20 +135,20 @@
elsif a.kind_of?(ECMA262::IdentifierName)
ECMA262::ECMA262String.new(a.to_js)
elsif a.kind_of?(ECMA262::ECMA262Numeric)
a
else
- raise ParseError.new("The Property name must be kind_of ItentiferName or String", lex)
+ nil
end
}
end
def property_set_parameter_list(lex, context)
lex.eval_lit {
a = lex.fwd_lit
if a.kind_of?(ECMA262::IdentifierName) and !a.reserved?
- a
+ [a]
else
nil
end
}
end
@@ -290,16 +289,15 @@
#
def postfix_exp(lex, context, options)
STDERR.puts "*** postfix_exp" if @debug
lex.debug_lit if @debug
- next_exp = :left_hand_side_exp
t = lex.eval_lit{
- a = __send__(next_exp, lex, context, options)
+ a = left_hand_side_exp(lex, context, options)
return nil if a.nil?
- if punc = (lex.match_lit(ECMA262::PUNC_INC) ||
- lex.match_lit(ECMA262::PUNC_DEC))
+ if punc = (lex.match_lit(ECMA262::PUNC_INC, :nolt => true) ||
+ lex.match_lit(ECMA262::PUNC_DEC, :nolt => true))
if punc == ECMA262::PUNC_INC
ECMA262::ExpPostInc.new(a)
else
ECMA262::ExpPostDec.new(a)
end
@@ -681,10 +679,10 @@
when ECMA262::PUNC_ORLET
ECMA262::ExpOrAssign.new(left_hand, b)
when ECMA262::PUNC_XORLET
ECMA262::ExpXorAssign.new(left_hand, b)
else
- raise "not implement"
+ raise "internal error"
end
else # some assignment operator presents but no assignment_expression => fail
return nil
end
else