def tokval(token, *accepted_types)
accepted_types = [TkVal] if accepted_types.empty?
accepted_types.push(TkNode) if accepted_types.include? TkVal
if accepted_types.include?(:attr)
accepted_types.push(TkSTRING, TkSYMBOL)
end
if accepted_types.include?(:string)
accepted_types.push(TkSTRING, TkDSTRING, TkXSTRING, TkDXSTRING)
end
if accepted_types.include?(:identifier)
accepted_types.push(TkIDENTIFIER, TkFID, TkGVAR)
end
if accepted_types.include?(:number)
accepted_types.push(TkFLOAT, TkINTEGER)
end
return unless accepted_types.any? {|t| t === token }
case token
when TkSTRING, TkDSTRING, TkXSTRING, TkDXSTRING
token.text[1..-2]
when TkSYMBOL
token.text[1..-1].to_sym
when TkFLOAT
token.text.to_f
when TkINTEGER
token.text.to_i
when TkREGEXP
token.text =~ /\A\/(.+)\/([^\/])\Z/
Regexp.new($1, $2)
when TkTRUE
true
when TkFALSE
false
when TkNIL
nil
else
token.text
end
end