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
A new instance of ParserScope.
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
#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
15 16 17 |
# File 'opal/lib/opal/parser/parser_scope.rb', line 15 def add_local(local) @locals << local end |
#has_local?(local) ⇒ 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 |