class Haml::Parser

def parse_old_attributes(text)

Returns:
  • (Integer) - last_line
  • (String) - rest
  • (String) - attributes_hash - Hash literal starting with `{` and ending with `}`
def parse_old_attributes(text)
  last_line = @line.index + 1
  begin
    # Old attributes often look like a valid Hash literal, but it sometimes allow code like
    # `{ hash, foo: bar }`, which is compiled to `_hamlout.attributes({}, nil, hash, foo: bar)`.
    #
    # To scan such code correctly, this scans `a( hash, foo: bar }` instead, stops when there is
    # 1 more :on_embexpr_end (the last '}') than :on_embexpr_beg, and resurrects '{' afterwards.
    balanced, rest = balance_tokens(text.sub(?{, METHOD_CALL_PREFIX), :on_embexpr_beg, :on_embexpr_end, count: 1)
    attributes_hash = balanced.sub(METHOD_CALL_PREFIX, ?{)
  rescue SyntaxError => e
    if e.message == Error.message(:unbalanced_brackets) && !@template.empty?
      text << "\n#{@next_line.text}"
      last_line += 1
      next_line
      retry
    end
    raise e
  end
  return attributes_hash, rest, last_line
end