:- module(_,_).
% :- use_package(sr/bfall).

%% * Parsing: using append and standard lists
%    ----------------------------------------
% (See also grammar_alternatives file)

% A first approach at parsing: using append to match: 

myphrase(P) :-
    % A (article) must be at beginning of P, T1 is the rest:
    append_(A,T1,P),
    article(A),
    append_(S1,T2,T1),
    spaces(S1),
    append_(N,T3,T2),
    noun(N),
    append_(S2,V,T3),
    spaces(S2),
    verb(V).

article([a]).
article([t,h,e]).

spaces([' ']). 
spaces([' ' | T]) :- 
    spaces(T).

noun([c,a,r]).
noun([p,l,a,n,e]).

verb([f,l,i,e,s]).
verb([d,r,i,v,e,s]).

% Local version for alternate sr
append_([],X,X).
append_([X|Y],Z,[X|W]) :- append_(Y,Z,W).

% Try:
% ?- myphrase([t,h,e,' ',p,l,a,n,e,' ',f,l,i,e,s]).
% ?- myphrase([t,h,e,' ',p,l,a,n,e]).

% And we can generate: 
% ?- myphrase(X).

% Try also uncommenting :- use_pakage(sr/bfall).
% above and, again:
% ?- myphrase(X).
% We get fair generation!
