Parse statements individually to prevent parser hangs#322
Conversation
There was a problem hiding this comment.
✅ No Issues Found
1 files reviewed | Confidence: 95% | Recommendation: Merge
Review Details
Files: vibeprolog/parser.py (1 change)
Checked: Security, bugs, performance, error handling, code clarity
Summary: The change implements individual statement parsing to prevent Earley parser state explosion on large files. Code correctly handles position adjustments for PlDoc comments and maintains backward compatibility. No issues found.
There was a problem hiding this comment.
Code Review
This pull request introduces a significant performance and stability improvement by parsing Prolog statements individually, which is an effective strategy to prevent parser hangs on large files. The implementation is well-thought-out, especially in how it preserves PlDoc comment associations by adjusting metadata positions. I have one suggestion to further improve the robustness of the new parsing loop. Overall, this is a solid enhancement.
Summary
Testing
import signal, sys, time
from vibeprolog.parser import PrologParser
parser = PrologParser()
with open('library/lists.pl') as f:
content = f.read()
signal.signal(signal.SIGALRM, lambda s,f: sys.exit(1))
signal.alarm(30)
start = time.time()
try:
res = parser.parse(content)
print('parsed', len(res), 'in', time.time()-start)
finally:
signal.alarm(0)
PY
Codex Task