Class: CSVPlusPlus::Language::References
- Inherits:
-
Object
- Object
- CSVPlusPlus::Language::References
- Defined in:
- lib/csv_plus_plus/language/references.rb
Overview
References in an AST that need to be resolved
Instance Attribute Summary collapse
-
#functions ⇒ Object
Returns the value of attribute functions.
-
#variables ⇒ Object
Returns the value of attribute variables.
Class Method Summary collapse
-
.extract(ast, code_section) ⇒ Object
Extract references from an AST.
Instance Method Summary collapse
-
#==(other) ⇒ Object
.
-
#empty? ⇒ Boolean
are there any references to be resolved?.
-
#initialize ⇒ References
constructor
Create an object with empty references.
-
#to_s ⇒ Object
to_s.
Constructor Details
#initialize ⇒ References
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
#functions ⇒ Object
Returns the value of attribute functions.
10 11 12 |
# File 'lib/csv_plus_plus/language/references.rb', line 10 def functions @functions end |
#variables ⇒ Object
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?
38 39 40 |
# File 'lib/csv_plus_plus/language/references.rb', line 38 def empty? @functions.empty? && @variables.empty? end |
#to_s ⇒ Object
to_s
43 44 45 |
# File 'lib/csv_plus_plus/language/references.rb', line 43 def to_s "References(functions: #{@functions}, variables: #{@variables})" end |