diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-03-17 01:25:55 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-03-17 01:25:55 +1100 |
commit | 6b6fc58a996f32a8d0e1947c92ac2b181a800816 (patch) | |
tree | 2093f73c0e3bb4131a05a2aa77c282ef6767ec54 | |
parent | eea18ca12f847b2a302d1793bef5fcc1eb452277 (diff) |
Rewritten to use chars instead of char codes, bug fixed
-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))}. |