lib/minjs/program.rb in minjs-0.2.2 vs lib/minjs/program.rb in minjs-0.3.0

- old
+ new

@@ -1,28 +1,32 @@ module Minjs # # 14 Program # module Program + def program(lex, context) + prog = source_elements(@lex, @global_context) + if lex.eof? + return prog + else + raise ParseError.new("unexpceted token", lex) + end + end + def source_elements(lex, context, options = {}) prog = [] - while !lex.eof? - t = source_element(lex, context) - if t - prog.push(t) - else - break - end + while t = source_element(lex, context) + prog.push(t) end ECMA262::Prog.new(context, ECMA262::SourceElements.new(prog)) end def source_element(lex, context) - lex.eval_lit{ - statement(lex, context) - } or lex.eval_lit{ - func_declaration(lex, context) - } + #lex.eval_lit{ + statement(lex, context) + #} or lex.eval_lit{ => statement + # func_declaration(lex, context) + #} end end end