class Parser::Context
Context
of parsing that is represented by a stack of scopes.
Supported states: + :class - in the class body (class A; end) + :module - in the module body (module M; end) + :sclass - in the singleton class body (class << obj; end) + :def - in the method body (def m; end) + :defs - in the singleton method body (def self.m; end) + :block - in the block body (tap {}) + :lambda - in the lambda body (-> {})
Attributes
stack[R]
Public Class Methods
new()
click to toggle source
# File lib/parser/context.rb, line 18 def initialize @stack = [] freeze end
Public Instance Methods
class_definition_allowed?()
click to toggle source
# File lib/parser/context.rb, line 47 def class_definition_allowed? def_index = stack.rindex { |item| [:def, :defs].include?(item) } sclass_index = stack.rindex(:sclass) def_index.nil? || (!sclass_index.nil? && sclass_index > def_index) end
Also aliased as: module_definition_allowed?, dynamic_const_definition_allowed?
empty?()
click to toggle source
# File lib/parser/context.rb, line 35 def empty? @stack.empty? end
in_block?()
click to toggle source
# File lib/parser/context.rb, line 56 def in_block? @stack.last == :block end
in_class?()
click to toggle source
# File lib/parser/context.rb, line 39 def in_class? @stack.last == :class end
in_dynamic_block?()
click to toggle source
# File lib/parser/context.rb, line 64 def in_dynamic_block? in_block? || in_lambda? end
in_lambda?()
click to toggle source
# File lib/parser/context.rb, line 60 def in_lambda? @stack.last == :lambda end
indirectly_in_def?()
click to toggle source
# File lib/parser/context.rb, line 43 def indirectly_in_def? @stack.include?(:def) || @stack.include?(:defs) end
pop()
click to toggle source
# File lib/parser/context.rb, line 27 def pop @stack.pop end
push(state)
click to toggle source
# File lib/parser/context.rb, line 23 def push(state) @stack << state end
reset()
click to toggle source
# File lib/parser/context.rb, line 31 def reset @stack.clear end