Class: Parser::StaticEnvironment

Inherits:
Object
  • Object
show all
Defined in:
lib/parser/static_environment.rb

Constant Summary collapse

FORWARD_ARGS =
:FORWARD_ARGS
ANONYMOUS_BLOCKARG =
:ANONYMOUS_BLOCKARG
ANONYMOUS_RESTARG =
:ANONYMOUS_RESTARG
ANONYMOUS_KWRESTARG =
:ANONYMOUS_KWRESTARG

Instance Method Summary collapse

Constructor Details

#initializeStaticEnvironment

Returns a new instance of StaticEnvironment.



11
12
13
# File 'lib/parser/static_environment.rb', line 11

def initialize
  reset
end

Instance Method Details

#declare(name) ⇒ Object



40
41
42
43
44
# File 'lib/parser/static_environment.rb', line 40

def declare(name)
  @variables.add(name.to_sym)

  self
end

#declare_anonymous_blockargObject



58
59
60
# File 'lib/parser/static_environment.rb', line 58

def declare_anonymous_blockarg
  declare(ANONYMOUS_BLOCKARG)
end

#declare_anonymous_kwrestargObject



82
83
84
# File 'lib/parser/static_environment.rb', line 82

def declare_anonymous_kwrestarg
  declare(ANONYMOUS_KWRESTARG)
end

#declare_anonymous_restargObject



70
71
72
# File 'lib/parser/static_environment.rb', line 70

def declare_anonymous_restarg
  declare(ANONYMOUS_RESTARG)
end

#declare_forward_argsObject



50
51
52
# File 'lib/parser/static_environment.rb', line 50

def declare_forward_args
  declare(FORWARD_ARGS)
end

#declared?(name) ⇒ Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/parser/static_environment.rb', line 46

def declared?(name)
  @variables.include?(name.to_sym)
end

#declared_anonymous_blockarg?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/parser/static_environment.rb', line 62

def declared_anonymous_blockarg?
  declared?(ANONYMOUS_BLOCKARG)
end

#declared_anonymous_kwrestarg?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/parser/static_environment.rb', line 86

def declared_anonymous_kwrestarg?
  declared?(ANONYMOUS_KWRESTARG)
end

#declared_anonymous_restarg?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'lib/parser/static_environment.rb', line 74

def declared_anonymous_restarg?
  declared?(ANONYMOUS_RESTARG)
end

#declared_forward_args?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/parser/static_environment.rb', line 54

def declared_forward_args?
  declared?(FORWARD_ARGS)
end

#empty?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/parser/static_environment.rb', line 94

def empty?
  @stack.empty?
end

#extend_dynamicObject



27
28
29
30
31
32
# File 'lib/parser/static_environment.rb', line 27

def extend_dynamic
  @stack.push(@variables)
  @variables = @variables.dup

  self
end

#extend_staticObject



20
21
22
23
24
25
# File 'lib/parser/static_environment.rb', line 20

def extend_static
  @stack.push(@variables)
  @variables = Set[]

  self
end

#parent_has_anonymous_blockarg?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/parser/static_environment.rb', line 66

def parent_has_anonymous_blockarg?
  @stack.any? { |variables| variables.include?(ANONYMOUS_BLOCKARG) }
end

#parent_has_anonymous_kwrestarg?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/parser/static_environment.rb', line 90

def parent_has_anonymous_kwrestarg?
  @stack.any? { |variables| variables.include?(ANONYMOUS_KWRESTARG) }
end

#parent_has_anonymous_restarg?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/parser/static_environment.rb', line 78

def parent_has_anonymous_restarg?
  @stack.any? { |variables| variables.include?(ANONYMOUS_RESTARG) }
end

#resetObject



15
16
17
18
# File 'lib/parser/static_environment.rb', line 15

def reset
  @variables = Set[]
  @stack     = []
end

#unextendObject



34
35
36
37
38
# File 'lib/parser/static_environment.rb', line 34

def unextend
  @variables = @stack.pop

  self
end