Class: Koto::Parser::AST::Processor::Context

Inherits:
Object
  • Object
show all
Defined in:
lib/koto.rb,
lib/koto/parser/ast/processor/context.rb,
lib/koto/parser/ast/processor/context/symbol_table.rb

Defined Under Namespace

Classes: SymbolTable

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeContext

Returns a new instance of Context.



13
14
15
16
17
18
19
# File 'lib/koto/parser/ast/processor/context.rb', line 13

def initialize
  @scopes  = SpaghettiStack.new(SymbolTable.new)
  @stack   = []
  @access  = :public

  freeze
end

Instance Attribute Details

#accessObject (readonly)

Returns the value of attribute access.



11
12
13
# File 'lib/koto/parser/ast/processor/context.rb', line 11

def access
  @access
end

#scopesObject (readonly)

Returns the value of attribute scopes.



9
10
11
# File 'lib/koto/parser/ast/processor/context.rb', line 9

def scopes
  @scopes
end

#stackObject (readonly)

Returns the value of attribute stack.



10
11
12
# File 'lib/koto/parser/ast/processor/context.rb', line 10

def stack
  @stack
end

Instance Method Details

#active_scopeObject



72
73
74
# File 'lib/koto/parser/ast/processor/context.rb', line 72

def active_scope
  @scopes.top
end

#current_scopeObject



76
77
78
# File 'lib/koto/parser/ast/processor/context.rb', line 76

def current_scope
  @stack.last
end

#get_in(node) ⇒ Object



21
22
23
24
# File 'lib/koto/parser/ast/processor/context.rb', line 21

def get_in(node)
  copy = self.deep_dup
  copy.send :get_in!, node
end

#get_outObject



35
36
37
38
# File 'lib/koto/parser/ast/processor/context.rb', line 35

def get_out
  copy = self.deep_dup
  copy.send :get_out!
end

#in_block?Boolean

Returns:

  • (Boolean)


114
115
116
117
# File 'lib/koto/parser/ast/processor/context.rb', line 114

def in_block?
  return false if top_level?
  current_scope.type == :block
end

#in_class?Boolean

Returns:

  • (Boolean)


94
95
96
97
# File 'lib/koto/parser/ast/processor/context.rb', line 94

def in_class?
  return false if top_level?
  current_scope.type == :class
end

#in_def?Boolean

Returns:

  • (Boolean)


109
110
111
112
# File 'lib/koto/parser/ast/processor/context.rb', line 109

def in_def?
  return false if top_level?
  current_scope.type == :def
end

#in_dynamic_block?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/koto/parser/ast/processor/context.rb', line 124

def in_dynamic_block?
  in_block? || in_lambda?
end

#in_lambda?Boolean

Returns:

  • (Boolean)


119
120
121
122
# File 'lib/koto/parser/ast/processor/context.rb', line 119

def in_lambda?
  return false if top_level?
  current_scope.type == :lambda
end

#in_module?Boolean

Returns:

  • (Boolean)


104
105
106
107
# File 'lib/koto/parser/ast/processor/context.rb', line 104

def in_module?
  return false if top_level?
  current_scope.type == :module
end

#in_sclass?Boolean

Returns:

  • (Boolean)


99
100
101
102
# File 'lib/koto/parser/ast/processor/context.rb', line 99

def in_sclass?
  return false if top_level?
  current_scope.type == :sclass
end

#save(node) ⇒ Object



54
55
56
57
# File 'lib/koto/parser/ast/processor/context.rb', line 54

def save(node)
  copy = self.deep_dup
  copy.send :save!, node
end

#switch_access_to(access) ⇒ Object



80
81
82
83
84
85
86
87
88
# File 'lib/koto/parser/ast/processor/context.rb', line 80

def switch_access_to(access)
  return self unless ACCESS_METHODS.include?(access) &&
    access != @access

  copy = self.dup
  copy.instance_variable_set(:@access, access)

  copy.freeze
end

#symbolsObject



68
69
70
# File 'lib/koto/parser/ast/processor/context.rb', line 68

def symbols
  active_scope.data
end

#top_level?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/koto/parser/ast/processor/context.rb', line 90

def top_level?
  @stack.empty?
end