class SyntaxTree::HshPtn


end
in { key: }
case value
pattern matching syntax.
HshPtn represents matching against a hash pattern using the Ruby 2.7+

def ===(other)

def ===(other)
  other.is_a?(HshPtn) && constant === other.constant &&
    keywords.length == other.keywords.length &&
    keywords
      .zip(other.keywords)
      .all? { |left, right| ArrayMatch.call(left, right) } &&
    keyword_rest === other.keyword_rest
end

def accept(visitor)

def accept(visitor)
  visitor.visit_hshptn(self)
end

def child_nodes

def child_nodes
  [constant, *keywords.flatten(1), keyword_rest]
end

def copy(constant: nil, keywords: nil, keyword_rest: nil, location: nil)

def copy(constant: nil, keywords: nil, keyword_rest: nil, location: nil)
  node =
    HshPtn.new(
      constant: constant || self.constant,
      keywords: keywords || self.keywords,
      keyword_rest: keyword_rest || self.keyword_rest,
      location: location || self.location
    )
  node.comments.concat(comments.map(&:copy))
  node
end

def deconstruct_keys(_keys)

def deconstruct_keys(_keys)
  {
    constant: constant,
    keywords: keywords,
    keyword_rest: keyword_rest,
    location: location,
    comments: comments
  }
end

def format(q)

def format(q)
  parts = keywords.map { |(key, value)| KeywordFormatter.new(key, value) }
  parts << KeywordRestFormatter.new(keyword_rest) if keyword_rest
  nested = PATTERNS.include?(q.parent.class)
  # If there is a constant, we're going to format to have the constant name
  # first and then use brackets.
  if constant
    q.group do
      q.format(constant)
      q.text("[")
      q.indent do
        q.breakable_empty
        format_contents(q, parts, nested)
      end
      q.breakable_empty
      q.text("]")
    end
    return
  end
  # If there's nothing at all, then we're going to use empty braces.
  if parts.empty?
    q.text("{}")
    return
  end
  # If there's only one pair, then we'll just print the contents provided
  # we're not inside another pattern.
  if !nested && parts.size == 1
    format_contents(q, parts, nested)
    return
  end
  # Otherwise, we're going to always use braces to make it clear it's a hash
  # pattern.
  q.group do
    q.text("{")
    q.indent do
      q.breakable_space
      format_contents(q, parts, nested)
    end
    if q.target_ruby_version < Formatter::SemanticVersion.new("2.7.3")
      q.text(" }")
    else
      q.breakable_space
      q.text("}")
    end
  end
end

def format_contents(q, parts, nested)

def format_contents(q, parts, nested)
  keyword_rest = self.keyword_rest
  q.group { q.seplist(parts) { |part| q.format(part, stackable: false) } }
  # If there isn't a constant, and there's a blank keyword_rest, then we
  # have an plain ** that needs to have a `then` after it in order to
  # parse correctly on the next parse.
  if !constant && keyword_rest && keyword_rest.value.nil? && !nested
    q.text(" then")
  end
end

def initialize(constant:, keywords:, keyword_rest:, location:)

def initialize(constant:, keywords:, keyword_rest:, location:)
  @constant = constant
  @keywords = keywords
  @keyword_rest = keyword_rest
  @location = location
  @comments = []
end