Class: CSVPlusPlus::Runtime::References
- Inherits:
-
Object
- Object
- CSVPlusPlus::Runtime::References
- Extended by:
- T::Sig
- Defined in:
- lib/csv_plus_plus/runtime/references.rb
Overview
References in an AST that need to be resolved
TODO: turn this into a CanExtractReferences?
Instance Attribute Summary collapse
-
#functions ⇒ Array<Entities::Function>
Functions references.
-
#variables ⇒ Array<Entities::Variable>
Variable references.
Class Method Summary collapse
-
.extract(ast, runtime) ⇒ References
Extract references from an AST and return them in a new
Referencesobject.
Instance Method Summary collapse
- #==(other) ⇒ boolean
-
#empty? ⇒ ::T::Boolean
Are there any references to be resolved?.
-
#initialize ⇒ References
constructor
Create an object with empty references.
Constructor Details
#initialize ⇒ References
Create an object with empty references. The caller will build them up as it depth-first-searches
88 89 90 91 |
# File 'lib/csv_plus_plus/runtime/references.rb', line 88 def initialize @functions = ::T.let([], ::T::Array[::CSVPlusPlus::Entities::FunctionCall]) @variables = ::T.let([], ::T::Array[::CSVPlusPlus::Entities::Variable]) end |
Instance Attribute Details
#functions ⇒ Array<Entities::Function>
Functions references
11 12 13 |
# File 'lib/csv_plus_plus/runtime/references.rb', line 11 def functions @functions end |
#variables ⇒ Array<Entities::Variable>
Variable references
11 12 13 |
# File 'lib/csv_plus_plus/runtime/references.rb', line 11 def variables @variables end |
Class Method Details
.extract(ast, runtime) ⇒ References
Extract references from an AST and return them in a new References object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/csv_plus_plus/runtime/references.rb', line 33 def self.extract(ast, runtime) new.tap do |refs| ::CSVPlusPlus::Runtime::Graph.depth_first_search(ast) do |node| unless node.type == ::CSVPlusPlus::Entities::Type::FunctionCall \ || node.type == ::CSVPlusPlus::Entities::Type::Variable next end refs.functions << node if function_reference?(node, runtime) refs.variables << node if variable_reference?(node, runtime) end end end |
Instance Method Details
#==(other) ⇒ boolean
97 98 99 |
# File 'lib/csv_plus_plus/runtime/references.rb', line 97 def ==(other) @functions == other.functions && @variables == other.variables end |
#empty? ⇒ ::T::Boolean
Are there any references to be resolved?
105 106 107 |
# File 'lib/csv_plus_plus/runtime/references.rb', line 105 def empty? @functions.empty? && @variables.empty? end |