I've been trying to parse a file containing lines of integers using phrase_from_file
with the grammar rules
line --> I,line,{integer(I)}.
line --> ['\n'].
thusly: phrase_from_file(line,'input.txt').
It fails, and I got lost very quickly trying to trace it.
I've even tried to print I
, but it doesn't even get there.
EDIT::
As none of the solutions below really fit my needs (using read/1
assumes you're reading terms, and sometimes writing that DCG might just take too long), I cannibalized this code I googled, the main changes being the addition of:
read_rest(-1,[]):-!.
read_word(C,[],C) :- ( C=32 ;
C=(-1)
) , !.
read/1
assumes you're reading terms, and sometimes writing that DCG might just take too long), I cannibalized this code I googled, the main changes being the addition of: ` read_rest(-1,[]):-!. read_word(C,[],C) :- ( C=32 ; C=(-1) ) , !. ` – mosheweset_prolog_flag(double_quotes, chars)
or stick to codes (less recommended) – false