Keep track of the current "depth" you're parsing at.
If the depth of the next line is more than the current depth, recursively call the parser with the new depth, then add the result from that call to the current list.
If the depth of the next line is equal to the current depth, add it to the current list.
If the depth of the next line is less than the current depth, return the current list.