SWI-Prolog (threaded, 64 bits, version 8.0.0)
While developing DCGs to parse large files (230 MB (241,632,543 bytes)) the parse sometimes ends with an exception:
ERROR: Stack limit (2.0Gb) exceeded ERROR: Stack sizes: local: 1.0Gb, global: 0.4Gb, trail: 0.1Mb ERROR: Stack depth: 204,035, last-call: 0%, Choice points: 4,279,251
In this case, as in many cases before, I suspect the cause is that a DCG rule is not properly written and thus not finding the ending character(s), e.g.
multiline_text_codes(Cs) --> \+ "\n;", "\n", multiline_text_codes(Cs). multiline_text_codes([C|Cs]) --> multiline_text_code(C), multiline_text_codes(Cs). multiline_text_codes() --> . multiline_text_code(C) --> \+ "\n;", [C].
and so continues looking further creating more choice points, even to the end of the list of character codes.
Is there a way to track (gain access to) the number of choice points in a predicate (clause) so that an action can be taken such as reporting the predicate if the number of choice points reaches or exceeds a set value?
If this could be done only once per program or pl file, versus once per predicate, it would be desired.
I am aware of Hackers corner but have never used anything from there.
While my main development system is Windows, I can switch to Linux if that is necessary.