Class: CSVPlusPlus::Language::References

Inherits:
Object
  • Object
show all
Defined in:
lib/csv_plus_plus/language/references.rb

Overview

References in an AST that need to be resolved

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeReferences

Create an object with empty references. The caller will build them up as it depth-first-searches



32
33
34
35
# File 'lib/csv_plus_plus/language/references.rb', line 32

def initialize
  @functions = []
  @variables = []
end

Instance Attribute Details

#functionsObject

Returns the value of attribute functions.



10
11
12
# File 'lib/csv_plus_plus/language/references.rb', line 10

def functions
  @functions
end

#variablesObject

Returns the value of attribute variables.



10
11
12
# File 'lib/csv_plus_plus/language/references.rb', line 10

def variables
  @variables
end

Class Method Details

.extract(ast, code_section) ⇒ Object

Extract references from an AST. And return them in a new References object



13
14
15
16
17
18
19
20
21
22
# File 'lib/csv_plus_plus/language/references.rb', line 13

def self.extract(ast, code_section)
  new.tap do |refs|
    ::CSVPlusPlus::Graph.depth_first_search(ast) do |node|
      next unless node.function_call? || node.variable?

      refs.functions << node if function_reference?(node, code_section)
      refs.variables << node if node.variable?
    end
  end
end

Instance Method Details

#==(other) ⇒ Object



48
49
50
# File 'lib/csv_plus_plus/language/references.rb', line 48

def ==(other)
  @functions == other.functions && @variables == other.variables
end

#empty?Boolean

are there any references to be resolved?

Returns:

  • (Boolean)


38
39
40
# File 'lib/csv_plus_plus/language/references.rb', line 38

def empty?
  @functions.empty? && @variables.empty?
end

#to_sObject

to_s



43
44
45
# File 'lib/csv_plus_plus/language/references.rb', line 43

def to_s
  "References(functions: #{@functions}, variables: #{@variables})"
end