def literal_concat head, tail
return tail unless head
return head unless tail
htype, ttype = head[0], tail[0]
head = s(:dstr, '', head) if htype == :evstr
case ttype
when :str then
if htype == :str
head[-1] << tail[-1]
elsif htype == :dstr and head.size == 2 then
head[-1] << tail[-1]
else
head << tail
end
when :dstr then
if htype == :str then
tail[1] = head[-1] + tail[1]
head = tail
else
tail[0] = :array
tail[1] = s(:str, tail[1])
tail.delete_at 1 if tail[1] == s(:str, '')
head.push(*tail[1..-1])
end
when :evstr then
head[0] = :dstr if htype == :str
if head.size == 2 and tail.size > 1 and tail[1][0] == :str then
head[-1] << tail[1][-1]
head[0] = :str if head.size == 2
else
head.push(tail)
end
else
x = [head, tail]
raise "unknown type: #{x.inspect}"
end
return head
end