[]. identity([H|T]) --> [H], identity(T). ?- phrase_from_fil" /> []. identity([H|T]) --> [H], identity(T). ?- phrase_from_fil" /> []. identity([H|T]) --> [H], identity(T). ?- phrase_from_fil"/>

SWI Prolog PIO DCGs can't deal with null bytes

76 views Asked by At

I have a file that is just the letter a. I can "parse" it with this DCG:

identity([]) --> [].
identity([H|T]) --> [H], identity(T).
?- phrase_from_file(identity(X), "jah.txt").
X = [97] ;
false.

This is correct-- but when I add a NUL byte to my file:

enter image description here

When I attempt to post the above query, Prolog locks up forever. I guess it has to do something with null-terminated strings somewhere, but I'm not sure what to do here-- I'm using DCGs to parse binary files, so I need to be able to deal with null bytes.

1

There are 1 answers

0
SuperDisk On BEST ANSWER

I needed to pass type(binary) as an option to phrase_from_file/3.

phrase_from_file(identity(X), "jah.txt", [type(binary)]).