Module finding calling program DCG predicates

I’m using: SWI-Prolog version 8.1.6

Here’s simplified version of a module I have.

:- module(parse_tools,[]).
:- use_module(library(dcg/basics)).

:- export(quot_csv//1).
quot_csv(Value) --> { var(Value) },`"`,string(Value),`"`,!,(`,`;eos).
quot_csv(DCG) --> `"`,DCG,`"`,!,(`,`;eos).

mdy(M,D,Y) --> blanks,integer(M),`/`,integer(D),`/`,integer(Y),string(_).

cash(Number) --> blanks,prefix,float(Number),string(_).

prefix,`0.` --> `$`,blanks,`.`,!.
prefix,`-` --> `-$`,blanks,!.
prefix --> `$`,blanks.

The intent is for calling program to be able to able to use something like:

phrase(lin(M,D,Y,Cash),Line,_),
% more stuff using M,D,Y and Cash.

lin(M,D,Y,Cash) --> quot_csv(mdy(M,D,Y)),quot_csv(cash(Cash)).

This works fine, but I want to allow the calling program to use its own custom DCG with quote_csv//1. But then quot_csv//1 won’t be able to find it since it’s in a different module. What is the most direct way to do this.

Thanks,
John

Declare quot_csv//1 as a meta-predicate.

I would add it to export list of the module where it’s defined (btw, why you opted for the directive export/1 ?):

:- module(parse_tools,[lin//4]).

Anyway, beware of this construct

, string(_).

It could make your parse time exponential, and surely make your grammar difficult to debug. Try to be more specific…

quot_csv has cuts in it to account for choice points like those left by string//1.

Thanks! I declared quot_csv as:

:- meta_predicate(quot_csv(//)).

I also got rid of the option to pass a variable instead. All one has to do is call:

quote_csv(string(S))

And S will get everything anyway and it satisfies the meta_predicate requirement.