Class: Opal::ParserScope

Inherits:
Object show all
Defined in:
opal/lib/opal/parser/parser_scope.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type) ⇒ ParserScope

Returns a new instance of ParserScope



9
10
11
12
13
# File 'opal/lib/opal/parser/parser_scope.rb', line 9

def initialize(type)
  @block  = type == :block
  @locals = []
  @parent = nil
end

Instance Attribute Details

#localsObject (readonly)

Returns the value of attribute locals



6
7
8
# File 'opal/lib/opal/parser/parser_scope.rb', line 6

def locals
  @locals
end

#parentObject

Returns the value of attribute parent



7
8
9
# File 'opal/lib/opal/parser/parser_scope.rb', line 7

def parent
  @parent
end

Instance Method Details

#add_local(local) ⇒ Object



15
16
17
# File 'opal/lib/opal/parser/parser_scope.rb', line 15

def add_local(local)
  @locals << local
end

#has_local?(local) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
# File 'opal/lib/opal/parser/parser_scope.rb', line 19

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