Line_count/2 and phrase_from_file

On SWI-prolog 8.1.0 I’m using phrase_from_file to parse a file.
When I detect an error I need to report the line number. Unfortunately line_count/2 reports the wrong number, apparently the last line of the last file compiled?

This used to work - or perhaps I’ve never advanced that many lines before realizing I can’t advance the parse and reporting the error? I describe using line_count/2 and phrase_from_file in the DCG tutorial. And the SimGen code was using it (though it might have been broken, we stopped work rather abruptly on it while I was in middle of some major work).


I hate to say it but line_count/2 with phrase_from_file has not been working for many months. I learned of it from your tutorial but after trying it, it did not work. I chalked it up to the tutorial being out of date and threaded my own line counter routines into the DCG. It would be nice if it did work, but I can manage without it.

1 Like

Hi Anne,

how do you get the stream if you are using phrase_from_file? Like,

..., phrase_from_file(grammar, 'filename'), ...

grammar --> { line_count(???, Count) }, ...

Did you use an option in the 3-arg version of phrase_from_file to get access to the stream?

line_count/2 can never have worked. At least in theory lazy_list_location(-Location)// should work.