TexSurgery could parse all the src into a tree, then findall, code_surgery etcetera could be simpler and faster
A single pass could turn the tex document into a tree, branching at every environment, command, section, subsection, paragraph...
It is not as straightforward as it seems, as it is not possible to know in advance if tex groups following a command are indeed an argument to the command or just some sample tex that was grouped for some reason. A possible approach is to keep the tree agnostic, so \commandname{tex1}{tex2 with a \anothercommand} would be parsed into a flat list, nesting only inside the groups:
(Command(name='commandname'), TexGroup('tex1'), TexGroup('tex2 with a ', Command(name='anothercommand')))
Parsing the flat structure of a usual tex document into chapter, section, etc also requires some thought. In principle, the tex could redefine some of the macros that define the logical structure of the document, but it was never the intention of texsurgery to parse macros. We want to edit the tex in a clear way before the tex engine runs...