the three methods that deal with looping are bit more intenseas they have to share state between the three of them for simplicity ( ' sure you're eager to see the end of this long we're almost there!)we'll handle this as instance variables on the class itself as an exerciseyou might want to consider better ways to architect thisespecially after reading the next three def process_loopover(selfmatchargument)self loop_index self loop_list self context get(argument[]self pos self loop_pos match end(def process_loopvar(selfmatchargument)self outfile write(self loop_list[self loop_index]self pos match end(def process_endloop(selfmatchargument)self loop_index + if self loop_index >len(self loop_list)self pos match end(del self loop_index del self loop_list del self loop_pos elseself pos self loop_pos when we encounter the loopover directivewe don' have to output anythingbut we do have to set the initial state on three variables the loop_list variable is assumed to be list pulled from the context dictionary the loop_index variable indicates what position in that list should be output in this iteration of the loopwhile loop_pos is stored so we know where to jump back to when we get to the end of the loop the loopvar directive outputs the value at the current position in the loop_list variable and skips to the end of the directive note that it doesn' increment the loop index because the loopvar directive could be called multiple times inside loop the endloop directive is more complicated it determines whether there are more elements in the loop_listif there areit just jumps back to the start of the loopincrementing the index otherwiseit resets all the variables that were being used to process the loop and jumps to the end of the directive so the engine can carry on with the next match