Class: Parser::StaticEnvironment

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

Constant Summary collapse

FORWARD_ARGS =
:FORWARD_ARGS
ANONYMOUS_RESTARG_IN_CURRENT_SCOPE =
:ANONYMOUS_RESTARG_IN_CURRENT_SCOPE
ANONYMOUS_RESTARG_INHERITED =
:ANONYMOUS_RESTARG_INHERITED
ANONYMOUS_KWRESTARG_IN_CURRENT_SCOPE =
:ANONYMOUS_KWRESTARG_IN_CURRENT_SCOPE
ANONYMOUS_KWRESTARG_INHERITED =
:ANONYMOUS_KWRESTARG_INHERITED
ANONYMOUS_BLOCKARG_IN_CURRENT_SCOPE =
:ANONYMOUS_BLOCKARG_IN_CURRENT_SCOPE
ANONYMOUS_BLOCKARG_INHERITED =
:ANONYMOUS_BLOCKARG_INHERITED

Instance Method Summary collapse

Constructor Details

#initializeStaticEnvironment

Returns a new instance of StaticEnvironment.



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

def initialize
  reset
end

Instance Method Details

#declare(name) ⇒ Object



55
56
57
58
59
# File 'lib/parser/static_environment.rb', line 55

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

  self
end

#declare_anonymous_blockargObject

Anonymous blockarg



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

def declare_anonymous_blockarg
  declare(ANONYMOUS_BLOCKARG_IN_CURRENT_SCOPE)
end

#declare_anonymous_kwrestargObject

Anonymous kwresarg



113
114
115
# File 'lib/parser/static_environment.rb', line 113

def declare_anonymous_kwrestarg
  declare(ANONYMOUS_KWRESTARG_IN_CURRENT_SCOPE)
end

#declare_anonymous_restargObject

Anonymous restarg



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

def declare_anonymous_restarg
  declare(ANONYMOUS_RESTARG_IN_CURRENT_SCOPE)
end

#declare_forward_argsObject

Forward args



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

def declare_forward_args
  declare(FORWARD_ARGS)
end

#declared?(name) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#declared_anonymous_blockarg?Boolean

Returns:

  • (Boolean)


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

def declared_anonymous_blockarg?
  declared?(ANONYMOUS_BLOCKARG_IN_CURRENT_SCOPE) || declared?(ANONYMOUS_BLOCKARG_INHERITED)
end

#declared_anonymous_blockarg_in_current_scpe?Boolean

Returns:

  • (Boolean)


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

def declared_anonymous_blockarg_in_current_scpe?
  declared?(ANONYMOUS_BLOCKARG_IN_CURRENT_SCOPE)
end

#declared_anonymous_kwrestarg?Boolean

Returns:

  • (Boolean)


117
118
119
# File 'lib/parser/static_environment.rb', line 117

def declared_anonymous_kwrestarg?
  declared?(ANONYMOUS_KWRESTARG_IN_CURRENT_SCOPE) || declared?(ANONYMOUS_KWRESTARG_INHERITED)
end

#declared_anonymous_kwrestarg_in_current_scope?Boolean

Returns:

  • (Boolean)


121
122
123
# File 'lib/parser/static_environment.rb', line 121

def declared_anonymous_kwrestarg_in_current_scope?
  declared?(ANONYMOUS_KWRESTARG_IN_CURRENT_SCOPE)
end

#declared_anonymous_restarg?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/parser/static_environment.rb', line 99

def declared_anonymous_restarg?
  declared?(ANONYMOUS_RESTARG_IN_CURRENT_SCOPE) || declared?(ANONYMOUS_RESTARG_INHERITED)
end

#declared_anonymous_restarg_in_current_scope?Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/parser/static_environment.rb', line 103

def declared_anonymous_restarg_in_current_scope?
  declared?(ANONYMOUS_RESTARG_IN_CURRENT_SCOPE)
end

#declared_forward_args?Boolean

Returns:

  • (Boolean)


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

def declared_forward_args?
  declared?(FORWARD_ARGS)
end

#empty?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/parser/static_environment.rb', line 129

def empty?
  @stack.empty?
end

#extend_dynamicObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/parser/static_environment.rb', line 33

def extend_dynamic
  @stack.push(@variables)
  @variables = @variables.dup
  if @variables.delete(ANONYMOUS_BLOCKARG_IN_CURRENT_SCOPE)
    @variables.add(ANONYMOUS_BLOCKARG_INHERITED)
  end
  if @variables.delete(ANONYMOUS_RESTARG_IN_CURRENT_SCOPE)
    @variables.add(ANONYMOUS_RESTARG_INHERITED)
  end
  if @variables.delete(ANONYMOUS_KWRESTARG_IN_CURRENT_SCOPE)
    @variables.add(ANONYMOUS_KWRESTARG_INHERITED)
  end

  self
end

#extend_staticObject



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

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

  self
end

#parent_has_anonymous_blockarg?Boolean

Returns:

  • (Boolean)


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

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

#parent_has_anonymous_kwrestarg?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'lib/parser/static_environment.rb', line 125

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

#parent_has_anonymous_restarg?Boolean

Returns:

  • (Boolean)


107
108
109
# File 'lib/parser/static_environment.rb', line 107

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

#resetObject



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

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

#unextendObject



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

def unextend
  @variables = @stack.pop

  self
end