Move most of the logic from generate_parser_expr into separate functions