# Phrase\_from\_file vs phrase

**URL:** <https://swi-prolog.discourse.group/t/phrase-from-file-vs-phrase/2925>\
**Category:** Help!\
**Created:** [September 12, 2020, 12:44pm UTC](https://swi-prolog.discourse.group/t/phrase-from-file-vs-phrase/2925 "2020-09-12T12:44:33Z")\
**Posts on this page:** 1\
**Showing post:** 25

<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:** [September 14, 2020, 10:26am UTC](https://swi-prolog.discourse.group/t/phrase-from-file-vs-phrase/2925/25 "2020-09-14T10:26:20Z")

</div>

See

> [@Using phrase\_from\_file](https://swi-prolog.discourse.group/t/using-phrase-from-file/1880):
>
> The lazy parsing predicate [phrase\_from\_file/2](https://www.swi-prolog.org/pldoc/man?predicate=phrase_from_file/2),[3](https://www.swi-prolog.org/pldoc/doc_for?object=phrase_from_file/3) is useful, especially since it provides nice feedback for file position when an error is encountered. It does, however, place certain restrictions on the DCG - particularly in handling eof. I asked Jan to outline those restrictions, he suggested I do so on discourse so everyone could benefit - So this is me asking Jan (or anybody else who can help) what steps one needs to take to make one’s DCG happy with phrase\_from\_file.

phrase\_from\_file loads lazily. It has an attributed variable, when you try to unify it it fires off  
a goal that loads more text. This kinda-sorta works.

@jan - would it make sense to have a non-lazy phrase\_from\_file that supported the current line/char reporting? I usually am using phrase\_from\_file not because it’s lazy but because it supports line tracking, which is pretty much always needed - you will eventually have to deal iwth invalid files,  
and ‘not valid’ is rarely the right error message.

---

_[View the full topic](https://swi-prolog.discourse.group/t/phrase-from-file-vs-phrase/2925)._
