Module: Ibex::Frontend::AST::Node

Overview

Adds deterministic, recursively serializable hashes to Struct nodes.

Instance Method Summary collapse

Instance Method Details

#to_hObject



48
49
50
51
52
53
54
55
56
57
# File 'lib/ibex/frontend/ast.rb', line 48

def to_h
  fields = each_pair.to_h { |name, value| [name, serialize(value)] }
  fields.delete(:aliases) if self.class.name.end_with?("::Tokens") && !fields[:aliases]
  if self.class.name.end_with?("::Root")
    fields.delete(:extended) unless fields[:extended]
    fields.delete(:cst) unless fields[:cst]
  end
  fields.delete(:node_annotation) if self.class.name.end_with?("::Alternative") && !fields[:node_annotation]
  { node: self.class.name.split("::").last }.merge(fields)
end