Sha256: 3496c5b84b5c3cee01635153c718482775774154154631c2ae11aa4a05e50dfe

Contents?: true

Size: 625 Bytes

Versions: 13

Compression:

Stored size: 625 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

    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

13 entries across 13 versions & 2 rubygems

Version Path
opal-0.7.0.beta3 lib/opal/parser/parser_scope.rb
opal-0.6.3 lib/opal/parser/parser_scope.rb
opal-0.7.0.beta2 lib/opal/parser/parser_scope.rb
opal-cj-0.7.0.beta2 lib/opal/parser/parser_scope.rb
opal-cj-0.7.0.beta1 lib/opal/parser/parser_scope.rb
opal-0.7.0.beta1 lib/opal/parser/parser_scope.rb
opal-0.6.2 lib/opal/parser/parser_scope.rb
opal-0.6.1 lib/opal/parser/parser_scope.rb
opal-0.6.0 lib/opal/parser/parser_scope.rb
opal-0.5.5 lib/opal/parser/parser_scope.rb
opal-0.5.4 lib/opal/parser/parser_scope.rb
opal-0.5.2 lib/opal/parser/parser_scope.rb
opal-0.5.0 lib/opal/parser/parser_scope.rb