Class: Solargraph::Parser::Region

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

Overview

Data used by the parser to track context at various locations in a source.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source: Solargraph::Source.load_string(''), closure: nil, scope: nil, visibility: :public, lvars: []) ⇒ Region

Returns a new instance of Region.

Parameters:

  • source (Source) (defaults to: Solargraph::Source.load_string(''))
  • namespace (String)
  • scope (Symbol) (defaults to: nil)
  • visibility (Symbol) (defaults to: :public)


28
29
30
31
32
33
34
35
36
# File 'lib/solargraph/parser/region.rb', line 28

def initialize source: Solargraph::Source.load_string(''), closure: nil,
               scope: nil, visibility: :public, lvars: []
  @source = source
  # @closure = closure
  @closure = closure || Pin::Namespace.new(name: '', location: source.location)
  @scope = scope
  @visibility = visibility
  @lvars = lvars
end

Instance Attribute Details

#closurePin::Closure (readonly)

Returns:



10
11
12
# File 'lib/solargraph/parser/region.rb', line 10

def closure
  @closure
end

#lvarsArray<Symbol> (readonly)

Returns:

  • (Array<Symbol>)


22
23
24
# File 'lib/solargraph/parser/region.rb', line 22

def lvars
  @lvars
end

#scopeSymbol (readonly)

Returns:

  • (Symbol)


13
14
15
# File 'lib/solargraph/parser/region.rb', line 13

def scope
  @scope
end

#sourceSolargraph::Source (readonly)

Returns:



19
20
21
# File 'lib/solargraph/parser/region.rb', line 19

def source
  @source
end

#visibilitySymbol (readonly)

Returns:

  • (Symbol)


16
17
18
# File 'lib/solargraph/parser/region.rb', line 16

def visibility
  @visibility
end

Instance Method Details

#code_for(node) ⇒ String

Parameters:

  • node (Parser::AST::Node)

Returns:

  • (String)


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

def code_for node
  source.code_for(node)
end

#filenameString

Returns:

  • (String)


39
40
41
# File 'lib/solargraph/parser/region.rb', line 39

def filename
  source.filename
end

#update(closure: nil, scope: nil, visibility: nil, lvars: nil) ⇒ Region

Generate a new Region with the provided attribute changes.

Parameters:

  • closure (Pin::Closure, nil) (defaults to: nil)
  • scope (Symbol, nil) (defaults to: nil)
  • visibility (Symbol, nil) (defaults to: nil)

Returns:



49
50
51
52
53
54
55
56
57
# File 'lib/solargraph/parser/region.rb', line 49

def update closure: nil, scope: nil, visibility: nil, lvars: nil
  Region.new(
    source: source,
    closure: closure || self.closure,
    scope: scope || self.scope,
    visibility: visibility || self.visibility,
    lvars: lvars || self.lvars
  )
end