def eval_expr(expr, val, plugin)
case expr
when "text()"
if( val.is_a?(Hash) && val[TextNode] && val.size == 1 )
val[TextNode]
else
val
end
when "size()"
case val
when Array
val.size
when nil
0
else
1
end
when /int\((.+)\)/
eval_expr($1,val,plugin).to_i
when /float\((.+)\)/
eval_expr($1,val,plugin).to_f
when /^(-?\d+)$/
$1.to_i
when /^(-?\d+)\.(\d+)$/
$1.to_f
when /^('|"|"|')(.+)('|"|"|')$/
str = $2
str.gsub(/\\./){|m| $1}
when /^%q\((.+)\)$/
str = $1
str.gsub(/\\./){|m| $1}
when /^%r\((.+)\)$/, %r{/(.+)/}
str = $1
str.gsub!(/\\./){|m| $1}
Regexp.new(str)
when 'nil'
nil
else
path_split(expr).each{|path|
case val
when Hash
val = val[path]
if( val.is_a?(Hash) && val[TextNode] && val.size == 1 )
val = val[TextNode]
end
when Array
val = val.collect{|v|
eval_expr(path, v, plugin)
}.flatten.reject{|v| v.nil?}
if( val.size == 0 )
val = nil
end
else
val = nil
break
end
}
val
end
end