lib/soroban/parser/rewrite.rb in soroban-0.7.3 vs lib/soroban/parser/rewrite.rb in soroban-0.8.0
- old
+ new
@@ -1,36 +1,43 @@
module Treetop
module Runtime
- class SyntaxNode
- def to_ruby(dependencies)
+ # Each node in the AST produced by the treetop parser implements to_ruby,
+ # which allows the Soroban sheet to store the ruby version of the Excel
+ # contents of each cell in the sheet (and which also gathers and stores the
+ # dependencies that call has on other cells). Each concrete syntax node may
+ # override rewrite_ruby and extract_labels.
+ class SyntaxNode
+ def to_ruby(cell)
if nonterminal?
value = ""
- elements.each { |element| value << element.to_ruby(dependencies) }
- _add_dependency(dependencies, extract(value))
+ elements.each { |element| value << element.to_ruby(cell) }
+ _add_dependency(cell, value)
rewrite_ruby(value)
else
- _add_dependency(dependencies, extract(text_value))
+ _add_dependency(cell, text_value)
rewrite_ruby(text_value)
end
end
+ # Return the ruby version of the Excel value. By default this does
+ # nothing; see nodes.rb for concrete implementations.
def rewrite_ruby(value)
value
end
- def extract(value)
+ # Return either a single label of the form :A1, or an array of labels of
+ # the form [:B1, :B2, ...]. This is used to keep track of the dependencies
+ # of this particular cell.
+ def extract_labels(value)
+ nil
end
private
- def _add_dependency(dependencies, value)
- return if value.nil?
- dependencies << value
- dependencies.flatten!
- dependencies.compact!
- dependencies.uniq!
+ def _add_dependency(cell, value)
+ cell.add_dependencies(extract_labels(value))
end
-
end
+
end
end