lib/minjs/statement.rb in minjs-0.1.2 vs lib/minjs/statement.rb in minjs-0.1.3

- old
+ new

@@ -66,18 +66,11 @@ end lex.eval_lit { if s = statement_list(lex, context) and lex.match_lit(ECMA262::PUNC_RCURLYBRAC) ECMA262::StBlock.new(s) else - if s - lex.debug_lit - puts lex.debug_code(pos0, lex.pos) - raise 'no "}" end of block' - else - lex.debug_lit - raise "bad block" - end + raise ParseError.new('no "}" end of block', lex) end } end def statement_list(lex, context) @@ -96,11 +89,11 @@ # #12.2 # variable_statement # def var_statement(lex, context) - raise 'error' if context.nil? + raise 'internal error' if context.nil? return nil unless lex.match_lit(ECMA262::ID_VAR) lex.eval_lit { if vl = var_decl_list(lex, context, {}) and semicolon(lex, context) #10.5 vl.each do |v| @@ -109,11 +102,11 @@ context.var_env.record.set_mutable_binding(dn, :undefined, nil) end ECMA262::StVar.new(context, vl) else lex.debug_lit - raise Minjs::ParseError.new("var_statement") + raise Minjs::ParseError.new("var_statement", lex) end } end def var_decl_list(lex, context, options) @@ -183,13 +176,14 @@ end # #12.5 # def if_statement(lex, context) + return nil unless lex.match_lit(ECMA262::ID_IF) lex.eval_lit { - unless lex.match_lit(ECMA262::ID_IF) and lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and cond=exp(lex, context, {}) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and s=statement(lex, context) - next nil + unless lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and cond=exp(lex, context, {}) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and s=statement(lex, context) + raise ParseError.new("bad statement", lex) end if lex.match_lit(ECMA262::ID_ELSE) and e=statement(lex, context) ECMA262::StIf.new(cond, s, e) else ECMA262::StIf.new(cond, s, nil) @@ -207,21 +201,21 @@ return nil unless lex.match_lit(ECMA262::ID_WHILE) if lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and e=exp(lex, context, {}) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and s=statement(lex, context) ECMA262::StWhile.new(e, s) else lex.debug_lit - raise ParseError.new("while_statement") + raise ParseError.new("while_statement", lex) end end def do_while_statement(lex, context) return nil unless lex.match_lit(ECMA262::ID_DO) if s=statement(lex, context) and lex.match_lit(ECMA262::ID_WHILE) and lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and e=exp(lex, context, {}) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and semicolon(lex, context) ECMA262::StDoWhile.new(e, s) else lex.debug_lit - raise ParseError.new("do_while_statement") + raise ParseError.new("do_while_statement", lex) end end def for_statement(lex, context) return nil unless lex.match_lit(ECMA262::ID_FOR) @@ -322,11 +316,11 @@ lex.eval_lit { if lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and e=exp(lex, context, {}) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and s=statement(lex, context) ECMA262::StWith.new(e, s) else lex.debug_lit - raise ParseError.new("switch_statement") + raise ParseError.new("switch_statement", lex) end } end # # 12.11 @@ -336,11 +330,11 @@ lex.eval_lit { if lex.match_lit(ECMA262::PUNC_LPARENTHESIS) and e=exp(lex, context, {}) and lex.match_lit(ECMA262::PUNC_RPARENTHESIS) and c = case_block(lex, context) ECMA262::StSwitch.new(e, c) else lex.debug_lit - raise ParseError.new("switch_statement") + raise ParseError.new("switch_statement", lex) end } end def case_block(lex, context) @@ -382,10 +376,10 @@ lex.eval_lit{ if e=exp(lex, context, {}) and semicolon(lex, context) ECMA262::StThrow.new(e) else lex.debug_lit - raise ParseError.new("throw_statement") + raise ParseError.new("throw_statement", lex) end } end # # 12.14