class Mustermann::AST::Node
@!visibility private
Attributes
@!visibility private
@!visibility private
@!visibility private
Public Class Methods
@!visibility private @param [Symbol] name of the node @return [Class] factory for the node
# File lib/mustermann/ast/node.rb, line 12 def self.[](name) @names ||= {} @names[name] ||= begin const_name = constant_name(name) Object.const_get(const_name) if Object.const_defined?(const_name) end end
@!visibility private @param [Symbol] name of the node @return [String] qualified name of factory for the node
# File lib/mustermann/ast/node.rb, line 29 def self.constant_name(name) return self.name if name.to_sym == :node name = name.to_s.split(?_).map(&:capitalize).join "#{self.name}::#{name}" end
@!visibility private
# File lib/mustermann/ast/node.rb, line 43 def initialize(payload = nil, **options) options.each { |key, value| public_send("#{key}=", value) } self.payload = payload end
Helper for creating a new instance and calling parse
on it. @return [Mustermann::AST::Node] @!visibility private
# File lib/mustermann/ast/node.rb, line 38 def self.parse(*args, &block) new(*args).tap { |n| n.parse(&block) } end
Turns a class name into a node identifier. @!visibility private
# File lib/mustermann/ast/node.rb, line 22 def self.type name[/[^:]+$/].split(/(?<=.)(?=[A-Z])/).map(&:downcase).join(?_).to_sym end
Public Instance Methods
Loop through all nodes that don't have child nodes. @!visibility private
# File lib/mustermann/ast/node.rb, line 65 def each_leaf(&block) return enum_for(__method__) unless block_given? called = false Array(payload).each do |entry| next unless entry.respond_to? :each_leaf entry.each_leaf(&block) called = true end yield(self) unless called end
@!visibility private
# File lib/mustermann/ast/node.rb, line 49 def is_a?(type) type = Node[type] if type.is_a? Symbol super(type) end
@return [Integer] length of the substring @!visibility private
# File lib/mustermann/ast/node.rb, line 78 def length stop - start if start and stop end
@return [Integer] minimum size for a node @!visibility private
# File lib/mustermann/ast/node.rb, line 84 def min_size 0 end
Double dispatch helper for reading from the buffer into the payload. @!visibility private
# File lib/mustermann/ast/node.rb, line 56 def parse self.payload ||= [] while element = yield payload << element end end
Turns a class name into a node identifier. @!visibility private
# File lib/mustermann/ast/node.rb, line 90 def type self.class.type end