class Nokogiri::CSS::XPathVisitor

def an_plus_b node, options={}

def an_plus_b node, options={}
  raise ArgumentError, "expected an+b node to contain 4 tokens, but is #{node.value.inspect}" unless node.value.size == 4
  a = node.value[0].to_i
  b = node.value[3].to_i
  position = options[:last] ? "(last()-position()+1)" : "position()"
  if (b == 0)
    return "(#{position} mod #{a}) = 0"
  else
    compare = (a < 0) ? "<=" : ">="
    return "(#{position} #{compare} #{b}) and (((#{position}-#{b}) mod #{a.abs}) = 0)"
  end
end