nodes: 0, module; 1, function_definition; 2, function_name:do_sort_by; 3, parameters; 4, block; 5, identifier:self; 6, identifier:element; 7, identifier:decl; 8, identifier:pseudo; 9, expression_statement; 10, if_statement; 11, expression_statement; 12, expression_statement; 13, expression_statement; 14, expression_statement; 15, expression_statement; 16, expression_statement; 17, expression_statement; 18, comment:#  Find current target, set its sort as well; 19, for_statement; 20, comment:"""Implement sort-by declaration - pre-match."""; 21, comparison_operator:',' in decl.value; 22, block; 23, else_clause; 24, assignment; 25, assignment; 26, assignment; 27, assignment; 28, assignment; 29, assignment; 30, assignment; 31, pattern_list; 32, line_continuation:\; 33, call; 34, block; 35, string; 36, attribute; 37, expression_statement; 38, block; 39, identifier:sort; 40, call; 41, identifier:step; 42, subscript; 43, identifier:target; 44, call; 45, attribute; 46, identifier:sort; 47, attribute; 48, subscript; 49, attribute; 50, False; 51, attribute; 52, None; 53, identifier:pos; 54, identifier:action; 55, identifier:enumerate; 56, argument_list; 57, if_statement; 58, string_content:,; 59, identifier:decl; 60, identifier:value; 61, assignment; 62, expression_statement; 63, expression_statement; 64, identifier:css_to_func; 65, argument_list; 66, attribute; 67, subscript; 68, attribute; 69, argument_list; 70, identifier:target; 71, identifier:sort; 72, identifier:target; 73, identifier:lang; 74, attribute; 75, string; 76, identifier:target; 77, identifier:isgroup; 78, identifier:target; 79, identifier:groupby; 80, call; 81, boolean_operator; 82, block; 83, pattern_list; 84, call; 85, assignment; 86, assignment; 87, call; 88, call; 89, attribute; 90, subscript; 91, identifier:self; 92, identifier:state; 93, attribute; 94, string; 95, identifier:self; 96, identifier:current_target; 97, identifier:self; 98, identifier:state; 99, string_content:lang; 100, identifier:reversed; 101, argument_list; 102, comparison_operator:action[0] == 'target'; 103, line_continuation:\; 104, comparison_operator:action[1].tree == element.etree_element; 105, expression_statement; 106, expression_statement; 107, expression_statement; 108, break_statement; 109, identifier:css; 110, identifier:flags; 111, identifier:split; 112, argument_list; 113, identifier:css; 114, attribute; 115, identifier:flags; 116, None; 117, identifier:serialize; 118, argument_list; 119, identifier:serialize; 120, argument_list; 121, identifier:self; 122, identifier:css_namespaces; 123, attribute; 124, string; 125, identifier:self; 126, identifier:state; 127, string_content:current_step; 128, subscript; 129, subscript; 130, string; 131, attribute; 132, attribute; 133, assignment; 134, assignment; 135, assignment; 136, attribute; 137, string; 138, identifier:decl; 139, identifier:value; 140, identifier:css; 141, boolean_operator; 142, identifier:self; 143, identifier:state; 144, string_content:lang; 145, identifier:step; 146, string; 147, identifier:action; 148, integer:0; 149, string_content:target; 150, subscript; 151, identifier:tree; 152, identifier:element; 153, identifier:etree_element; 154, attribute; 155, identifier:sort; 156, attribute; 157, False; 158, attribute; 159, None; 160, identifier:decl; 161, identifier:value; 162, string_content:,; 163, identifier:flags; 164, string; 165, string_content:actions; 166, identifier:action; 167, integer:1; 168, subscript; 169, identifier:sort; 170, subscript; 171, identifier:isgroup; 172, subscript; 173, identifier:groupby; 174, identifier:action; 175, integer:1; 176, identifier:action; 177, integer:1; 178, identifier:action; 179, integer:1
code: def do_sort_by(self, element, decl, pseudo):
          """Implement sort-by declaration - pre-match."""
          if ',' in decl.value:
              css, flags = split(decl.value, ',')
          else:
              css = decl.value
              flags = None
          sort = css_to_func(serialize(css), serialize(flags or ''),
                             self.css_namespaces, self.state['lang'])
          step = self.state[self.state['current_step']]
  
          target = self.current_target()
          target.sort = sort
          target.lang = self.state['lang']
          target.isgroup = False
          target.groupby = None
          #  Find current target, set its sort as well
          for pos, action in \
                  enumerate(reversed(step['actions'])):
              if action[0] == 'target' and \
                      action[1].tree == element.etree_element:
                  action[1].sort = sort
                  action[1].isgroup = False
                  action[1].groupby = None
                  break