diff options
Diffstat (limited to 'read.pro')
-rw-r--r-- | read.pro | 30 |
1 files changed, 16 insertions, 14 deletions
@@ -20,35 +20,37 @@ readList(L) :- readLine(L) :- - get0(C), - buildLine(C,L). + get_char(C), + readLine_tail(C,L). -buildLine(10,[]) :- !. -buildLine(C,[C|X]) :- - get0(C2), - buildLine(C2,X). +readLine_tail('\n',[]) :- !. +readLine_tail(C,[C|X]) :- + get_char(C2), + readLine_tail(C2,X). -wordList([X|Y]) --> word(X), whitespace, wordList(Y). -wordList([X]) --> whitespace, wordList(X). +wordList(X) --> whitespace, wordList(X). wordList([X]) --> word(X). wordList([X]) --> word(X), whitespace. +wordList([X|Y]) --> word(X), whitespace, wordList(Y). -word(W) --> charList(X), {name(W,X)}. +word(W) --> charList(X), {atom_chars(W,X)}. -charList([X|Y]) --> char(X), charList(Y). +charList([X|Xs]) --> char(X), charList(Xs). charList([X]) --> char(X). -char(X) --> [X], {X>=33}. - - whitespace --> whsp, whitespace. whitespace --> whsp. -whsp --> [X], {X<33}. +whsp --> oneOf(_,[' ', '\r', '\n', '\t']). +char(X) --> noneOf(X,[' ', '\r', '\n', '\t']). + + +oneOf(X,L) --> [X], {member(X,L)}. +noneOf(X,L) --> [X], {not(member(X,L))}. |