Class: Opal::ParserScope
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
-
#locals ⇒ Object
readonly
Returns the value of attribute locals.
-
#parent ⇒ Object
Returns the value of attribute parent.
Instance Method Summary collapse
- #add_local(local) ⇒ Object
- #has_local?(local) ⇒ Boolean
-
#initialize(type) ⇒ ParserScope
constructor
Create new parse scope.
Constructor Details
#initialize(type) ⇒ ParserScope
Create new parse scope. Valid types are :block, :class, :module, :def.
12 13 14 15 16 |
# File 'opal/lib/opal/parser/parser_scope.rb', line 12 def initialize(type) @block = type == :block @locals = [] @parent = nil end |
Instance Attribute Details
#locals ⇒ Object (readonly)
Returns the value of attribute locals
6 7 8 |
# File 'opal/lib/opal/parser/parser_scope.rb', line 6 def locals @locals end |
#parent ⇒ Object
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
18 19 20 |
# File 'opal/lib/opal/parser/parser_scope.rb', line 18 def add_local(local) @locals << local end |
#has_local?(local) ⇒ Boolean
22 23 24 25 26 |
# File 'opal/lib/opal/parser/parser_scope.rb', line 22 def has_local?(local) return true if @locals.include? local return @parent.has_local?(local) if @parent and @block false end |