From 6b6fc58a996f32a8d0e1947c92ac2b181a800816 Mon Sep 17 00:00:00 2001 From: Jed Barber Date: Mon, 17 Mar 2014 01:25:55 +1100 Subject: Rewritten to use chars instead of char codes, bug fixed --- read.pro | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/read.pro b/read.pro index 35bfb52..63d3ae7 100644 --- a/read.pro +++ b/read.pro @@ -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))}. -- cgit