SWI-Prolog has some support predicate, for instance:
..., read_line_to_codes(Stream, Codes), phrase(parse, Codes, []), ...
But I would advise you to adopt phrase_from_file/2 (as already suggested in another answer). There is a support library to help parsing input, with some ready to use parser:
:- use_module(library(http/dcg_basics)).
edit the support library has been renamed, there is a back compatibility trick, that allows old naming, but now it's better to use library(dcg/basics).