def nest_and_try_closing(delimiter, ts, te, lookahead=nil)
delimiter = coerce_encoding(delimiter)
if @start_delim && @start_delim == delimiter
@nesting += 1
elsif delimiter?(delimiter)
@nesting -= 1
end
if @nesting == 0
if words?
extend_space(ts, ts)
end
if lookahead && @label_allowed && lookahead[0] == ?: &&
lookahead[1] != ?: && @start_tok == :tSTRING_BEG
flush_string
emit(:tLABEL_END, @end_delim, ts, te + 1)
elsif @monolithic
emit(:tSTRING, @buffer, @str_s, te)
else
flush_string unless heredoc?
emit(:tSTRING_END, @end_delim, ts, te)
end
end
end