bufread/[2,3]

Module: builtins

bufread/2 — runs the Prolog parser on a string of text
bufread/3 — similiar to bufread/2, allowing read options
old_bufread/2 — similiar to bufread/2, giving additional information on variables

FORMS

bufread(Buffer, Term)

bufread(Buffer, Term, Options)

old_bufread(Buffer, [Term | VarNames ])

DESCRIPTION

bufread/2 takes a Prolog string, Buffer, and attempts to transform it into a Prolog term. It does this by :

old_bufread/2 behaves similarly, except that it returns in VarNamess a list of the quoted variable names occurring in the term read. The same information can be obtain using bufread/3 with Options containing either variable_names(VNs) or vars_and_names(Vars,Names).

EXAMPLES

The following examples read the string

"f(abc, Bob)"

?- bufread("f(abc, Bob)", Term).

Term=f(abc,_A) 

yes.

?- bufread("f(abc, Bob)", Term, [vars_and_names(Vars,Names)]).

Term=f(abc,_A) 
Vars=[_A] 
Names=['Bob'] 

yes.

Here is how syntax error (a missing comma) in the string is handled:

f(abc Bob)stream_descriptor(,open,string,string([102,40,97,98,99,32,66,111,98,41]),[input|nooutput],false,53,[],0,0,0,true,1,wt_opts(78,400,flat),[],wait,text,eof_code,true,0)
      ^Syntax error 
	string("f(abc Bob)"), line 1: Illegal token after primary expression

NOTE

old_bufread/2 is defined as follows:

old_bufread(String,[Term|VarNames]) :-
        open(string(String),read,Stream),
        read_term(Stream,Term,
                  [attach_fullstop(true),vars_and_names(_,VarNames)]),
        close(Stream).