def balance(scanner, start, finish, count = 0)
      str = ''.dup
      scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
      regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
      while scanner.scan(regexp)
        str << scanner.matched
        count += 1 if scanner.matched[-1] == start
        count -= 1 if scanner.matched[-1] == finish
        return [str.strip, scanner.rest] if count == 0
      end
    end
def balance(scanner, start, finish, count = 0)
      str = ''.dup
      scanner = StringScanner.new(scanner) unless scanner.is_a? StringScanner
      regexp = Regexp.new("(.*?)[\\#{start.chr}\\#{finish.chr}]", Regexp::MULTILINE)
      while scanner.scan(regexp)
        str << scanner.matched
        count += 1 if scanner.matched[-1] == start
        count -= 1 if scanner.matched[-1] == finish
        return [str.strip, scanner.rest] if count == 0
      end
    end
Moves a scanner through a balanced pair of characters.
 For example:

     Foo (Bar (Baz bang) bop) (Bang (bop bip))
     ^                       ^
     from                    to

 @param scanner [StringScanner] The string scanner to move
 @param start [String] The character opening the balanced pair.
 @param finish [String] The character closing the balanced pair.
 @param count [Fixnum] The number of opening characters matched
   before calling this method
 @return [(String, String)] The string matched within the balanced pair
   and the rest of the string.
   `["Foo (Bar (Baz bang) bop)", " (Bang (bop bip))"]` in the example above.