Sha256: 12276eaf296aa36772a890453c639c49d5cd5d5734f59538238cab94d693d449

Contents?: true

Size: 746 Bytes

Versions: 34

Compression:

Stored size: 746 Bytes

Contents

module Opal
  # ParserScope is used during lexing to keep track of local variables
  # created inside a scope. A lexer scope can be asked if it has a local
  # variable defined, and it can also check its parent scope if applicable.
  class ParserScope
    attr_reader :locals
    attr_accessor :parent

    # Create new parse scope. Valid types are :block, :class, :module, :def.
    #
    # @param type [Symbol] scope type
    def initialize(type)
      @block  = type == :block
      @locals = []
      @parent = nil
    end

    def add_local(local)
      @locals << local
    end

    def has_local?(local)
      return true if @locals.include? local
      return @parent.has_local?(local) if @parent and @block
      false
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
opal-0.10.6 lib/opal/parser/parser_scope.rb
opal-0.10.6.beta lib/opal/parser/parser_scope.rb
opal-0.10.5 lib/opal/parser/parser_scope.rb
opal-0.10.4 lib/opal/parser/parser_scope.rb
opal-0.10.3 lib/opal/parser/parser_scope.rb
opal-0.10.2 lib/opal/parser/parser_scope.rb
opal-0.10.1 lib/opal/parser/parser_scope.rb
opal-0.10.0 lib/opal/parser/parser_scope.rb
opal-0.10.0.rc2 lib/opal/parser/parser_scope.rb
opal-0.9.4 lib/opal/parser/parser_scope.rb
opal-0.9.3 lib/opal/parser/parser_scope.rb
opal-0.10.0.rc1 lib/opal/parser/parser_scope.rb
opal-0.10.0.beta5 lib/opal/parser/parser_scope.rb
opal-0.10.0.beta4 lib/opal/parser/parser_scope.rb
opal-0.10.0.beta3 lib/opal/parser/parser_scope.rb
opal-0.10.0.beta2 lib/opal/parser/parser_scope.rb
opal-0.10.0.beta1 lib/opal/parser/parser_scope.rb
opal-0.9.2 lib/opal/parser/parser_scope.rb
opal-0.9.0 lib/opal/parser/parser_scope.rb
opal-0.9.0.rc1 lib/opal/parser/parser_scope.rb