module SyntaxTree::WithScope

def visit_binary(node)

Visit for capturing local variables defined in regex named capture groups
def visit_binary(node)
  if node.operator == :=~
    left = node.left
    if left.is_a?(RegexpLiteral) && left.parts.length == 1 &&
         left.parts.first.is_a?(TStringContent)
      content = left.parts.first
      value = content.value
      location = content.location
      start_line = location.start_line
      Regexp
        .new(value, Regexp::FIXEDENCODING)
        .names
        .each do |name|
          offset = value.index(/\(\?<#{Regexp.escape(name)}>/)
          line = start_line + value[0...offset].count("\n")
          # We need to add 3 to account for these three characters
          # prefixing a named capture (?<
          column = location.start_column + offset + 3
          if value[0...offset].include?("\n")
            column =
              value[0...offset].length - value[0...offset].rindex("\n") +
                3 - 1
          end
          ident_location =
            Location.new(
              start_line: line,
              start_char: location.start_char + offset,
              start_column: column,
              end_line: line,
              end_char: location.start_char + offset + name.length,
              end_column: column + name.length
            )
          identifier = Ident.new(value: name, location: ident_location)
          current_scope.add_local_definition(identifier, :variable)
        end
    end
  end
  super
end