class YARP::LexCompat::Heredoc::DedentingHeredoc
def <<(token)
whitespace on plain string content tokens. This allows us to later
As tokens are coming in, we track the minimum amount of common leading
def <<(token) case token.event when :on_embexpr_beg, :on_heredoc_beg @embexpr_balance += 1 when :on_embexpr_end, :on_heredoc_end @embexpr_balance -= 1 when :on_tstring_content if embexpr_balance == 0 token.value.split(/(?<=\n)/).each_with_index do |line, index| next if line.strip.empty? && line.end_with?("\n") next if !(dedent_next || index > 0) leading = line[/\A(\s*)\n?/, 1] next_dedent = 0 leading.each_char do |char| if char == "\t" next_dedent = next_dedent - (next_dedent % TAB_WIDTH) + TAB_WIDTH else next_dedent += 1 end end @dedent = [dedent, next_dedent].compact.min end end end @dedent_next = token.event == :on_tstring_content && embexpr_balance == 0 tokens << token end