flatten bracketed commas in dcgs

This commit is contained in:
Mark Thom
2019-01-26 14:38:54 -07:00
parent ef3d3aa01a
commit 91b85db90c
4 changed files with 28 additions and 7 deletions

View File

@@ -45,15 +45,27 @@ expand_dcgs(Term0, N, (ModHead :- ModBody)) :-
nonvar(Body),
expand_body(Body, ModBody, N, N1).
expand_body(Term0, (ModTerm, ModTerms), N0, N) :-
expand_body(Term0, ModTerms, N0, N) :-
nonvar(Term0), Term0 = (Term, Terms), !,
nonvar(Term),
expand_body_term(Term, ModTerm, N0, N1),
expand_body(Terms, ModTerms, N1, N).
unfurl_commas(ModTerm, ModTerms, ModTerms1),
expand_body(Terms, ModTerms1, N1, N).
expand_body(Term0, ModTerm, N0, N) :-
nonvar(Term0),
expand_body_term(Term0, ModTerm, N0, N).
/* unfurl_commas(?ModTerm, -ModTerms, -ModTerms1) :
sets ModTerms = (ModTermI0, ModTermI1, ..., ModTermIN, ModTerms1)
where ModTerm = (ModTermI0, ModTermI1, ..., ModTermIN) */
unfurl_commas(ModTerm, ModTerms, ModTerms1) :-
nonvar(ModTerm),
ModTerm = (ModTermI0, ModTermIs),
!,
ModTerms = (ModTermI0, ModTerms2),
unfurl_commas(ModTermIs, ModTerms2, ModTerms1).
unfurl_commas(ModTermIN, (ModTermIN, ModTerms1), ModTerms1).
expand_body_term([], true, N, N) :- !.
expand_body_term([Arg|Args], ModTerm, N0, N) :-
!, N is N0 + 1,