generate_packets.py: parse packet and type definitions in one go
Note that this causes an edge case where at the very end of the file, an end line can be omitted – explicitly forbidding this would require writing a custom takewhile implementation, which probably isn't worth the hassle.
Part of #45186. Make a PacketsDefintion.parse_clean_lines(lines: Iterable[str]) method that parses input line by line in one go, rather than the current approach of doing types first and then going over everything that's left again for the packets.
This will make it so types can no longer be defined anywhere, but must be defined before they're used, and may no longer be defined inside a packet definition.