def parse_series(tokens):
 for token in tokens:
  if (token.type == 'STRING'):
   raise ValueError('String tokens not allowed in series.')
 s = ''.join((token.value for token in tokens)).strip()
 if (s == 'odd'):
  return (2, 1)
 elif (s == 'even'):
  return (2, 0)
 elif (s == 'n'):
  return (1, 0)
 if ('n' not in s):
  return (0, int(s))
 (a, b) = s.split('n', 1)
 if (not a):
  a = 1
 elif ((a == '-') or (a == '+')):
  a = int((a + '1'))
 else:
  a = int(a)
 if (not b):
  b = 0
 else:
  b = int(b)
 return (a, b)

def parse_series ( tokens ) : for token in tokens : if ( token . type == 'STRING' ) : raise ValueError ( 'String tokens not allowed in series.' ) s = '' . join ( ( token . value for token in tokens ) ) . strip ( ) if ( s == 'odd' ) : return ( 2 , 1 ) elif ( s == 'even' ) : return ( 2 , 0 ) elif ( s == 'n' ) : return ( 1 , 0 ) if ( 'n' not in s ) : return ( 0 , int ( s ) ) ( a , b ) = s . split ( 'n' , 1 ) if ( not a ) : a = 1 elif ( ( a == '-' ) or ( a == '+' ) ) : a = int ( ( a + '1' ) ) else : a = int ( a ) if ( not b ) : b = 0 else : b = int ( b ) return ( a , b )
parses the arguments for :nth-child() and friends .