# Line\_count/2 and phrase\_from\_file

**URL:** <https://swi-prolog.discourse.group/t/line-count-2-and-phrase-from-file/731>\
**Category:** Help!\
**Created:** [May 27, 2019, 11:29pm UTC](https://swi-prolog.discourse.group/t/line-count-2-and-phrase-from-file/731 "2019-05-27T23:29:58Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anniepoo](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/anniepoo/32/12_2.png) [@anniepoo](https://swi-prolog.discourse.group/u/anniepoo)\
**Post date:** [May 27, 2019, 11:29pm UTC](https://swi-prolog.discourse.group/t/line-count-2-and-phrase-from-file/731/1 "2019-05-27T23:29:59Z")

</div>

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).

Hmm…

---

<div class="post-metadata">

**Author:** ![EricGT](https://avatars.discourse-cdn.com/v4/letter/e/f1d935/32.png) [@EricGT](https://swi-prolog.discourse.group/u/EricGT)\
**Post date:** [May 27, 2019, 11:34pm UTC](https://swi-prolog.discourse.group/t/line-count-2-and-phrase-from-file/731/2 "2019-05-27T23:34:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Boris](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/boris/32/7486_2.png) [@Boris](https://swi-prolog.discourse.group/u/Boris)\
**Post date:** [May 28, 2019, 5:18am UTC](https://swi-prolog.discourse.group/t/line-count-2-and-phrase-from-file/731/3 "2019-05-28T05:18:41Z")

</div>

Hi Anne,

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

```prolog
..., 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?

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 28, 2019, 6:47am UTC](https://swi-prolog.discourse.group/t/line-count-2-and-phrase-from-file/731/4 "2019-05-28T06:47:21Z")

</div>

line\_count/2 can never have worked. At least in theory [lazy\_list\_location(-Location)//](http://www.swi-prolog.org/pldoc/doc_for?object=lazy_list_location//1) should work.
