parser: Improve detection of entity loops Set a flag to detect entity loops at once instead of processing until the depth limit is exceeded.