def tokval_list(tokenlist, *accepted_types)
return [] unless tokenlist
out = [[]]
parencount, beforeparen = 0, 0
needcomma = false
seen_comma = true
tokenlist.each do |token|
tokval = accepted_types == [:all] ? token.text : tokval(token, *accepted_types)
parencond = !out.last.empty? && tokval != nil
case token
when TkCOMMA
if parencount == 0
out << [] unless out.last.empty?
needcomma = false
seen_comma = true
else
out.last << token.text if parencond
end
when TkLPAREN
if seen_comma
beforeparen += 1
else
parencount += 1
out.last << token.text if parencond
end
when TkRPAREN
if beforeparen > 0
beforeparen -= 1
else
out.last << token.text if parencount > 0 && tokval != nil
parencount -= 1
end
when TkLBRACE, TkLBRACK, TkDO
parencount += 1
out.last << token.text if tokval != nil
when TkRBRACE, TkRBRACK, TkEND
out.last << token.text if tokval != nil
parencount -= 1
else
break if TkKW === token && ![TkTRUE, TkFALSE, TkSUPER, TkSELF, TkNIL].include?(token.class)
seen_comma = false unless TkWhitespace === token
if parencount == 0
next if needcomma
next if TkWhitespace === token
if tokval != nil
out.last << tokval
else
out.last.clear
needcomma = true
end
elsif parencond
needcomma = true
out.last << token.text
end
end
if beforeparen == 0 && parencount < 0
break
end
end
out.map {|e| e.empty? ? nil : (e.size == 1 ? e.pop : e.flatten.join) }.compact
end