Sha256: 71989117a4fd6dce5278a8c181b1164b38923c2692ec139711d12d9ea76e4823

Contents?: true

Size: 1.33 KB

Versions: 2

Compression:

Stored size: 1.33 KB

Contents

module Minjs::Lex
  #
  # 14 Program
  #
  module Program
    include Minjs

    # Tests next literals sequence is Program or not.
    #
    # If sequence is Program
    # return ECMA262::Prog object and
    # forward lexical parser position.
    # Otherwise return nil and position is not changed.
    #
    # @return [ECMA262::Prog] element
    #
    # @see http://www.ecma-international.org/ecma-262 ECMA262 14
    def program(var_env)
      prog = source_elements(var_env)
      if eof?
        return prog
      else
        raise ParseError.new("unexpceted token", self)
      end
    end

    # Tests next literals sequence is SourceElements or not.
    #
    # If sequence is SourceElements
    # return ECMA262::SourceElements object and
    # forward lexical parser position.
    # Otherwise return nil and position is not changed.
    #
    # @return [ECMA262::SourceElements] element
    #
    # @see http://www.ecma-international.org/ecma-262 ECMA262 14
    def source_elements(var_env)
      prog = []
      while t = source_element(var_env)
        prog.push(t)
      end
      ECMA262::Prog.new(var_env, ECMA262::SourceElements.new(prog))
    end

    def source_element(var_env)
      #eval_lit{
      statement(var_env)
      #} or eval_lit{ => statement
      #  func_declaration(var_env)
      #}
    end

    private :source_element
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
minjs-0.4.2 lib/minjs/lex/program.rb
minjs-0.4.1 lib/minjs/lex/program.rb