Class: CSVPlusPlus::References
- Inherits:
-
Object
- Object
- CSVPlusPlus::References
- Defined in:
- lib/csv_plus_plus/references.rb
Overview
References in an AST that need to be resolved
Instance Attribute Summary collapse
-
#functions ⇒ Array<Entities::Function>
Functions references.
-
#variables ⇒ Array<Entities::Variable>
Variable references.
Class Method Summary collapse
-
.extract(ast, scope) ⇒ References
Extract references from an AST and return them in a new
Referencesobject.
Instance Method Summary collapse
- #==(other) ⇒ boolean
-
#empty? ⇒ boolean
Are there any references to be resolved?.
-
#initialize ⇒ References
constructor
Create an object with empty references.
- #to_s ⇒ String
Constructor Details
#initialize ⇒ References
Create an object with empty references. The caller will build them up as it depth-first-searches
46 47 48 49 |
# File 'lib/csv_plus_plus/references.rb', line 46 def initialize @functions = [] @variables = [] end |
Instance Attribute Details
#functions ⇒ Array<Entities::Function>
Functions references
11 12 13 |
# File 'lib/csv_plus_plus/references.rb', line 11 def functions @functions end |
#variables ⇒ Array<Entities::Variable>
Variable references
11 12 13 |
# File 'lib/csv_plus_plus/references.rb', line 11 def variables @variables end |
Class Method Details
.extract(ast, scope) ⇒ References
Extract references from an AST and return them in a new References object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/csv_plus_plus/references.rb', line 21 def self.extract(ast, scope) 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, scope) refs.variables << node if node.variable? end end end |
Instance Method Details
#==(other) ⇒ boolean
64 65 66 |
# File 'lib/csv_plus_plus/references.rb', line 64 def ==(other) @functions == other.functions && @variables == other.variables end |
#empty? ⇒ boolean
Are there any references to be resolved?
54 55 56 |
# File 'lib/csv_plus_plus/references.rb', line 54 def empty? @functions.empty? && @variables.empty? end |
#to_s ⇒ String
59 60 61 |
# File 'lib/csv_plus_plus/references.rb', line 59 def to_s "References(functions: #{@functions}, variables: #{@variables})" end |